ib-ruby 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +8 -0
- data/README.rdoc +6 -6
- data/VERSION +1 -1
- data/bin/contract_details +3 -3
- data/bin/depth_of_market +6 -3
- data/bin/historic_data +8 -8
- data/bin/historic_data_cli +23 -46
- data/bin/market_data +2 -7
- data/bin/time_and_sales +1 -2
- data/lib/ib-ruby/connection.rb +59 -38
- data/lib/ib-ruby/messages/incoming.rb +34 -18
- data/lib/ib-ruby/messages/outgoing.rb +83 -133
- data/lib/ib-ruby/models/contract.rb +17 -18
- data/lib/ib-ruby/models/order.rb +69 -1
- data/lib/ib-ruby/socket.rb +1 -1
- data/lib/ib-ruby/symbols/options.rb +4 -4
- data/spec/ib-ruby/connection_spec.rb +60 -33
- data/spec/ib-ruby/models/contract_spec.rb +2 -2
- metadata +101 -101
data/lib/ib-ruby/models/order.rb
CHANGED
@@ -258,7 +258,75 @@ module IB
|
|
258
258
|
super opts
|
259
259
|
end
|
260
260
|
|
261
|
-
|
261
|
+
# This returns an Array of data from the given order,
|
262
|
+
# mixed with data from associated contract. Ugly mix, indeed.
|
263
|
+
def serialize_with contract
|
264
|
+
[contract.serialize_long(:sec_id),
|
265
|
+
action, # main order fields
|
266
|
+
total_quantity,
|
267
|
+
order_type,
|
268
|
+
limit_price,
|
269
|
+
aux_price,
|
270
|
+
tif, # xtended order fields
|
271
|
+
oca_group,
|
272
|
+
account,
|
273
|
+
open_close,
|
274
|
+
origin,
|
275
|
+
order_ref,
|
276
|
+
transmit,
|
277
|
+
parent_id,
|
278
|
+
block_order,
|
279
|
+
sweep_to_fill,
|
280
|
+
display_size,
|
281
|
+
trigger_method,
|
282
|
+
outside_rth, # was: ignore_rth
|
283
|
+
hidden,
|
284
|
+
contract.serialize_combo_legs(:long),
|
285
|
+
'', # deprecated shares_allocation field
|
286
|
+
discretionary_amount,
|
287
|
+
good_after_time,
|
288
|
+
good_till_date,
|
289
|
+
fa_group,
|
290
|
+
fa_method,
|
291
|
+
fa_percentage,
|
292
|
+
fa_profile,
|
293
|
+
short_sale_slot, # 0 only for retail, 1 or 2 for institution (Institutional)
|
294
|
+
designated_location, # only populate when short_sale_slot == 2 (Institutional)
|
295
|
+
oca_type,
|
296
|
+
rule_80a,
|
297
|
+
settling_firm,
|
298
|
+
all_or_none,
|
299
|
+
min_quantity || EOL,
|
300
|
+
percent_offset || EOL,
|
301
|
+
etrade_only,
|
302
|
+
firm_quote_only,
|
303
|
+
nbbo_price_cap || EOL,
|
304
|
+
auction_strategy || EOL,
|
305
|
+
starting_price || EOL,
|
306
|
+
stock_ref_price || EOL,
|
307
|
+
delta || EOL,
|
308
|
+
stock_range_lower || EOL,
|
309
|
+
stock_range_upper || EOL,
|
310
|
+
override_percentage_constraints,
|
311
|
+
volatility || EOL, # Volatility orders
|
312
|
+
volatility_type || EOL, # Volatility orders
|
313
|
+
delta_neutral_order_type, # Volatility orders
|
314
|
+
delta_neutral_aux_price || EOL, # Volatility orders
|
315
|
+
continuous_update, # Volatility orders
|
316
|
+
reference_price_type || EOL, # Volatility orders
|
317
|
+
trail_stop_price || EOL, # TRAIL_STOP_LIMIT stop price
|
318
|
+
scale_init_level_size || EOL, # Scale Orders
|
319
|
+
scale_subs_level_size || EOL, # Scale Orders
|
320
|
+
scale_price_increment || EOL, # Scale Orders
|
321
|
+
clearing_account,
|
322
|
+
clearing_intent,
|
323
|
+
not_held,
|
324
|
+
contract.serialize_under_comp,
|
325
|
+
serialize_algo,
|
326
|
+
what_if]
|
327
|
+
end
|
328
|
+
|
329
|
+
def serialize_algo
|
262
330
|
if algo_strategy.empty? || algo_strategy.nil?
|
263
331
|
['']
|
264
332
|
else
|
data/lib/ib-ruby/socket.rb
CHANGED
@@ -10,18 +10,18 @@ module IB
|
|
10
10
|
Options =
|
11
11
|
{:wfc20 => Models::Contract.new(:symbol => "WFC",
|
12
12
|
:exchange => "SMART",
|
13
|
-
:expiry => "
|
13
|
+
:expiry => "201112",
|
14
14
|
:right => "CALL",
|
15
15
|
:strike => 20.0,
|
16
16
|
:sec_type => SECURITY_TYPES[:option],
|
17
|
-
:description => "Wells Fargo 20 Call 2011-
|
17
|
+
:description => "Wells Fargo 20 Call 2011-12"),
|
18
18
|
:z50 => Models::Contract.new(:symbol => "Z",
|
19
19
|
:exchange => "LIFFE",
|
20
|
-
:expiry => "
|
20
|
+
:expiry => "201112",
|
21
21
|
:right => "CALL",
|
22
22
|
:strike => 50.0,
|
23
23
|
:sec_type => SECURITY_TYPES[:option],
|
24
|
-
:description => " FTSE-100 index 50 Call 2011-
|
24
|
+
:description => " FTSE-100 index 50 Call 2011-12"),
|
25
25
|
|
26
26
|
}
|
27
27
|
end
|
@@ -2,56 +2,83 @@ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
|
2
2
|
|
3
3
|
describe IB::Connection do
|
4
4
|
|
5
|
-
context
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
context 'when connected to IB Gateway', :connected => true do
|
6
|
+
# THIS depends on TWS|Gateway connectivity
|
7
|
+
before(:all) { @ib = IB::Connection.new }
|
8
|
+
after(:all) { @ib.close if @ib }
|
9
|
+
|
10
|
+
context 'instantiation with default options' do
|
10
11
|
subject { @ib }
|
11
12
|
|
12
13
|
it { should_not be_nil }
|
13
14
|
it { should be_connected }
|
14
15
|
its (:server) {should be_a Hash}
|
15
|
-
its (:
|
16
|
+
its (:server) {should have_key :reader}
|
17
|
+
its (:subscribers) {should have_at_least(1).item} # :NextValidID and empty Hashes
|
16
18
|
its (:next_order_id) {should be_a Fixnum} # Not before :NextValidID arrives
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
describe '#send_message', 'sending messages' do
|
22
|
+
it 'allows 3 signatures representing IB::Messages::Outgoing' do
|
23
|
+
expect {
|
24
|
+
@ib.send_message :RequestOpenOrders, :subscribe => true
|
25
|
+
}.to_not raise_error
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
expect {
|
28
|
+
@ib.send_message IB::Messages::Outgoing::RequestOpenOrders, :subscribe => true
|
29
|
+
}.to_not raise_error
|
30
|
+
|
31
|
+
expect {
|
32
|
+
@ib.send_message IB::Messages::Outgoing::RequestOpenOrders.new(:subscribe => true)
|
33
|
+
}.to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'has legacy #dispatch alias' do
|
37
|
+
expect { @ib.dispatch :RequestOpenOrders, :subscribe => true
|
38
|
+
}.to_not raise_error
|
39
|
+
end
|
27
40
|
end
|
28
|
-
end # instantiation
|
29
41
|
|
30
|
-
|
31
|
-
|
42
|
+
context "subscriptions" do
|
43
|
+
|
44
|
+
it '#subscribe, adds (multiple) subscribers' do
|
45
|
+
@subscriber_id = @ib.subscribe(IB::Messages::Incoming::Alert, :AccountValue) do
|
46
|
+
puts "oooooooooo"
|
47
|
+
end
|
48
|
+
|
49
|
+
@subscriber_id.should be_a Fixnum
|
32
50
|
|
33
|
-
|
34
|
-
|
35
|
-
|
51
|
+
@ib.subscribers.should have_key(IB::Messages::Incoming::Alert)
|
52
|
+
@ib.subscribers.should have_key(IB::Messages::Incoming::AccountValue)
|
53
|
+
@ib.subscribers[IB::Messages::Incoming::Alert].should have_key(@subscriber_id)
|
54
|
+
@ib.subscribers[IB::Messages::Incoming::AccountValue].should have_key(@subscriber_id)
|
55
|
+
@ib.subscribers[IB::Messages::Incoming::Alert][@subscriber_id].should be_a Proc
|
56
|
+
@ib.subscribers[IB::Messages::Incoming::AccountValue][@subscriber_id].should be_a Proc
|
36
57
|
end
|
37
58
|
|
38
|
-
|
59
|
+
it '#unsubscribe, removes all subscribers at this id' do
|
60
|
+
@ib.unsubscribe(@subscriber_id)
|
39
61
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@ib.subscribers[IB::Messages::Incoming::AccountValue].should have_key(@subscriber_id)
|
44
|
-
@ib.subscribers[IB::Messages::Incoming::Alert][@subscriber_id].should be_a Proc
|
45
|
-
@ib.subscribers[IB::Messages::Incoming::AccountValue][@subscriber_id].should be_a Proc
|
46
|
-
end
|
62
|
+
@ib.subscribers[IB::Messages::Incoming::Alert].should_not have_key(@subscriber_id)
|
63
|
+
@ib.subscribers[IB::Messages::Incoming::AccountValue].should_not have_key(@subscriber_id)
|
64
|
+
end
|
47
65
|
|
48
|
-
|
49
|
-
|
66
|
+
end # subscriptions
|
67
|
+
end # connected
|
50
68
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
69
|
+
context 'not connected to IB Gateway' do
|
70
|
+
before(:all) { @ib = IB::Connection.new :connect => false, :reader => false }
|
54
71
|
|
55
|
-
|
72
|
+
context 'instantiation passing :connect => false' do
|
73
|
+
subject { @ib }
|
74
|
+
|
75
|
+
it { should_not be_nil }
|
76
|
+
it { should_not be_connected }
|
77
|
+
its (:server) {should be_a Hash}
|
78
|
+
its (:server) {should_not have_key :reader}
|
79
|
+
its (:subscribers) {should be_empty}
|
80
|
+
its (:next_order_id) {should be_nil}
|
81
|
+
end
|
56
82
|
|
83
|
+
end # not connected
|
57
84
|
end # describe IB::Connection
|
@@ -194,12 +194,12 @@ describe IB::Models::Contract do
|
|
194
194
|
subject { stock = IB::Models::Contract.new properties }
|
195
195
|
|
196
196
|
it "serializes long" do
|
197
|
-
subject.
|
197
|
+
subject.serialize_long.should ==
|
198
198
|
["TEST", IB::SECURITY_TYPES[:stock], "200609", 1234, "PUT", 123, "SMART", nil, "USD", "baz"]
|
199
199
|
end
|
200
200
|
|
201
201
|
it "serializes short" do
|
202
|
-
subject.
|
202
|
+
subject.serialize_short.should ==
|
203
203
|
["TEST", IB::SECURITY_TYPES[:stock], "200609", 1234, "PUT", 123, "SMART", "USD", "baz"]
|
204
204
|
end
|
205
205
|
end #serialization
|
metadata
CHANGED
@@ -2,139 +2,139 @@
|
|
2
2
|
name: ib-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
|
8
|
+
- arvicco
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-12 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.0.13
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.5.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
38
|
description: Ruby Implementation of the Interactive Broker' TWS API
|
39
39
|
email: arvitallian@gmail.com
|
40
40
|
executables:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
- account_info
|
42
|
+
- contract_details
|
43
|
+
- depth_of_market
|
44
|
+
- historic_data
|
45
|
+
- historic_data_cli
|
46
|
+
- market_data
|
47
|
+
- option_data
|
48
|
+
- template
|
49
|
+
- time_and_sales
|
50
50
|
extensions: []
|
51
51
|
|
52
52
|
extra_rdoc_files:
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
- LICENSE
|
54
|
+
- HISTORY
|
55
|
+
- README.rdoc
|
56
56
|
files:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
57
|
+
- bin/account_info
|
58
|
+
- bin/contract_details
|
59
|
+
- bin/depth_of_market
|
60
|
+
- bin/historic_data
|
61
|
+
- bin/historic_data_cli
|
62
|
+
- bin/market_data
|
63
|
+
- bin/option_data
|
64
|
+
- bin/template
|
65
|
+
- bin/time_and_sales
|
66
|
+
- lib/ib-ruby/connection.rb
|
67
|
+
- lib/ib-ruby/constants.rb
|
68
|
+
- lib/ib-ruby/messages/incoming.rb
|
69
|
+
- lib/ib-ruby/messages/outgoing.rb
|
70
|
+
- lib/ib-ruby/messages.rb
|
71
|
+
- lib/ib-ruby/models/bar.rb
|
72
|
+
- lib/ib-ruby/models/contract.rb
|
73
|
+
- lib/ib-ruby/models/execution.rb
|
74
|
+
- lib/ib-ruby/models/model.rb
|
75
|
+
- lib/ib-ruby/models/order.rb
|
76
|
+
- lib/ib-ruby/models.rb
|
77
|
+
- lib/ib-ruby/socket.rb
|
78
|
+
- lib/ib-ruby/symbols/forex.rb
|
79
|
+
- lib/ib-ruby/symbols/futures.rb
|
80
|
+
- lib/ib-ruby/symbols/options.rb
|
81
|
+
- lib/ib-ruby/symbols/stocks.rb
|
82
|
+
- lib/ib-ruby/symbols.rb
|
83
|
+
- lib/ib-ruby.rb
|
84
|
+
- lib/version.rb
|
85
|
+
- spec/ib-ruby/connection_spec.rb
|
86
|
+
- spec/ib-ruby/models/contract_spec.rb
|
87
|
+
- spec/ib-ruby/models/order_spec.rb
|
88
|
+
- spec/ib-ruby_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- tasks/common.rake
|
91
|
+
- tasks/doc.rake
|
92
|
+
- tasks/gem.rake
|
93
|
+
- tasks/git.rake
|
94
|
+
- tasks/spec.rake
|
95
|
+
- tasks/version.rake
|
96
|
+
- Rakefile
|
97
|
+
- README.rdoc
|
98
|
+
- LICENSE
|
99
|
+
- VERSION
|
100
|
+
- HISTORY
|
101
|
+
- .gitignore
|
102
102
|
has_rdoc: true
|
103
103
|
homepage: http://github.com/arvicco/ib-ruby
|
104
104
|
licenses: []
|
105
105
|
|
106
106
|
post_install_message:
|
107
107
|
rdoc_options:
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
108
|
+
- --charset
|
109
|
+
- UTF-8
|
110
|
+
- --main
|
111
|
+
- README.rdoc
|
112
|
+
- --title
|
113
|
+
- mix
|
114
114
|
require_paths:
|
115
|
-
|
115
|
+
- lib
|
116
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: "0"
|
128
128
|
requirements: []
|
129
129
|
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.6.2
|
132
132
|
signing_key:
|
133
133
|
specification_version: 3
|
134
134
|
summary: Ruby Implementation of the Interactive Broker' TWS API
|
135
135
|
test_files:
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
- spec/ib-ruby/connection_spec.rb
|
137
|
+
- spec/ib-ruby/models/contract_spec.rb
|
138
|
+
- spec/ib-ruby/models/order_spec.rb
|
139
|
+
- spec/ib-ruby_spec.rb
|
140
|
+
- spec/spec_helper.rb
|