ib-api 10.33.4 → 972.0
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/Gemfile +2 -3
- data/Gemfile.lock +52 -67
- data/README.md +8 -60
- data/VERSION +1 -1
- data/api.gemspec +3 -10
- data/bin/console +38 -39
- data/bin/console.yml +2 -2
- data/changelog.md +0 -25
- data/example/README.md +76 -0
- data/example/account_info +54 -0
- data/example/account_positions +30 -0
- data/example/account_summary +88 -0
- data/example/cancel_orders +74 -0
- data/example/fa_accounts +25 -0
- data/example/fundamental_data +40 -0
- data/example/historic_data_cli +186 -0
- data/example/list_orders +45 -0
- data/example/portfolio_csv +81 -0
- data/example/scanner_data +62 -0
- data/example/template +19 -0
- data/example/tick_data +28 -0
- data/lib/extensions/class-extensions.rb +87 -0
- data/lib/ib/base.rb +1 -7
- data/lib/ib/base_properties.rb +12 -30
- data/lib/ib/connection.rb +269 -418
- data/lib/ib/constants.rb +22 -31
- data/lib/ib/errors.rb +1 -9
- data/lib/ib/logger.rb +26 -0
- data/lib/ib/messages/abstract_message.rb +43 -10
- data/lib/ib/messages/incoming/abstract_message.rb +98 -98
- data/lib/ib/messages/incoming/account_value.rb +78 -0
- data/lib/ib/messages/incoming/alert.rb +4 -4
- data/lib/ib/messages/incoming/contract_data.rb +29 -32
- data/lib/ib/messages/incoming/execution_data.rb +3 -3
- data/lib/ib/messages/incoming/historical_data.rb +33 -14
- data/lib/ib/messages/incoming/{market_depth.rb → market_depths.rb} +10 -0
- data/lib/ib/messages/incoming/next_valid_id.rb +0 -1
- data/lib/ib/messages/incoming/open_order.rb +201 -214
- data/lib/ib/messages/incoming/order_status.rb +1 -1
- data/lib/ib/messages/incoming/portfolio_value.rb +58 -27
- data/lib/ib/messages/incoming/scanner_data.rb +1 -1
- data/lib/ib/messages/incoming/ticks.rb +268 -0
- data/lib/ib/messages/incoming.rb +95 -136
- data/lib/ib/messages/outgoing/abstract_message.rb +22 -18
- data/lib/ib/messages/outgoing/{request_account_summary.rb → account_requests.rb} +40 -7
- data/lib/ib/messages/outgoing/{bar_request_message.rb → bar_requests.rb} +16 -13
- data/lib/ib/messages/outgoing/place_order.rb +198 -138
- data/lib/ib/messages/outgoing/{request_market_data.rb → request_marketdata.rb} +29 -32
- data/lib/ib/messages/outgoing/request_tick_data.rb +21 -0
- data/lib/ib/messages/outgoing.rb +160 -133
- data/lib/ib/messages.rb +7 -47
- data/lib/ib/model.rb +4 -0
- data/lib/ib/models.rb +14 -0
- data/lib/{server_versions.rb → ib/server_versions.rb} +9 -40
- data/lib/ib/socket.rb +147 -45
- data/lib/ib/support.rb +158 -240
- data/lib/ib/version.rb +1 -1
- data/lib/ib-api.rb +5 -42
- data/lib/models/ib/account.rb +85 -0
- data/{models → lib/models}/ib/account_value.rb +5 -5
- data/{models → lib/models}/ib/bag.rb +7 -7
- data/{models → lib/models}/ib/bar.rb +2 -2
- data/{models → lib/models}/ib/combo_leg.rb +4 -26
- data/lib/models/ib/condition.rb +245 -0
- data/{models → lib/models}/ib/contract.rb +170 -166
- data/{models → lib/models}/ib/contract_detail.rb +15 -25
- data/{models → lib/models}/ib/execution.rb +1 -1
- data/{models → lib/models}/ib/forex.rb +2 -1
- data/lib/models/ib/future.rb +15 -0
- data/{models → lib/models}/ib/index.rb +3 -2
- data/lib/models/ib/option.rb +78 -0
- data/lib/models/ib/option_detail.rb +55 -0
- data/{models → lib/models}/ib/order.rb +165 -366
- data/{models → lib/models}/ib/order_state.rb +22 -25
- data/lib/models/ib/portfolio_value.rb +64 -0
- data/lib/models/ib/stock.rb +16 -0
- data/{models → lib/models}/ib/underlying.rb +5 -3
- data/lib/models/ib/vertical.rb +96 -0
- data/lib/requires.rb +12 -0
- metadata +64 -188
- data/CLAUDE.md +0 -131
- data/LLM_GUIDE.md +0 -388
- data/bin/simple +0 -91
- data/conditions/ib/execution_condition.rb +0 -31
- data/conditions/ib/margin_condition.rb +0 -28
- data/conditions/ib/order_condition.rb +0 -29
- data/conditions/ib/percent_change_condition.rb +0 -34
- data/conditions/ib/price_condition.rb +0 -44
- data/conditions/ib/time_condition.rb +0 -42
- data/conditions/ib/volume_condition.rb +0 -36
- data/lib/class_extensions.rb +0 -167
- data/lib/ib/contract.rb +0 -30
- data/lib/ib/messages/incoming/abstract_tick.rb +0 -25
- data/lib/ib/messages/incoming/account_message.rb +0 -26
- data/lib/ib/messages/incoming/contract_message.rb +0 -13
- data/lib/ib/messages/incoming/histogram_data.rb +0 -30
- data/lib/ib/messages/incoming/historical_data_update.rb +0 -50
- data/lib/ib/messages/incoming/managed_accounts.rb +0 -21
- data/lib/ib/messages/incoming/market_depth_l2.rb +0 -15
- data/lib/ib/messages/incoming/position_data.rb +0 -21
- data/lib/ib/messages/incoming/positions_multi.rb +0 -15
- data/lib/ib/messages/incoming/receive_fa.rb +0 -30
- data/lib/ib/messages/incoming/tick_by_tick.rb +0 -77
- data/lib/ib/messages/incoming/tick_efp.rb +0 -18
- data/lib/ib/messages/incoming/tick_generic.rb +0 -12
- data/lib/ib/messages/incoming/tick_option.rb +0 -60
- data/lib/ib/messages/incoming/tick_price.rb +0 -60
- data/lib/ib/messages/incoming/tick_size.rb +0 -55
- data/lib/ib/messages/incoming/tick_string.rb +0 -13
- data/lib/ib/messages/outgoing/new-place-order.rb +0 -193
- data/lib/ib/messages/outgoing/old-place-order.rb +0 -147
- data/lib/ib/messages/outgoing/request_historical_data.rb +0 -182
- data/lib/ib/messages/outgoing/request_market_depth.rb +0 -57
- data/lib/ib/messages/outgoing/request_real_time_bars.rb +0 -48
- data/lib/ib/messages/outgoing/request_scanner_subscription.rb +0 -73
- data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +0 -21
- data/lib/ib/order_condition.rb +0 -26
- data/lib/ib/plugins.rb +0 -27
- data/lib/ib/prepare_data.rb +0 -61
- data/lib/ib/raw_message_parser.rb +0 -99
- data/lib/support/array_function.rb +0 -28
- data/lib/support/logging.rb +0 -45
- data/models/ib/account.rb +0 -72
- data/models/ib/future.rb +0 -64
- data/models/ib/option.rb +0 -149
- data/models/ib/option_detail.rb +0 -84
- data/models/ib/portfolio_value.rb +0 -86
- data/models/ib/spread.rb +0 -176
- data/models/ib/stock.rb +0 -25
- data/plugins/ib/advanced-account.rb +0 -442
- data/plugins/ib/alerts/base-alert.rb +0 -125
- data/plugins/ib/alerts/gateway-alerts.rb +0 -15
- data/plugins/ib/alerts/order-alerts.rb +0 -73
- data/plugins/ib/auto-adjust.rb +0 -0
- data/plugins/ib/connection-tools.rb +0 -122
- data/plugins/ib/eod.rb +0 -326
- data/plugins/ib/greeks.rb +0 -102
- data/plugins/ib/managed-accounts.rb +0 -274
- data/plugins/ib/market-price.rb +0 -150
- data/plugins/ib/option-chain.rb +0 -167
- data/plugins/ib/order-flow.rb +0 -157
- data/plugins/ib/order-prototypes/abstract.rb +0 -67
- data/plugins/ib/order-prototypes/adaptive.rb +0 -40
- data/plugins/ib/order-prototypes/all-in-one.rb +0 -46
- data/plugins/ib/order-prototypes/combo.rb +0 -46
- data/plugins/ib/order-prototypes/forex.rb +0 -40
- data/plugins/ib/order-prototypes/limit.rb +0 -193
- data/plugins/ib/order-prototypes/market.rb +0 -116
- data/plugins/ib/order-prototypes/pegged.rb +0 -169
- data/plugins/ib/order-prototypes/premarket.rb +0 -31
- data/plugins/ib/order-prototypes/stop.rb +0 -202
- data/plugins/ib/order-prototypes/volatility.rb +0 -39
- data/plugins/ib/order-prototypes.rb +0 -118
- data/plugins/ib/probability-of-expiring.rb +0 -109
- data/plugins/ib/process-orders.rb +0 -155
- data/plugins/ib/roll.rb +0 -86
- data/plugins/ib/spread-prototypes/butterfly.rb +0 -77
- data/plugins/ib/spread-prototypes/calendar.rb +0 -97
- data/plugins/ib/spread-prototypes/stock-spread.rb +0 -56
- data/plugins/ib/spread-prototypes/straddle.rb +0 -70
- data/plugins/ib/spread-prototypes/strangle.rb +0 -93
- data/plugins/ib/spread-prototypes/vertical.rb +0 -83
- data/plugins/ib/spread-prototypes.rb +0 -70
- data/plugins/ib/symbols/abstract.rb +0 -136
- data/plugins/ib/symbols/bonds.rb +0 -28
- data/plugins/ib/symbols/cfd.rb +0 -19
- data/plugins/ib/symbols/combo.rb +0 -46
- data/plugins/ib/symbols/commodity.rb +0 -17
- data/plugins/ib/symbols/forex.rb +0 -41
- data/plugins/ib/symbols/futures.rb +0 -127
- data/plugins/ib/symbols/index.rb +0 -43
- data/plugins/ib/symbols/options.rb +0 -99
- data/plugins/ib/symbols/stocks.rb +0 -44
- data/plugins/ib/symbols/version.rb +0 -5
- data/plugins/ib/symbols.rb +0 -118
- data/plugins/ib/verify.rb +0 -226
- data/symbols/w20.yml +0 -210
- data/t.txt +0 -20
- data/update.md +0 -71
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TickEFP = def_message [47, 6], AbstractTick,
|
|
8
|
-
[:ticker_id, :int],
|
|
9
|
-
[:tick_type, :int],
|
|
10
|
-
[:basis_points, :decimal],
|
|
11
|
-
[:formatted_basis_points, :string],
|
|
12
|
-
[:implied_futures_price, :decimal],
|
|
13
|
-
[:hold_days, :int],
|
|
14
|
-
[:dividend_impact, :decimal],
|
|
15
|
-
[:dividends_to_expiry, :decimal]
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
# This message is received when the market in an option or its underlier moves.
|
|
7
|
-
# TWS option model volatilities, prices, and deltas, along with the present
|
|
8
|
-
# value of dividends expected on that options underlier are received.
|
|
9
|
-
# TickOption message contains following @data:
|
|
10
|
-
# :ticker_id - Id that was specified previously in the call to reqMktData()
|
|
11
|
-
# :tick_type - Specifies the type of option computation (see TICK_TYPES).
|
|
12
|
-
# :implied_volatility - The implied volatility calculated by the TWS option
|
|
13
|
-
# modeler, using the specified :tick_type value.
|
|
14
|
-
# :delta - The option delta value.
|
|
15
|
-
# :option_price - The option price.
|
|
16
|
-
# :pv_dividend - The present value of dividends expected on the options underlier
|
|
17
|
-
# :gamma - The option gamma value.
|
|
18
|
-
# :vega - The option vega value.
|
|
19
|
-
# :theta - The option theta value.
|
|
20
|
-
# :under_price - The price of the underlying.
|
|
21
|
-
TickOption = TickOptionComputation =
|
|
22
|
-
def_message([21, 0], AbstractTick,
|
|
23
|
-
[:ticker_id, :int],
|
|
24
|
-
[:tick_type, :int],
|
|
25
|
-
[:tick_attribute, :int],
|
|
26
|
-
[:implied_volatility, :decimal_limit_1], # -1 and below
|
|
27
|
-
[:delta, :decimal_limit_2], # -2 and below
|
|
28
|
-
[:option_price, :decimal_limit_1], # -1 -"-
|
|
29
|
-
[:pv_dividend, :decimal_limit_1], # -1 -"-
|
|
30
|
-
[:gamma, :decimal_limit_2], # -2 -"-
|
|
31
|
-
[:vega, :decimal_limit_2], # -2 -"-
|
|
32
|
-
[:theta, :decimal_limit_2], # -2 -"-
|
|
33
|
-
[:under_price, :decimal_limit_1]) do
|
|
34
|
-
|
|
35
|
-
"<TickOption #{type} " +
|
|
36
|
-
"option @ #{"%8.3f" % (option_price || -1)}, IV: #{"%4.3f" % (implied_volatility || -1)}, " +
|
|
37
|
-
"delta: #{"%5.3f" % (delta || -1)}, " +
|
|
38
|
-
"gamma: #{"%6.4f" % (gamma || -1)}, vega: #{ "%6.5f" % (vega || -1)}, " +
|
|
39
|
-
"theta: #{"%7.6f" % (theta || -1)}, pv_dividend: #{"%5.3f" % (pv_dividend || -1)}, " +
|
|
40
|
-
"underlying @ #{"% 8.3f" % (under_price || -1)} >"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
class TickOption
|
|
44
|
-
def greeks
|
|
45
|
-
{ delta: delta, gamma: gamma, vega: vega, theta: theta }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def iv
|
|
49
|
-
implied_volatility
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def greeks?
|
|
54
|
-
greeks.values.any? &:present?
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
# The IB code seems to dispatch up to two wrapped objects for this message, a tickPrice
|
|
7
|
-
# and sometimes a tickSize, which seems to be identical to the TICK_SIZE object.
|
|
8
|
-
#
|
|
9
|
-
# Important note from
|
|
10
|
-
# http://chuckcaplan.com/twsapi/index.php/void%20tickPrice%28%29 :
|
|
11
|
-
#
|
|
12
|
-
# "The low you get is NOT the low for the day as you'd expect it
|
|
13
|
-
# to be. It appears IB calculates the low based on all
|
|
14
|
-
# transactions after 4pm the previous day. The most inaccurate
|
|
15
|
-
# results occur when the stock moves up in the 4-6pm aftermarket
|
|
16
|
-
# on the previous day and then gaps open upward in the
|
|
17
|
-
# morning. The low you receive from TWS can be easily be several
|
|
18
|
-
# points different from the actual 9:30am-4pm low for the day in
|
|
19
|
-
# cases like this. If you require a correct traded low for the
|
|
20
|
-
# day, you can't get it from the TWS API. One possible source to
|
|
21
|
-
# help build the right data would be to compare against what Yahoo
|
|
22
|
-
# lists on finance.yahoo.com/q?s=ticker under the "Day's Range"
|
|
23
|
-
# statistics (be careful here, because Yahoo will use anti-Denial
|
|
24
|
-
# of Service techniques to hang your connection if you try to
|
|
25
|
-
# request too many bytes in a short period of time from them). For
|
|
26
|
-
# most purposes, a good enough approach would start by replacing
|
|
27
|
-
# the TWS low for the day with Yahoo's day low when you first
|
|
28
|
-
# start watching a stock ticker; let's call this time T. Then,
|
|
29
|
-
# update your internal low if the bid or ask tick you receive is
|
|
30
|
-
# lower than that for the remainder of the day. You should check
|
|
31
|
-
# against Yahoo again at time T+20min to handle the occasional
|
|
32
|
-
# case where the stock set a new low for the day in between
|
|
33
|
-
# T-20min (the real time your original quote was from, taking into
|
|
34
|
-
# account the delay) and time T. After that you should have a
|
|
35
|
-
# correct enough low for the rest of the day as long as you keep
|
|
36
|
-
# updating based on the bid/ask. It could still get slightly off
|
|
37
|
-
# in a case where a short transaction setting a new low appears in
|
|
38
|
-
# between ticks of data that TWS sends you. The high is probably
|
|
39
|
-
# distorted in the same way the low is, which would throw your
|
|
40
|
-
# results off if the stock traded after-hours and gapped down. It
|
|
41
|
-
# should be corrected in a similar way as described above if this
|
|
42
|
-
# is important to you."
|
|
43
|
-
#
|
|
44
|
-
# IB then emits at most 2 events on eWrapper:
|
|
45
|
-
# tickPrice( tickerId, tickType, price, canAutoExecute)
|
|
46
|
-
# tickSize( tickerId, sizeTickType, size)
|
|
47
|
-
TickPrice = def_message [1, 6], AbstractTick,
|
|
48
|
-
[:ticker_id, :int],
|
|
49
|
-
[:tick_type, :int],
|
|
50
|
-
[:price, :decimal],
|
|
51
|
-
[:size, :int],
|
|
52
|
-
[:can_auto_execute, :int]
|
|
53
|
-
class TickPrice
|
|
54
|
-
def valid?
|
|
55
|
-
super && !price.zero?
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Incoming
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
# The IB code seems to dispatch up to two wrapped objects for this message, a tickPrice
|
|
7
|
-
# and sometimes a tickSize, which seems to be identical to the TICK_SIZE object.
|
|
8
|
-
#
|
|
9
|
-
# Important note from
|
|
10
|
-
# http://chuckcaplan.com/twsapi/index.php/void%20tickPrice%28%29 :
|
|
11
|
-
#
|
|
12
|
-
# "The low you get is NOT the low for the day as you'd expect it
|
|
13
|
-
# to be. It appears IB calculates the low based on all
|
|
14
|
-
# transactions after 4pm the previous day. The most inaccurate
|
|
15
|
-
# results occur when the stock moves up in the 4-6pm aftermarket
|
|
16
|
-
# on the previous day and then gaps open upward in the
|
|
17
|
-
# morning. The low you receive from TWS can be easily be several
|
|
18
|
-
# points different from the actual 9:30am-4pm low for the day in
|
|
19
|
-
# cases like this. If you require a correct traded low for the
|
|
20
|
-
# day, you can't get it from the TWS API. One possible source to
|
|
21
|
-
# help build the right data would be to compare against what Yahoo
|
|
22
|
-
# lists on finance.yahoo.com/q?s=ticker under the "Day's Range"
|
|
23
|
-
# statistics (be careful here, because Yahoo will use anti-Denial
|
|
24
|
-
# of Service techniques to hang your connection if you try to
|
|
25
|
-
# request too many bytes in a short period of time from them). For
|
|
26
|
-
# most purposes, a good enough approach would start by replacing
|
|
27
|
-
# the TWS low for the day with Yahoo's day low when you first
|
|
28
|
-
# start watching a stock ticker; let's call this time T. Then,
|
|
29
|
-
# update your internal low if the bid or ask tick you receive is
|
|
30
|
-
# lower than that for the remainder of the day. You should check
|
|
31
|
-
# against Yahoo again at time T+20min to handle the occasional
|
|
32
|
-
# case where the stock set a new low for the day in between
|
|
33
|
-
# T-20min (the real time your original quote was from, taking into
|
|
34
|
-
# account the delay) and time T. After that you should have a
|
|
35
|
-
# correct enough low for the rest of the day as long as you keep
|
|
36
|
-
# updating based on the bid/ask. It could still get slightly off
|
|
37
|
-
# in a case where a short transaction setting a new low appears in
|
|
38
|
-
# between ticks of data that TWS sends you. The high is probably
|
|
39
|
-
# distorted in the same way the low is, which would throw your
|
|
40
|
-
# results off if the stock traded after-hours and gapped down. It
|
|
41
|
-
# should be corrected in a similar way as described above if this
|
|
42
|
-
# is important to you."
|
|
43
|
-
#
|
|
44
|
-
# IB then emits at most 2 events on eWrapper:
|
|
45
|
-
# tickPrice( tickerId, tickType, price, canAutoExecute)
|
|
46
|
-
# tickSize( tickerId, sizeTickType, size)
|
|
47
|
-
|
|
48
|
-
TickSize = def_message [2, 6], AbstractTick,
|
|
49
|
-
[:ticker_id, :int],
|
|
50
|
-
[:tick_type, :int],
|
|
51
|
-
[:size, :int]
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Outgoing
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
PlaceOrder = def_message [ 3,0 ]
|
|
7
|
-
|
|
8
|
-
class PlaceOrder
|
|
9
|
-
def encode
|
|
10
|
-
order = @data[:order]
|
|
11
|
-
contract = @data[:contract]
|
|
12
|
-
|
|
13
|
-
error 'contract has to be specified' unless contract.is_a? IB::Contract
|
|
14
|
-
|
|
15
|
-
# send place order msg
|
|
16
|
-
fields = [ super ]
|
|
17
|
-
fields << contract.serialize_short(:primary_exchange, :sec_id_type)
|
|
18
|
-
fields << order.serialize_main_order_fields
|
|
19
|
-
fields << order.serialize_extended_order_fields
|
|
20
|
-
|
|
21
|
-
# Send combo legs for BAG requests (srv v8 and above)
|
|
22
|
-
if contract.bag?
|
|
23
|
-
fields.push(combo_legs.size)
|
|
24
|
-
fields += combo_legs.map do |the_leg|
|
|
25
|
-
array = [
|
|
26
|
-
the_leg.con_id,
|
|
27
|
-
the_leg.ratio,
|
|
28
|
-
the_leg.side.to_sup,
|
|
29
|
-
the_leg.exchange,
|
|
30
|
-
the_leg[:open_close],
|
|
31
|
-
the_leg[:short_sale_slot],
|
|
32
|
-
the_leg.designated_location,
|
|
33
|
-
]
|
|
34
|
-
array.push(the_leg.exempt_code) if server_version >= KNOWN_SERVERS[:min_server_ver_sshortx_old] # 51
|
|
35
|
-
array
|
|
36
|
-
end.flatten
|
|
37
|
-
|
|
38
|
-
# TODO: order_combo_leg?
|
|
39
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_order_combo_legs_price] # 61
|
|
40
|
-
fields.push(contract.combo_legs.size)
|
|
41
|
-
fields += contract.combo_legs.map { |leg| leg.price || '' }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# TODO: smartComboRoutingParams
|
|
45
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_smart_combo_routing_params] # 57
|
|
46
|
-
fields.push(order.combo_params.size)
|
|
47
|
-
fields += order.combo_params.to_a
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
fields << order.serialize_auxilery_order_fields # incluing advisory order fields
|
|
52
|
-
|
|
53
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_models_support]
|
|
54
|
-
fields.push(order.model_code )
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
fields += [
|
|
58
|
-
order[:short_sale_slot] , # 0 only for retail, 1 or 2 for institution (Institutional)
|
|
59
|
-
order.designated_location # only populate when short_sale_slot == 2 (Institutional)
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
fields.push(order.exempt_code) if server_version >= KNOWN_SERVERS[:min_server_ver_sshortx_old]
|
|
63
|
-
|
|
64
|
-
fields.push(order[:oca_type])
|
|
65
|
-
fields += [
|
|
66
|
-
order[:rule_80a], # .to_sup[0..0],
|
|
67
|
-
order.settling_firm,
|
|
68
|
-
order.all_or_none,
|
|
69
|
-
order.min_quantity,
|
|
70
|
-
order.percent_offset,
|
|
71
|
-
false, # was: order.etrade_only || false, desupported in TWS > 981
|
|
72
|
-
false, # was: order.firm_quote_only || false, desupported in TWS > 981
|
|
73
|
-
'', ## desupported in TWS > 981, too. maybe we have to insert a hard-coded "" here
|
|
74
|
-
order[:auction_strategy], # AUCTION_MATCH, AUCTION_IMPROVEMENT, AUCTION_TRANSPARENT
|
|
75
|
-
order.starting_price ,
|
|
76
|
-
order.stock_ref_price ,
|
|
77
|
-
order.delta ,
|
|
78
|
-
order.stock_range_lower ,
|
|
79
|
-
order.stock_range_upper ,
|
|
80
|
-
order.override_percentage_constraints,
|
|
81
|
-
order.serialize_volatility_order_fields,
|
|
82
|
-
order.serialize_delta_neutral_order_fields
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
fields += [
|
|
86
|
-
order.continuous_update,
|
|
87
|
-
order[:reference_price_type] ,
|
|
88
|
-
order.trail_stop_price,
|
|
89
|
-
order.trailing_percent
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
fields << order.serialize_scale_order_fields
|
|
93
|
-
|
|
94
|
-
fields.push order.hedge_type
|
|
95
|
-
fields.push order.hedge_param # default is [] --> omitted if left default
|
|
96
|
-
fields.push order.opt_out_smart_routing
|
|
97
|
-
|
|
98
|
-
fields.push order.clearing_account
|
|
99
|
-
fields.push order.clearing_intent
|
|
100
|
-
|
|
101
|
-
fields.push(order.not_held) if server_version >= KNOWN_SERVERS[:min_server_ver_not_held] #44
|
|
102
|
-
|
|
103
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_delta_neutral] # 40
|
|
104
|
-
fields += contract.serialize_under_comp
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_algo_orders] # 41
|
|
108
|
-
fields += order.serialize_algo
|
|
109
|
-
end
|
|
110
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_algo_id] # 71
|
|
111
|
-
fields.push(order.algo_id)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
fields.push(order.what_if)
|
|
115
|
-
fields.push(order.serialize_misc_options) if server_version >= KNOWN_SERVERS[:min_server_ver_linking] # 70
|
|
116
|
-
fields.push(order.solicided) if server_version >= KNOWN_SERVERS[:min_server_ver_order_solicited] # 73
|
|
117
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_randomize_size_and_price] # 76
|
|
118
|
-
fields += [
|
|
119
|
-
order.random_size,
|
|
120
|
-
order.random_price
|
|
121
|
-
]
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
fields << order.serialize_pegged_order_fields
|
|
125
|
-
fields += order.serialize_conditions
|
|
126
|
-
fields += [
|
|
127
|
-
order.adjusted_order_type,
|
|
128
|
-
order.trigger_price,
|
|
129
|
-
order.limit_price_offset,
|
|
130
|
-
order.adjusted_stop_price,
|
|
131
|
-
order.adjusted_stop_limit_price,
|
|
132
|
-
order.adjusted_trailing_amount,
|
|
133
|
-
order.adjustable_trailing_unit
|
|
134
|
-
]
|
|
135
|
-
|
|
136
|
-
fields.push(order.ext_operator) if server_version >= KNOWN_SERVERS[:min_server_ver_ext_operator]
|
|
137
|
-
|
|
138
|
-
fields << order.serialize_soft_dollar_tier
|
|
139
|
-
|
|
140
|
-
fields.push(order.cash_qty) if server_version >= KNOWN_SERVERS[:min_server_ver_cash_qty] # 111
|
|
141
|
-
|
|
142
|
-
fields << order.serialize_mifid_order_fields
|
|
143
|
-
|
|
144
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_auto_price_for_hedge]
|
|
145
|
-
fields.push(order.dont_use_auto_price_for_hedge)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
fields.push(order.is_O_ms_container) if server_version >= KNOWN_SERVERS[:min_server_ver_order_container]
|
|
149
|
-
|
|
150
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_d_peg_orders]
|
|
151
|
-
fields.push(order.discretionary_up_to_limit_price)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_price_mgmt_algo]
|
|
155
|
-
fields.push(order.use_price_management_algo)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_duration]
|
|
159
|
-
fields.push(order.duration)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_post_to_ats]
|
|
163
|
-
fields.push(order.post_to_ats)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_auto_cancel_parent]
|
|
167
|
-
fields.push(order.auto_cancel_parent)
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_advanced_order_reject]
|
|
171
|
-
fields.push(order.advanced_order_reject)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_manual_order_time]
|
|
175
|
-
fields.push(order.manual_order_time)
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
fields << order.serialize_peg_best_and_mid
|
|
179
|
-
|
|
180
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_customer_account]
|
|
181
|
-
fields.push(order.customer_account)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
if server_version >= KNOWN_SERVERS[:min_server_ver_professional_customer]
|
|
185
|
-
fields.push(order.professional_account)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
fields
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
module IB
|
|
2
|
-
module Messages
|
|
3
|
-
module Outgoing
|
|
4
|
-
extend Messages # def_message macros
|
|
5
|
-
|
|
6
|
-
# Data format is { :id => local_id,
|
|
7
|
-
# :contract => Contract,
|
|
8
|
-
# :order => Order }
|
|
9
|
-
PlaceOrder = def_message [ 3,0 ]
|
|
10
|
-
|
|
11
|
-
class PlaceOrder
|
|
12
|
-
def encode
|
|
13
|
-
|
|
14
|
-
# lamba's to include order fields dependend of the server version provided
|
|
15
|
-
include_model_code = -> (m) { if server_version >= KNOWN_SERVERS[ :min_server_ver_models_support ] then m else [] end }
|
|
16
|
-
include_ext_operator = -> (e) { if server_version >= KNOWN_SERVERS[ :min_server_ver_ext_operator ] then e else [] end }
|
|
17
|
-
include_cash_qty = -> (c) { if server_version >= KNOWN_SERVERS[ :min_server_ver_cash_qty ] then c else [] end }
|
|
18
|
-
include_auto_price_for_hedge = -> (a) { if server_version >= KNOWN_SERVERS[ :min_server_ver_auto_price_for_hedge ] then a else [] end }
|
|
19
|
-
include_order_container = -> (o) { if server_version >= KNOWN_SERVERS[ :min_server_ver_order_container] then o else [] end }
|
|
20
|
-
include_d_peg_order = -> (d) { if server_version >= KNOWN_SERVERS[ :min_server_ver_d_peg_orders ] then d else [] end }
|
|
21
|
-
include_price_mgmt_algo = -> (p) { if server_version >= KNOWN_SERVERS[ :min_server_ver_price_mgmt_algo ]then p else [] end }
|
|
22
|
-
include_duration = -> (d) { if server_version >= KNOWN_SERVERS[ :min_server_ver_duration ]then d else [] end }
|
|
23
|
-
include_ats = -> (a) { if server_version >= KNOWN_SERVERS[ :min_server_ver_post_to_ats ]then a else [] end }
|
|
24
|
-
include_auto_cancel_parent = -> (a) { if server_version >= KNOWN_SERVERS[ :min_server_ver_auto_cancel_parent ] then a else [] end }
|
|
25
|
-
include_manual_order_time = -> (m) { if server_version >= KNOWN_SERVERS[ :min_server_ver_manual_order_time ] then m else [] end }
|
|
26
|
-
include_advanced_reject = -> (a){ if server_version >= KNOWN_SERVERS[ :min_server_ver_advanced_order_reject ] then a else [] end }
|
|
27
|
-
include_customer_account = -> (c) { if server_version >= KNOWN_SERVERS[ :min_server_ver_customer_account ] then c else [] end }
|
|
28
|
-
include_professional_customer = -> (p) { if server_version >= KNOWN_SERVERS[ :min_server_ver_professional_customer ] then p else [] end }
|
|
29
|
-
|
|
30
|
-
order = @data[ :order ]
|
|
31
|
-
contract = @data[ :contract ]
|
|
32
|
-
|
|
33
|
-
error "contract has to be specified" unless contract.is_a? IB::Contract
|
|
34
|
-
|
|
35
|
-
# -------------------------- start here -----------------------------------------
|
|
36
|
-
# build an array of order values ready to be transmitted to the tws ( after flattening )
|
|
37
|
-
#
|
|
38
|
-
[ super,
|
|
39
|
-
contract.serialize_short( :primary_exchange, :sec_id_type ),
|
|
40
|
-
order.serialize_main_order_fields,
|
|
41
|
-
order.serialize_extended_order_fields,
|
|
42
|
-
# legs
|
|
43
|
-
[ contract.serialize_legs( :extended ),
|
|
44
|
-
if contract.bag?
|
|
45
|
-
[
|
|
46
|
-
## Support for per-leg prices in Order
|
|
47
|
-
[contract.combo_legs.size] + contract.combo_legs.map { |_| nil }, #(&:price) ,
|
|
48
|
-
## Support for combo routing params in Order
|
|
49
|
-
order.combo_params.empty? ? 0 : [order.combo_params.size] + order.combo_params.to_a
|
|
50
|
-
]
|
|
51
|
-
else
|
|
52
|
-
[ "do not include" ]
|
|
53
|
-
end ],
|
|
54
|
-
order.serialize_auxilery_order_fields, # incluing advisory order fields
|
|
55
|
-
# regulatory order fields
|
|
56
|
-
[
|
|
57
|
-
include_model_code[ order.model_code ],
|
|
58
|
-
order[:short_sale_slot] , # 0 only for retail, 1 or 2 for institution (Institutional)
|
|
59
|
-
order.designated_location, # only populate when short_sale_slot == 2 (Institutional)
|
|
60
|
-
order.exempt_code,
|
|
61
|
-
order[:oca_type],
|
|
62
|
-
order[:rule_80a], #.to_sup[0..0],
|
|
63
|
-
order.settling_firm ],
|
|
64
|
-
# algo order fields -1- (8)
|
|
65
|
-
[ order.all_or_none,
|
|
66
|
-
order.min_quantity ,
|
|
67
|
-
order.percent_offset,
|
|
68
|
-
false, # was: order.etrade_only || false, desupported in TWS > 981
|
|
69
|
-
false, # was: order.firm_quote_only || false, desupported in TWS > 981
|
|
70
|
-
false, # was order.nbbo_price_cap || "", ## desupported in TWS > 981
|
|
71
|
-
order[:auction_strategy],
|
|
72
|
-
order.starting_price,
|
|
73
|
-
order.stock_ref_price,
|
|
74
|
-
order.delta,
|
|
75
|
-
order.stock_range_lower,
|
|
76
|
-
order.stock_range_upper,
|
|
77
|
-
order.override_percentage_constraints,
|
|
78
|
-
order.serialize_volatility_order_fields
|
|
79
|
-
],
|
|
80
|
-
|
|
81
|
-
order.serialize_delta_neutral_order_fields, # (9)
|
|
82
|
-
|
|
83
|
-
# Volatility orders (10)
|
|
84
|
-
[
|
|
85
|
-
order.continuous_update,
|
|
86
|
-
order[:reference_price_type],
|
|
87
|
-
],
|
|
88
|
-
# trailing orders (11)
|
|
89
|
-
#
|
|
90
|
-
[
|
|
91
|
-
order.trail_stop_price,
|
|
92
|
-
order.trailing_percent,
|
|
93
|
-
],
|
|
94
|
-
|
|
95
|
-
order.serialize_scale_order_fields, # (12)
|
|
96
|
-
|
|
97
|
-
# Support for hedgeType (13)
|
|
98
|
-
[
|
|
99
|
-
order.hedge_type,
|
|
100
|
-
order.hedge_param
|
|
101
|
-
],
|
|
102
|
-
|
|
103
|
-
order.opt_out_smart_routing,
|
|
104
|
-
|
|
105
|
-
order.clearing_account ,
|
|
106
|
-
order.clearing_intent ,
|
|
107
|
-
order.not_held ,
|
|
108
|
-
contract.serialize_under_comp,
|
|
109
|
-
order.serialize_algo(),
|
|
110
|
-
order.what_if,
|
|
111
|
-
order.serialize_misc_options,
|
|
112
|
-
order.solicided,
|
|
113
|
-
order.random_size,
|
|
114
|
-
order.random_price,
|
|
115
|
-
order.serialize_pegged_order_fields,
|
|
116
|
-
order.serialize_conditions ,
|
|
117
|
-
order.adjusted_order_type ,
|
|
118
|
-
order.trigger_price ,
|
|
119
|
-
order.limit_price_offset ,
|
|
120
|
-
order.adjusted_stop_price ,
|
|
121
|
-
order.adjusted_stop_limit_price ,
|
|
122
|
-
order.adjusted_trailing_amount ,
|
|
123
|
-
order.adjustable_trailing_unit ,
|
|
124
|
-
include_ext_operator[ order.ext_operator ] ,
|
|
125
|
-
order.serialize_soft_dollar_tier,
|
|
126
|
-
include_cash_qty[ order.cash_qty ] ,
|
|
127
|
-
order.serialize_mifid_order_fields,
|
|
128
|
-
include_auto_price_for_hedge[ order.dont_use_auto_price_for_hedge ],
|
|
129
|
-
include_order_container[ order.is_O_ms_container ],
|
|
130
|
-
include_d_peg_order[ order.discretionary_up_to_limit_price ],
|
|
131
|
-
include_price_mgmt_algo[ order.use_price_management_algo ],
|
|
132
|
-
include_duration[ order.duration ],
|
|
133
|
-
include_ats[ order.post_to_ats ],
|
|
134
|
-
include_auto_cancel_parent[ order.auto_cancel_parent ],
|
|
135
|
-
include_advanced_reject[ order.advanced_order_reject ],
|
|
136
|
-
include_manual_order_time[ order.manual_order_time ],
|
|
137
|
-
order.serialize_peg_best_and_mid,
|
|
138
|
-
include_customer_account[ order.customer_account ],
|
|
139
|
-
include_professional_customer[ order.professional_account ]
|
|
140
|
-
]
|
|
141
|
-
end # encode
|
|
142
|
-
end # PlaceOrder
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
end # module Outgoing
|
|
146
|
-
end # module Messages
|
|
147
|
-
end # module IB
|