Permalink
Browse files

Specs fixed

  • Loading branch information...
1 parent d0b17b6 commit 5f06701ab592f2967c91115ba8b0e0b8c376f050 @arvicco arvicco committed Apr 4, 2012
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- ib-ruby (0.7.3)
+ ib-ruby (0.7.4)
bundler (>= 1.0.20)
GEM
@@ -1,7 +1,7 @@
require 'order_helper'
require 'combo_helper'
-OPTS[:silent] = false
+#OPTS[:silent] = false
def define_contracts
@ib = IB::Connection.new OPTS[:connection].merge(:logger => mock_logger)
@@ -19,25 +19,28 @@ def define_contracts
define_contracts
end
+ # Testing different combinations of Parent + Attached Orders:
[
- [:stock, 100, 'DAY', 'LMT', 9.13, 20.0],
- #[:stock, 100, 'GTC', 'LMT', 9.13, 20.0],
- #[:butterfly, 100, 'DAY', 'LMT', 0.05, 1.0],
- #[:butterfly, 10, 'GTC', 'LMT', 0.05, 1.0],
- #[:butterfly, 100, 'GTC', 'STPLMT', 0.05, 0.05, 1.0],
+ #[:stock, 100, 'DAY', 'LMT', 9.13, 20.0], # Parent + takeprofit target
+ [:stock, 100, 'DAY', 'STP', 9.13, 0.0, 8.0], # Parent + stoploss
+ [:stock, 100, 'GTC', 'LMT', 9.13, 20.0], # GTC Parent + target
+ [:butterfly, 10, 'DAY', 'LMT', 0.05, 1.0], # Combo Parent + target
+ #[:butterfly, 10, 'GTC', 'LMT', 0.05, 1.0], # GTC Combo Parent + target
+ [:butterfly, 100, 'GTC', 'STPLMT', 0.05, 0.05, 1.0], # GTC Combo Parent + stoplimit target
].each do |(contract, qty, tif, attach_type, limit_price, attach_price, aux_price)|
context "#{tif} BUY (#{contract}) limit order with attached #{attach_type} SELL" do
- # Needed to pend Modifying Order context (in order_helper.rb) specially for Combos
let(:contract_type) { contract }
before(:all) do
@ib = IB::Connection.new OPTS[:connection].merge(:logger => mock_logger)
@ib.wait_for :NextValidId
@ib.clear_received # to avoid conflict with pre-existing Orders
+ #p [contract, qty, tif, attach_type, limit_price, attach_price, aux_price]
@contract = @contracts[contract]
place_order @contract,
+ :total_quantity => qty,
:limit_price => limit_price,
:tif => tif,
:transmit => false
@@ -52,7 +55,7 @@ def define_contracts
@ib.received[:OrderStatus].should have_exactly(0).status_message
end
- context "Attaching #{attach_type} takeprofit" do
+ context "Attaching #{attach_type} order" do
before(:all) do
@attached_order = IB::Order.new :total_quantity => qty,
:limit_price => attach_price,
@@ -64,7 +67,7 @@ def define_contracts
@order_id_attached = @ib.place_order @attached_order, @contract
@order_id_after = @ib.next_order_id
- @ib.wait_for [:OpenOrder, 2], [:OrderStatus, 2], 5
+ @ib.wait_for [:OpenOrder, 3], [:OrderStatus, 3], 4
end
it_behaves_like 'Placed Order'
@@ -1,7 +1,7 @@
require 'order_helper'
require 'combo_helper'
-OPTS[:silent] = false
+#OPTS[:silent] = false
describe "Combo Order", :connected => true, :integration => true, :slow => true do
@@ -1,7 +1,9 @@
require 'order_helper'
-OPTS[:silent] = false
+#OPTS[:silent] = false
+
describe 'Orders', :connected => true, :integration => true do
+ let(:contract_type) { :stock }
before(:all) { verify_account }
View
@@ -15,8 +15,8 @@
end
it 'receives confirmation of Order submission' do
- order_should_be /Submitted/ # ()Pre)Submitted
- status_should_be /Submitted/
+ order_should_be /Submit/ # ()Pre)Submitted
+ status_should_be /Submit/
end
end # Placing
@@ -41,8 +41,13 @@
it 'receives OpenOrder and OrderStatus for placed order(s)' do
order_should_be /Submitted/
status_should_be /Submitted/
+
if @attached_order
- order_should_be /Submit/, @attached_order
+ if contract_type == :butterfly && @attached_order.tif == 'GTC'
+ pending 'API Bug: Attached DAY orders not working for butterflies!'
+ else
+ order_should_be /Submit/, @attached_order
+ end
end
end
end # Retrieving
@@ -51,29 +56,22 @@
before(:all) do
if defined?(contract_type) && contract_type == :butterfly
pending 'API Bug: Order modification not working for butterflies!'
- elsif @attached_order
- pending 'API Bug: Order modification does not work for attached orders!'
- # Modify original order
- @order.total_quantity = 200
- @order.limit_price += 0.05
- @ib.modify_order @order, @contract # IB::Symbols::Stocks[:wfc] #
-
- # Modify attached order too (if any)
- @attached_order.limit_price = 25.0
- #@attached_order.tif = 'GTC'
- @ib.modify_order @attached_order, @contract
-
- @ib.send_message :RequestOpenOrders
- @ib.wait_for :OpenOrderEnd, 6 #sec
else
# Modification only works for non-attached, non-combo orders
@order.total_quantity = 200
@order.limit_price += 0.05
- @ib.modify_order @order, @contract # IB::Symbols::Stocks[:wfc] #
-
- @ib.send_message :RequestOpenOrders
- @ib.wait_for :OpenOrderEnd, 6 #sec
+ @order.transmit = true
+ @ib.modify_order @order, @contract
+
+ if @attached_order
+ # Modify attached order, if any
+ @attached_order.limit_price *= 1.5
+ @attached_order.tif = 'GTC'
+ @ib.modify_order @attached_order, @contract
+ end
end
+ @ib.send_message :RequestOpenOrders
+ @ib.wait_for :OpenOrderEnd, 6 #sec
end
after(:all) { clean_connection } # Clear logs and message collector
@@ -92,16 +90,21 @@
@contract.should == @ib.received[:OpenOrder].first.contract
order_should_be /Submit/
status_should_be /Submit/
+
if @attached_order
- order_should_be /Submit/, @attached_order
+ if contract_type == :butterfly && @attached_order.tif == 'GTC'
+ pending 'API Bug: Attached DAY orders not working for butterflies!'
+ else
+ order_should_be /Submit/, @attached_order
+ end
end
end
end # Modifying
context "Cancelling placed order" do
before(:all) do
@ib.cancel_order @order_id_placed
- @ib.wait_for [:OrderStatus, 7], :Alert
+ @ib.wait_for [:OrderStatus, 3], :Alert
end
after(:all) { clean_connection } # Clear logs and message collector
@@ -124,7 +127,11 @@
it 'receives cancellation Order Status' do
status_should_be /Cancel/ # Cancelled / PendingCancel
if @attached_order
- order_should_be /Cancel/, @attached_order
+ if contract_type == :butterfly && @attached_order.tif == 'GTC'
+ pending 'API Bug: Attached DAY orders not working for butterflies!'
+ else
+ status_should_be /Cancel/, @attached_order
+ end
end
end
@@ -159,7 +166,7 @@ def status_should_be status, order=@order
msg.order_id.should == order.order_id
msg.perm_id.should be_an Integer
msg.client_id.should == OPTS[:connection][:client_id]
- msg.parent_id.should == 0
+ msg.parent_id.should == 0 unless @attached_order
msg.why_held.should == ''
if @contract == IB::Symbols::Forex[:eurusd]

0 comments on commit 5f06701

Please sign in to comment.