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,3 +1,5 @@
|
|
|
1
|
+
require 'ib/messages/abstract_message'
|
|
2
|
+
|
|
1
3
|
module IB
|
|
2
4
|
module Messages
|
|
3
5
|
module Outgoing
|
|
@@ -22,7 +24,10 @@ module IB
|
|
|
22
24
|
# each one and postpending a '\0'.
|
|
23
25
|
#
|
|
24
26
|
def send_to socket
|
|
25
|
-
|
|
27
|
+
### debugging of outgoing Messages
|
|
28
|
+
# puts "------sendto ---------(debugging output in outgoing/abstract_message)"
|
|
29
|
+
# puts socket.prepare_message( self.preprocess).inspect.split('\x00')[3..-1].inspect
|
|
30
|
+
# puts "------sendto ---------"
|
|
26
31
|
socket.send_messages self.preprocess #.each {|data| socket.write_data data}
|
|
27
32
|
end
|
|
28
33
|
|
|
@@ -34,7 +39,7 @@ module IB
|
|
|
34
39
|
# Pre-process encoded message Array before sending into socket, such as
|
|
35
40
|
# changing booleans into 0/1 and stuff
|
|
36
41
|
def preprocess
|
|
37
|
-
self.encode.flatten.
|
|
42
|
+
self.encode.flatten.map {|data| data == true ? 1 : data == false ? 0 : data }
|
|
38
43
|
end
|
|
39
44
|
|
|
40
45
|
# Encode message content into (possibly, nested) Array of values.
|
|
@@ -42,30 +47,29 @@ module IB
|
|
|
42
47
|
# Most messages also contain (ticker, request or order) :id.
|
|
43
48
|
# Then, content of @data Hash is encoded per instructions in data_map.
|
|
44
49
|
# This method may be modified by message subclasses!
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
#
|
|
51
|
+
# If the version is zero, omit its apperance (for historical data)
|
|
47
52
|
def encode
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
## create a proper request_id and erase :id and :ticker_id if nessesary
|
|
54
|
+
if self.class.properties?.include?(:request_id)
|
|
55
|
+
@data[:request_id] = if @data[:request_id].blank? && @data[:ticker_id].blank? && @data[:id].blank?
|
|
56
|
+
rand(9999)
|
|
57
|
+
else
|
|
58
|
+
@data[:id] || @data[:ticker_id] || @data[:request_id]
|
|
59
|
+
end
|
|
60
|
+
@data[:id] = @data[:ticker_id] = nil
|
|
61
|
+
end
|
|
57
62
|
[
|
|
58
|
-
|
|
59
|
-
# include :id, :ticker_id, :local_id or :order_id as first field of the message (if present)
|
|
63
|
+
self.class.version.zero? ? self.class.message_id : [ self.class.message_id, self.class.version ],
|
|
60
64
|
@data[:id] || @data[:ticker_id] ||# @data[:request_id] || # id, ticker_id, local_id, order_id
|
|
61
|
-
@data[:local_id] || @data[:order_id] || [],
|
|
65
|
+
@data[:local_id] || @data[:order_id] || [], # do not appear in data_map
|
|
62
66
|
self.class.data_map.map do |(field, default_method, args)| # but request_id does
|
|
63
67
|
case
|
|
64
68
|
when default_method.nil?
|
|
65
69
|
@data[field]
|
|
66
|
-
|
|
70
|
+
|
|
67
71
|
when default_method.is_a?(Symbol) # method name with args
|
|
68
|
-
@data[field].send default_method, *args
|
|
72
|
+
@data[field].send default_method, *args
|
|
69
73
|
|
|
70
74
|
when default_method.respond_to?(:call) # callable with args
|
|
71
75
|
default_method.call @data[field], *args
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
|
|
1
2
|
module IB
|
|
2
3
|
module Messages
|
|
3
4
|
module Outgoing
|
|
4
|
-
extend Messages # def_message macros
|
|
5
5
|
|
|
6
|
+
RequestManagedAccounts = def_message 17
|
|
7
|
+
|
|
8
|
+
# @data = { :subscribe => boolean,
|
|
9
|
+
# :account_code => Advisor accounts only. Empty ('') for a standard account. }
|
|
10
|
+
RequestAccountUpdates = RequestAccountData = def_message([6, 2],
|
|
11
|
+
[:subscribe, true],
|
|
12
|
+
:account_code)
|
|
6
13
|
=begin
|
|
7
14
|
Call this method to request and keep up to date the data that appears
|
|
8
15
|
on the TWS Account Window Summary tab. The data is returned by
|
|
@@ -59,15 +66,41 @@ module IB
|
|
|
59
66
|
currencies.
|
|
60
67
|
|
|
61
68
|
=end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
RequestAccountSummary = def_message( 62,
|
|
70
|
+
:request_id, # autogenerated if not specified
|
|
71
|
+
[:group, 'All'],
|
|
72
|
+
:tags )
|
|
73
|
+
|
|
74
|
+
CancelAccountSummary = def_message 63 # :request_id required
|
|
75
|
+
|
|
76
|
+
# Note: The reqPositions function is not available in Introducing
|
|
77
|
+
# Broker or Financial Advisor master accounts that have very large
|
|
78
|
+
# numbers of subaccounts (> 50) to optimize the performance of TWS/IB
|
|
79
|
+
# Gateway v973+. Instead the function reqPositionsMulti can be used
|
|
80
|
+
# to subscribe to updates from individual subaccounts. Also not
|
|
81
|
+
# available with IBroker accounts configured for on-demand account
|
|
82
|
+
# lookup.
|
|
83
|
+
RequestPositions = def_message 61
|
|
84
|
+
CancelPositions = def_message 64
|
|
66
85
|
|
|
86
|
+
|
|
87
|
+
# The function reqPositionsMulti can be used with any
|
|
88
|
+
# account structure to subscribe to positions updates for multiple
|
|
89
|
+
# accounts and/or models. The account and model parameters are
|
|
90
|
+
# optional if there are not multiple accounts or models available.
|
|
91
|
+
RequestPositionsMulti = def_message( 74, :request_id, # autogenerated
|
|
92
|
+
[ :account, 'ALL' ],
|
|
93
|
+
[:model_code, nil ] )
|
|
67
94
|
|
|
95
|
+
CancelPositionsMulti = def_message( 75, :request_id ) # required
|
|
68
96
|
|
|
69
|
-
|
|
70
|
-
|
|
97
|
+
RequestAccountUpdatesMulti = def_message( 76, :request_id, # autogenerated
|
|
98
|
+
[ :account, 'ALL'], # account or account-group
|
|
99
|
+
[:model_code, nil],
|
|
100
|
+
[:leger_and_nlv, nil ])
|
|
101
|
+
CancelAccountUpdatesMulti = def_message 77, :request_id # required
|
|
102
|
+
end # module outgoing
|
|
103
|
+
end # module messages
|
|
71
104
|
end # module ib
|
|
72
105
|
|
|
73
106
|
# REQ_POSITIONS = 61
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module IB
|
|
2
2
|
module Messages
|
|
3
3
|
module Outgoing
|
|
4
|
-
extend Messages # def_message macros
|
|
5
4
|
|
|
6
5
|
# Messages that request bar data have special processing of @data
|
|
7
6
|
|
|
@@ -19,10 +18,11 @@ module IB
|
|
|
19
18
|
# unless BAR_SIZES.keys.include?(bar_size)
|
|
20
19
|
# error ":bar_size must be one of #{BAR_SIZES.inspect}", :args
|
|
21
20
|
# end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
|
|
22
|
+
contract = data[:contract].is_a?(IB::Contract) ?
|
|
23
|
+
data[:contract] : IB::Contract.from_ib_ruby(data[:contract])
|
|
24
|
+
|
|
25
|
+
[data_type, nil, contract]
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -44,7 +44,7 @@ module IB
|
|
|
44
44
|
#
|
|
45
45
|
# Version 3
|
|
46
46
|
RequestRealTimeBars = def_message [ 50, 3 ], BarRequestMessage,
|
|
47
|
-
|
|
47
|
+
:request_id # autogenerated if not specified
|
|
48
48
|
|
|
49
49
|
class RequestRealTimeBars
|
|
50
50
|
def parse data
|
|
@@ -63,14 +63,17 @@ module IB
|
|
|
63
63
|
bar_size,
|
|
64
64
|
data_type.to_s.upcase,
|
|
65
65
|
@data[:use_rth] ,
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
"XYZ" # not suported realtimebars option string
|
|
67
|
+
]
|
|
68
68
|
end
|
|
69
69
|
end # RequestRealTimeBars
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
## python reference (9.74)
|
|
72
|
+
# def reqHistoricalData(self, reqId:TickerId , contract:Contract, endDateTime:str,
|
|
73
|
+
# durationStr:str, barSizeSetting:str, whatToShow:str,
|
|
74
|
+
# useRTH:int, formatDate:int, keepUpToDate:bool, chartOptions:TagValueList)
|
|
72
75
|
RequestHistoricalData = def_message [20, 0], BarRequestMessage,
|
|
73
|
-
|
|
76
|
+
:request_id # autogenerated if not specified
|
|
74
77
|
|
|
75
78
|
# - data = {
|
|
76
79
|
# :contract => Contract: requested ticker description
|
|
@@ -186,9 +189,9 @@ module IB
|
|
|
186
189
|
data_type.to_s.upcase,
|
|
187
190
|
2 , # @data[:format_date], format-date is hard-coded as int_date in incoming/historicalData
|
|
188
191
|
contract.serialize_legs ,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
@data[:keep_up_todate], # 0 / 1
|
|
193
|
+
'XYZ' # chartOptions:TagValueList - For internal use only. Use default value XYZ.
|
|
194
|
+
]
|
|
192
195
|
end
|
|
193
196
|
end # RequestHistoricalData
|
|
194
197
|
|
|
@@ -1,149 +1,209 @@
|
|
|
1
1
|
module IB
|
|
2
2
|
module Messages
|
|
3
3
|
module Outgoing
|
|
4
|
-
extend Messages # def_message macros
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
# Data format is { :id => int: local_id,
|
|
6
|
+
# :contract => Contract,
|
|
7
|
+
# :order => Order }
|
|
8
|
+
PlaceOrder = def_message [3, 45] ## ServerVersion > 145: def_message[ 0,45 ]
|
|
9
|
+
## server-version is not known at compilation time
|
|
10
|
+
## Method call has to be replaced then
|
|
11
|
+
## Max-Client_ver --> 144!!
|
|
7
12
|
|
|
8
13
|
class PlaceOrder
|
|
14
|
+
|
|
9
15
|
def encode
|
|
16
|
+
# server_version = Connection.current.server_version
|
|
10
17
|
order = @data[:order]
|
|
11
18
|
contract = @data[:contract]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
order.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
19
|
+
error "contract has to be specified" unless contract.is_a? IB::Contract
|
|
20
|
+
[super[0..-1],
|
|
21
|
+
# [ [3,45, @data[:local_id] ],
|
|
22
|
+
contract.serialize_short(:primary_exchange, :sec_id_type),
|
|
23
|
+
|
|
24
|
+
# main order fields
|
|
25
|
+
(order.side == :short ? 'SSHORT' : order.side == :short_exempt ? 'SSHORTX' : order.side.to_sup),
|
|
26
|
+
order.total_quantity,
|
|
27
|
+
order[:order_type], # Internal code, 'LMT' instead of :limit
|
|
28
|
+
order.limit_price,
|
|
29
|
+
order.aux_price,
|
|
30
|
+
order[:tif],
|
|
31
|
+
order.oca_group,
|
|
32
|
+
order.account,
|
|
33
|
+
order.open_close.to_sup[0],
|
|
34
|
+
order[:origin], # translates :customer, :firm to 0,1
|
|
35
|
+
order.order_ref,
|
|
36
|
+
order.transmit,
|
|
37
|
+
order.parent_id,
|
|
38
|
+
order.block_order || false,
|
|
39
|
+
order.sweep_to_fill || false,
|
|
40
|
+
order.display_size,
|
|
41
|
+
order[:trigger_method],
|
|
42
|
+
order.outside_rth || false, # was: ignore_rth
|
|
43
|
+
order.hidden || false,
|
|
44
|
+
contract.serialize_legs(:extended),
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if contract.bag?
|
|
48
|
+
[
|
|
49
|
+
## Support for per-leg prices in Order
|
|
50
|
+
[contract.combo_legs.size] + contract.combo_legs.map { |_| nil }, #(&:price) ,
|
|
51
|
+
## Support for combo routing params in Order
|
|
52
|
+
order.combo_params.empty? ? 0 : [order.combo_params.size] + order.combo_params.to_a
|
|
53
|
+
]
|
|
54
|
+
else
|
|
55
|
+
[]
|
|
56
|
+
end,
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
"", # deprecated shares_allocation field
|
|
60
|
+
order.discretionary_amount,
|
|
61
|
+
order.good_after_time,
|
|
62
|
+
order.good_till_date,
|
|
63
|
+
[ order.fa_group,
|
|
64
|
+
order.fa_method,
|
|
65
|
+
order.fa_percentage,
|
|
66
|
+
order.fa_profile ] ,
|
|
67
|
+
order.model_code || "",
|
|
68
|
+
order[:short_sale_slot] || 0 , # 0 only for retail, 1 or 2 for institution (Institutional)
|
|
69
|
+
order.designated_location, # only populate when short_sale_slot == 2 (Institutional)
|
|
70
|
+
order.exempt_code,
|
|
71
|
+
order[:oca_type],
|
|
72
|
+
order[:rule_80a], #.to_sup[0..0],
|
|
73
|
+
order.settling_firm,
|
|
74
|
+
order.all_or_none || false,
|
|
75
|
+
order.min_quantity || "",
|
|
76
|
+
order.percent_offset || '',
|
|
77
|
+
order.etrade_only || false,
|
|
78
|
+
order.firm_quote_only || false,
|
|
79
|
+
order.nbbo_price_cap || "",
|
|
80
|
+
order[:auction_strategy],
|
|
81
|
+
order.starting_price,
|
|
82
|
+
order.stock_ref_price || "",
|
|
83
|
+
order.delta || "",
|
|
84
|
+
order.stock_range_lower || "",
|
|
85
|
+
order.stock_range_upper || "",
|
|
86
|
+
order.override_percentage_constraints || false,
|
|
87
|
+
if order.volatility.present?
|
|
88
|
+
[ order.volatility , # Volatility orders
|
|
89
|
+
order[:volatility_type] || 2 ] # default: annual volatility
|
|
90
|
+
else
|
|
91
|
+
["",""]
|
|
92
|
+
end,
|
|
93
|
+
# Support for delta neutral orders with parameters
|
|
94
|
+
if order.delta_neutral_order_type && order.delta_neutral_order_type != :none
|
|
95
|
+
[order[:delta_neutral_order_type],
|
|
96
|
+
order.delta_neutral_aux_price || "",
|
|
97
|
+
order.delta_neutral_con_id,
|
|
98
|
+
order.delta_neutral_settling_firm,
|
|
99
|
+
order.delta_neutral_clearing_account,
|
|
100
|
+
order[:delta_neutral_clearing_intent],
|
|
101
|
+
order.delta_neutral_open_close,
|
|
102
|
+
order.delta_neutral_short_sale,
|
|
103
|
+
order.delta_neutral_short_sale_slot,
|
|
104
|
+
order.delta_neutral_designated_location ]
|
|
105
|
+
else
|
|
106
|
+
['', '']
|
|
107
|
+
end,
|
|
108
|
+
|
|
109
|
+
order.continuous_update, # Volatility orders
|
|
110
|
+
order[:reference_price_type] || "", # Volatility orders
|
|
111
|
+
|
|
112
|
+
order.trail_stop_price || "", # TRAIL_STOP_LIMIT stop price
|
|
113
|
+
order.trailing_percent || "", # Support for trailing percent
|
|
114
|
+
|
|
115
|
+
order.scale_init_level_size || "", # Scale Orders
|
|
116
|
+
order.scale_subs_level_size || "", # Scale Orders
|
|
117
|
+
order.scale_price_increment || "", # Scale Orders
|
|
118
|
+
|
|
119
|
+
# Support for extended scale orders parameters
|
|
120
|
+
if order.scale_price_increment && order.scale_price_increment > 0
|
|
121
|
+
[order.scale_price_adjust_value || "",
|
|
122
|
+
order.scale_price_adjust_interval || "",
|
|
123
|
+
order.scale_profit_offset || "",
|
|
124
|
+
order.scale_auto_reset, # default: false,
|
|
125
|
+
order.scale_init_position || "",
|
|
126
|
+
order.scale_init_fill_qty || "",
|
|
127
|
+
order.scale_random_percent # default: false,
|
|
128
|
+
]
|
|
129
|
+
else
|
|
130
|
+
[]
|
|
131
|
+
end,
|
|
132
|
+
|
|
133
|
+
order.scale_table, # v 69
|
|
134
|
+
order.active_start_time || "" , # v 69
|
|
135
|
+
order.active_stop_time || "" , # v 69
|
|
136
|
+
|
|
137
|
+
# Support for hedgeType
|
|
138
|
+
order.hedge_type, # MIN_SERVER_VER_HEDGE_ORDERS
|
|
139
|
+
order.hedge_param || [],
|
|
140
|
+
|
|
141
|
+
order.opt_out_smart_routing, # MIN_SERVER_VER_OPT_OUT_SMART_ROUTING
|
|
142
|
+
|
|
143
|
+
order.clearing_account ,
|
|
144
|
+
order.clearing_intent ,
|
|
145
|
+
order.not_held ,
|
|
146
|
+
contract.serialize_under_comp,
|
|
147
|
+
order.serialize_algo(),
|
|
148
|
+
order.what_if,
|
|
149
|
+
order.serialize_misc_options, # MIN_SERVER_VER_LINKING
|
|
150
|
+
order.solicided , # MIN_SERVER_VER_ORDER_SOLICITED
|
|
151
|
+
order.random_size , # MIN_SERVER_VER_RANDOMIZE_SIZE_AND_PRICE
|
|
152
|
+
order.random_price , # MIN_SERVER_VER_RANDOMIZE_SIZE_AND_PRICE
|
|
153
|
+
( order[:type] == 'PEG BENCH' ? [ # pegged_to_benchmark v. 102
|
|
154
|
+
order.reference_contract_id,
|
|
155
|
+
order.is_pegged_change_amount_decrease,
|
|
156
|
+
order.pegged_change_amount,
|
|
157
|
+
order.reference_change_amount,
|
|
158
|
+
order.reference_exchange_id ] : [] ),
|
|
159
|
+
order.serialize_conditions , # serialisation of conditions outsourced to model file
|
|
160
|
+
order.adjusted_order_type ,
|
|
161
|
+
order.trigger_price ,
|
|
162
|
+
order.limit_price_offset ,
|
|
163
|
+
order.adjusted_stop_price ,
|
|
164
|
+
order.adjusted_stop_limit_price ,
|
|
165
|
+
order.adjusted_trailing_amount ,
|
|
166
|
+
order.adjustable_trailing_unit ,
|
|
167
|
+
order.ext_operator , # MIN_SERVER_VER_EXT_OPERATOR:
|
|
168
|
+
order.soft_dollar_tier_name,
|
|
169
|
+
order.soft_dollar_tier_value,
|
|
170
|
+
order.soft_dollar_tier_display_name,
|
|
171
|
+
# order.serialize_soft_dollar_tier() , # MIN_SERVER_VER_SOFT_DOLLAR_TIER
|
|
172
|
+
order.cash_qty , # MIN_SERVER_VER_CASH_QTY /111)
|
|
173
|
+
# if server_version >= 138 # :min_server_ver_decision_maker
|
|
174
|
+
[ order.mifid_2_decision_maker, order.mifid_2_decision_algo],
|
|
175
|
+
# end ,
|
|
176
|
+
# if server_version >= 139 # min_server_ver_mifid_execution
|
|
177
|
+
[ order.mifid_2_execution_maker, order.mifid_2_execution_algo ],
|
|
178
|
+
# end,
|
|
179
|
+
# if server_version >= 141 # min_server_ver_auto_price_for_hedge
|
|
180
|
+
order.dont_use_auto_price_for_hedge,
|
|
181
|
+
# end,
|
|
182
|
+
# if server_version >= 145 # min_server_ver_order_container
|
|
183
|
+
order.is_O_ms_container,
|
|
184
|
+
# end,
|
|
185
|
+
# if server_version >= 148 # min_server_ver_d_peg_orders
|
|
186
|
+
order.discretionary_up_to_limit_price
|
|
187
|
+
# end ]
|
|
188
|
+
]
|
|
189
|
+
#
|
|
190
|
+
#
|
|
191
|
+
#
|
|
192
|
+
# if self.serverVersion() >= MIN_SERVER_VER_AUTO_PRICE_FOR_HEDGE:141
|
|
193
|
+
# flds.append(make_field(order.dontUseAutoPriceForHedge))
|
|
194
|
+
#
|
|
195
|
+
# if self.serverVersion() >= MIN_SERVER_VER_ORDER_CONTAINER:145
|
|
196
|
+
# flds.append(make_field(order.isOmsContainer))
|
|
197
|
+
#
|
|
198
|
+
# if self.serverVersion() >= MIN_SERVER_VER_D_PEG_ORDERS: 148
|
|
199
|
+
# flds.append(make_field(order.discretionaryUpToLimitPrice))
|
|
200
|
+
#
|
|
201
|
+
#
|
|
143
202
|
|
|
144
|
-
fields
|
|
145
203
|
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
end
|
|
204
|
+
end # PlaceOrder
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
end # module Outgoing
|
|
208
|
+
end # module Messages
|
|
209
|
+
end # module IB
|