ib-ruby 0.5.19 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +4 -0
- data/TODO +0 -3
- data/VERSION +1 -1
- data/bin/contract_details +3 -3
- data/bin/depth_of_market +1 -1
- data/bin/historic_data +5 -8
- data/bin/market_data +2 -2
- data/bin/option_data +2 -2
- data/lib/ib-ruby/connection.rb +1 -9
- data/lib/ib-ruby/extensions.rb +8 -0
- data/lib/ib-ruby/messages/abstract_message.rb +89 -0
- data/lib/ib-ruby/messages/incoming.rb +415 -487
- data/lib/ib-ruby/messages/outgoing.rb +241 -305
- data/lib/ib-ruby/models/bar.rb +3 -3
- data/lib/ib-ruby/models/contract/bag.rb +1 -5
- data/lib/ib-ruby/models/contract.rb +50 -33
- data/lib/ib-ruby/models/execution.rb +6 -3
- data/lib/ib-ruby/models/order.rb +7 -5
- data/lib/ib-ruby/socket.rb +13 -0
- data/lib/ib-ruby/symbols/forex.rb +7 -14
- data/lib/ib-ruby/symbols/futures.rb +16 -20
- data/lib/ib-ruby/symbols/options.rb +6 -4
- data/lib/ib-ruby/symbols/stocks.rb +1 -1
- data/lib/ib-ruby.rb +1 -0
- data/spec/README.md +34 -0
- data/spec/ib-ruby/connection_spec.rb +4 -4
- data/spec/ib-ruby/messages/incoming_spec.rb +50 -0
- data/spec/ib-ruby/messages/outgoing_spec.rb +32 -0
- data/spec/ib-ruby/models/contract_spec.rb +27 -25
- data/spec/ib-ruby/models/order_spec.rb +56 -23
- data/spec/integration/account_info_spec.rb +85 -0
- data/spec/integration/contract_info_spec.rb +209 -0
- data/spec/integration/depth_data_spec.rb +46 -0
- data/spec/integration/historic_data_spec.rb +82 -0
- data/spec/integration/market_data_spec.rb +97 -0
- data/spec/integration/option_data_spec.rb +96 -0
- data/spec/integration/orders/execution_spec.rb +135 -0
- data/spec/{ib-ruby/messages → integration/orders}/open_order +9 -205
- data/spec/integration/orders/placement_spec.rb +150 -0
- data/spec/integration/orders/valid_ids_spec.rb +84 -0
- data/spec/integration_helper.rb +110 -0
- data/spec/message_helper.rb +13 -18
- data/spec/spec_helper.rb +35 -26
- metadata +33 -17
- data/spec/ib-ruby/messages/README.md +0 -16
- data/spec/ib-ruby/messages/account_info_spec.rb +0 -84
- data/spec/ib-ruby/messages/just_connect_spec.rb +0 -33
- data/spec/ib-ruby/messages/market_data_spec.rb +0 -92
- data/spec/ib-ruby/messages/orders_spec.rb +0 -219
- data/spec/ib-ruby_spec.rb +0 -0
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'message_helper'
|
2
|
-
|
3
|
-
describe IB::Messages do
|
4
|
-
|
5
|
-
context "Orders", :connected => true do
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
@eur = IB::Symbols::Forex[:eurusd]
|
9
|
-
@eur_order = IB::Models::Order.new :total_quantity => 20000,
|
10
|
-
:limit_price => 1,
|
11
|
-
:action => 'SELL',
|
12
|
-
:order_type => 'LMT'
|
13
|
-
@wfc = IB::Symbols::Stocks[:wfc]
|
14
|
-
@wfc_order = IB::Models::Order.new :total_quantity => 100,
|
15
|
-
:action => 'BUY',
|
16
|
-
:order_type => 'LMT'
|
17
|
-
end
|
18
|
-
|
19
|
-
context "Placing wrong order" do
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
connect_and_receive :NextValidID, :Alert, :OpenOrder, :OrderStatus
|
23
|
-
wait_for { received? :NextValidID }
|
24
|
-
|
25
|
-
@wfc_order.limit_price = 9.131313 # Set weird non-acceptable price
|
26
|
-
@order_id_before = @ib.next_order_id
|
27
|
-
@order_id_placed = @ib.place_order @wfc_order, @wfc
|
28
|
-
|
29
|
-
wait_for 2
|
30
|
-
end
|
31
|
-
|
32
|
-
after(:all) do
|
33
|
-
@ib.cancel_order @order_id_placed # Just in case...
|
34
|
-
close_connection
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'does not place new Order' do
|
38
|
-
@received[:OpenOrder].should be_empty
|
39
|
-
@received[:OrderStatus].should be_empty
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'still changes client`s next_order_id' do
|
43
|
-
@order_id_placed = @order_id_before
|
44
|
-
@ib.next_order_id.should == @order_id_before + 1
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'received :Alert message' do
|
48
|
-
subject { @received[:Alert].last }
|
49
|
-
|
50
|
-
it { should be_an IB::Messages::Incoming::Alert }
|
51
|
-
it { should be_error }
|
52
|
-
its(:code) { should be_a Integer }
|
53
|
-
its(:message) { should =~ /The price does not conform to the minimum price variation for this contract/ }
|
54
|
-
end
|
55
|
-
|
56
|
-
end # Placing wrong order
|
57
|
-
|
58
|
-
context "Off-market order" do
|
59
|
-
before(:all) do
|
60
|
-
connect_and_receive :NextValidID, :Alert, :OpenOrder, :OrderStatus
|
61
|
-
wait_for { received? :NextValidID }
|
62
|
-
|
63
|
-
@wfc_order.limit_price = 9.13 # Set acceptable price
|
64
|
-
@order_id_before = @ib.next_order_id
|
65
|
-
@order_id_placed = @ib.place_order @wfc_order, @wfc
|
66
|
-
|
67
|
-
wait_for(2) { @received[:OpenOrder].size > 1 && @received[:OpenOrder].size > 1 }
|
68
|
-
end
|
69
|
-
|
70
|
-
after(:all) do
|
71
|
-
#pp @received[:OpenOrder]
|
72
|
-
@ib.cancel_order @order_id_placed # Just in case...
|
73
|
-
close_connection
|
74
|
-
end
|
75
|
-
|
76
|
-
context "Placing" do
|
77
|
-
|
78
|
-
after(:all) { clean_connection } # Clear logs and message collector
|
79
|
-
|
80
|
-
it 'changes client`s next_order_id' do
|
81
|
-
@order_id_placed = @order_id_before
|
82
|
-
@ib.next_order_id.should == @order_id_before + 1
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'received :OpenOrder messages' do
|
86
|
-
subject { @received[:OpenOrder] }
|
87
|
-
|
88
|
-
it { should have_at_least(1).message }
|
89
|
-
|
90
|
-
it 'receives (optional) Order confirmation first' do
|
91
|
-
if subject.size > 1
|
92
|
-
msg = subject.first
|
93
|
-
msg.should be_an IB::Messages::Incoming::OpenOrder
|
94
|
-
msg.contract.should == @wfc
|
95
|
-
msg.order.should == @wfc_order
|
96
|
-
msg.order.order_id.should == @order_id_placed
|
97
|
-
msg.order.status.should == 'PreSubmitted'
|
98
|
-
else
|
99
|
-
puts 'Warning: Confirmation was skipped!'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'receives Order submission then' do
|
104
|
-
msg = subject.last
|
105
|
-
msg.should be_an IB::Messages::Incoming::OpenOrder
|
106
|
-
msg.contract.should == @wfc
|
107
|
-
msg.order.should == @wfc_order
|
108
|
-
msg.order.order_id.should == @order_id_placed
|
109
|
-
msg.order.status.should == 'Submitted'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'received :OrderStatus messages' do
|
114
|
-
subject { @received[:OrderStatus] }
|
115
|
-
|
116
|
-
it { should have_at_least(1).message }
|
117
|
-
|
118
|
-
it 'receives (optional) Order confirmation first' do
|
119
|
-
if subject.size > 1
|
120
|
-
msg = subject.first
|
121
|
-
msg.should be_an IB::Messages::Incoming::OrderStatus
|
122
|
-
msg.id.should == @order_id_placed
|
123
|
-
msg.perm_id.should be_an Integer
|
124
|
-
msg.client_id.should == 1111
|
125
|
-
msg.parent_id.should == 0
|
126
|
-
#msg.order_id.should == @order_id_placed
|
127
|
-
msg.status.should == 'PreSubmitted'
|
128
|
-
msg.filled.should == 0
|
129
|
-
msg.remaining.should == 100
|
130
|
-
msg.average_fill_price.should == 0
|
131
|
-
msg.last_fill_price.should == 0
|
132
|
-
msg.why_held.should == ''
|
133
|
-
else
|
134
|
-
puts 'Warning: Confirmation was skipped!'
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'receives Order submission then' do
|
139
|
-
msg = subject.last
|
140
|
-
msg.should be_an IB::Messages::Incoming::OrderStatus
|
141
|
-
msg.id.should == @order_id_placed
|
142
|
-
#msg.order_id.should == @order_id_placed
|
143
|
-
msg.perm_id.should be_an Integer
|
144
|
-
msg.client_id.should == 1111
|
145
|
-
msg.parent_id.should == 0
|
146
|
-
msg.status.should == 'Submitted'
|
147
|
-
msg.filled.should == 0
|
148
|
-
msg.remaining.should == 100
|
149
|
-
msg.average_fill_price.should == 0
|
150
|
-
msg.last_fill_price.should == 0
|
151
|
-
msg.why_held.should == ''
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end # Placing
|
155
|
-
|
156
|
-
context "Cancelling placed order" do
|
157
|
-
before(:all) do
|
158
|
-
@ib.cancel_order @order_id_placed
|
159
|
-
|
160
|
-
wait_for(2) { received?(:OrderStatus) && received?(:Alert) }
|
161
|
-
end
|
162
|
-
|
163
|
-
after(:all) { clean_connection } # Clear logs and message collector
|
164
|
-
|
165
|
-
it 'does not increase client`s next_order_id further' do
|
166
|
-
@ib.next_order_id.should == @order_id_before + 1
|
167
|
-
end
|
168
|
-
|
169
|
-
it { @received[:OrderStatus].should have_exactly(1).status_message }
|
170
|
-
|
171
|
-
it { @received[:Alert].should have_exactly(1).alert_message }
|
172
|
-
|
173
|
-
it 'receives Order cancellation status' do
|
174
|
-
msg = @received[:OrderStatus].first
|
175
|
-
msg.should be_an IB::Messages::Incoming::OrderStatus
|
176
|
-
msg.id.should == @order_id_placed
|
177
|
-
#msg.order_id.should == @order_id_placed
|
178
|
-
msg.perm_id.should be_an Integer
|
179
|
-
msg.client_id.should == 1111
|
180
|
-
msg.parent_id.should == 0
|
181
|
-
msg.status.should == 'Cancelled'
|
182
|
-
msg.filled.should == 0
|
183
|
-
msg.remaining.should == 100
|
184
|
-
msg.average_fill_price.should == 0
|
185
|
-
msg.last_fill_price.should == 0
|
186
|
-
msg.why_held.should == ''
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'receives Order cancelled Alert' do
|
190
|
-
alert = @received[:Alert].first
|
191
|
-
alert.should be_an IB::Messages::Incoming::Alert
|
192
|
-
alert.message.should =~ /Order Canceled - reason:/
|
193
|
-
end
|
194
|
-
end # Cancelling
|
195
|
-
|
196
|
-
context "Cancelling wrong order" do
|
197
|
-
before(:all) do
|
198
|
-
@ib.cancel_order rand(99999999)
|
199
|
-
|
200
|
-
wait_for(2) { received?(:Alert) }
|
201
|
-
end
|
202
|
-
|
203
|
-
it { @received[:Alert].should have_exactly(1).alert_message }
|
204
|
-
|
205
|
-
it 'does not increase client`s next_order_id further' do
|
206
|
-
@ib.next_order_id.should == @order_id_before + 1
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'receives unable to find Order Alert' do
|
210
|
-
alert = @received[:Alert].first
|
211
|
-
alert.should be_an IB::Messages::Incoming::Alert
|
212
|
-
alert.message.should =~ /Can't find order with id =/
|
213
|
-
end
|
214
|
-
end # Cancelling
|
215
|
-
end # Off-market order
|
216
|
-
|
217
|
-
|
218
|
-
end # Orders
|
219
|
-
end # describe IB::Messages::Incomming
|
data/spec/ib-ruby_spec.rb
DELETED
File without changes
|