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.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/Gemfile +2 -3
  4. data/Gemfile.lock +52 -67
  5. data/README.md +8 -60
  6. data/VERSION +1 -1
  7. data/api.gemspec +3 -10
  8. data/bin/console +38 -39
  9. data/bin/console.yml +2 -2
  10. data/changelog.md +0 -25
  11. data/example/README.md +76 -0
  12. data/example/account_info +54 -0
  13. data/example/account_positions +30 -0
  14. data/example/account_summary +88 -0
  15. data/example/cancel_orders +74 -0
  16. data/example/fa_accounts +25 -0
  17. data/example/fundamental_data +40 -0
  18. data/example/historic_data_cli +186 -0
  19. data/example/list_orders +45 -0
  20. data/example/portfolio_csv +81 -0
  21. data/example/scanner_data +62 -0
  22. data/example/template +19 -0
  23. data/example/tick_data +28 -0
  24. data/lib/extensions/class-extensions.rb +87 -0
  25. data/lib/ib/base.rb +1 -7
  26. data/lib/ib/base_properties.rb +12 -30
  27. data/lib/ib/connection.rb +269 -418
  28. data/lib/ib/constants.rb +22 -31
  29. data/lib/ib/errors.rb +1 -9
  30. data/lib/ib/logger.rb +26 -0
  31. data/lib/ib/messages/abstract_message.rb +43 -10
  32. data/lib/ib/messages/incoming/abstract_message.rb +98 -98
  33. data/lib/ib/messages/incoming/account_value.rb +78 -0
  34. data/lib/ib/messages/incoming/alert.rb +4 -4
  35. data/lib/ib/messages/incoming/contract_data.rb +29 -32
  36. data/lib/ib/messages/incoming/execution_data.rb +3 -3
  37. data/lib/ib/messages/incoming/historical_data.rb +33 -14
  38. data/lib/ib/messages/incoming/{market_depth.rb → market_depths.rb} +10 -0
  39. data/lib/ib/messages/incoming/next_valid_id.rb +0 -1
  40. data/lib/ib/messages/incoming/open_order.rb +201 -214
  41. data/lib/ib/messages/incoming/order_status.rb +1 -1
  42. data/lib/ib/messages/incoming/portfolio_value.rb +58 -27
  43. data/lib/ib/messages/incoming/scanner_data.rb +1 -1
  44. data/lib/ib/messages/incoming/ticks.rb +268 -0
  45. data/lib/ib/messages/incoming.rb +95 -136
  46. data/lib/ib/messages/outgoing/abstract_message.rb +22 -18
  47. data/lib/ib/messages/outgoing/{request_account_summary.rb → account_requests.rb} +40 -7
  48. data/lib/ib/messages/outgoing/{bar_request_message.rb → bar_requests.rb} +16 -13
  49. data/lib/ib/messages/outgoing/place_order.rb +198 -138
  50. data/lib/ib/messages/outgoing/{request_market_data.rb → request_marketdata.rb} +29 -32
  51. data/lib/ib/messages/outgoing/request_tick_data.rb +21 -0
  52. data/lib/ib/messages/outgoing.rb +160 -133
  53. data/lib/ib/messages.rb +7 -47
  54. data/lib/ib/model.rb +4 -0
  55. data/lib/ib/models.rb +14 -0
  56. data/lib/{server_versions.rb → ib/server_versions.rb} +9 -40
  57. data/lib/ib/socket.rb +147 -45
  58. data/lib/ib/support.rb +158 -240
  59. data/lib/ib/version.rb +1 -1
  60. data/lib/ib-api.rb +5 -42
  61. data/lib/models/ib/account.rb +85 -0
  62. data/{models → lib/models}/ib/account_value.rb +5 -5
  63. data/{models → lib/models}/ib/bag.rb +7 -7
  64. data/{models → lib/models}/ib/bar.rb +2 -2
  65. data/{models → lib/models}/ib/combo_leg.rb +4 -26
  66. data/lib/models/ib/condition.rb +245 -0
  67. data/{models → lib/models}/ib/contract.rb +170 -166
  68. data/{models → lib/models}/ib/contract_detail.rb +15 -25
  69. data/{models → lib/models}/ib/execution.rb +1 -1
  70. data/{models → lib/models}/ib/forex.rb +2 -1
  71. data/lib/models/ib/future.rb +15 -0
  72. data/{models → lib/models}/ib/index.rb +3 -2
  73. data/lib/models/ib/option.rb +78 -0
  74. data/lib/models/ib/option_detail.rb +55 -0
  75. data/{models → lib/models}/ib/order.rb +165 -366
  76. data/{models → lib/models}/ib/order_state.rb +22 -25
  77. data/lib/models/ib/portfolio_value.rb +64 -0
  78. data/lib/models/ib/stock.rb +16 -0
  79. data/{models → lib/models}/ib/underlying.rb +5 -3
  80. data/lib/models/ib/vertical.rb +96 -0
  81. data/lib/requires.rb +12 -0
  82. metadata +64 -188
  83. data/CLAUDE.md +0 -131
  84. data/LLM_GUIDE.md +0 -388
  85. data/bin/simple +0 -91
  86. data/conditions/ib/execution_condition.rb +0 -31
  87. data/conditions/ib/margin_condition.rb +0 -28
  88. data/conditions/ib/order_condition.rb +0 -29
  89. data/conditions/ib/percent_change_condition.rb +0 -34
  90. data/conditions/ib/price_condition.rb +0 -44
  91. data/conditions/ib/time_condition.rb +0 -42
  92. data/conditions/ib/volume_condition.rb +0 -36
  93. data/lib/class_extensions.rb +0 -167
  94. data/lib/ib/contract.rb +0 -30
  95. data/lib/ib/messages/incoming/abstract_tick.rb +0 -25
  96. data/lib/ib/messages/incoming/account_message.rb +0 -26
  97. data/lib/ib/messages/incoming/contract_message.rb +0 -13
  98. data/lib/ib/messages/incoming/histogram_data.rb +0 -30
  99. data/lib/ib/messages/incoming/historical_data_update.rb +0 -50
  100. data/lib/ib/messages/incoming/managed_accounts.rb +0 -21
  101. data/lib/ib/messages/incoming/market_depth_l2.rb +0 -15
  102. data/lib/ib/messages/incoming/position_data.rb +0 -21
  103. data/lib/ib/messages/incoming/positions_multi.rb +0 -15
  104. data/lib/ib/messages/incoming/receive_fa.rb +0 -30
  105. data/lib/ib/messages/incoming/tick_by_tick.rb +0 -77
  106. data/lib/ib/messages/incoming/tick_efp.rb +0 -18
  107. data/lib/ib/messages/incoming/tick_generic.rb +0 -12
  108. data/lib/ib/messages/incoming/tick_option.rb +0 -60
  109. data/lib/ib/messages/incoming/tick_price.rb +0 -60
  110. data/lib/ib/messages/incoming/tick_size.rb +0 -55
  111. data/lib/ib/messages/incoming/tick_string.rb +0 -13
  112. data/lib/ib/messages/outgoing/new-place-order.rb +0 -193
  113. data/lib/ib/messages/outgoing/old-place-order.rb +0 -147
  114. data/lib/ib/messages/outgoing/request_historical_data.rb +0 -182
  115. data/lib/ib/messages/outgoing/request_market_depth.rb +0 -57
  116. data/lib/ib/messages/outgoing/request_real_time_bars.rb +0 -48
  117. data/lib/ib/messages/outgoing/request_scanner_subscription.rb +0 -73
  118. data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +0 -21
  119. data/lib/ib/order_condition.rb +0 -26
  120. data/lib/ib/plugins.rb +0 -27
  121. data/lib/ib/prepare_data.rb +0 -61
  122. data/lib/ib/raw_message_parser.rb +0 -99
  123. data/lib/support/array_function.rb +0 -28
  124. data/lib/support/logging.rb +0 -45
  125. data/models/ib/account.rb +0 -72
  126. data/models/ib/future.rb +0 -64
  127. data/models/ib/option.rb +0 -149
  128. data/models/ib/option_detail.rb +0 -84
  129. data/models/ib/portfolio_value.rb +0 -86
  130. data/models/ib/spread.rb +0 -176
  131. data/models/ib/stock.rb +0 -25
  132. data/plugins/ib/advanced-account.rb +0 -442
  133. data/plugins/ib/alerts/base-alert.rb +0 -125
  134. data/plugins/ib/alerts/gateway-alerts.rb +0 -15
  135. data/plugins/ib/alerts/order-alerts.rb +0 -73
  136. data/plugins/ib/auto-adjust.rb +0 -0
  137. data/plugins/ib/connection-tools.rb +0 -122
  138. data/plugins/ib/eod.rb +0 -326
  139. data/plugins/ib/greeks.rb +0 -102
  140. data/plugins/ib/managed-accounts.rb +0 -274
  141. data/plugins/ib/market-price.rb +0 -150
  142. data/plugins/ib/option-chain.rb +0 -167
  143. data/plugins/ib/order-flow.rb +0 -157
  144. data/plugins/ib/order-prototypes/abstract.rb +0 -67
  145. data/plugins/ib/order-prototypes/adaptive.rb +0 -40
  146. data/plugins/ib/order-prototypes/all-in-one.rb +0 -46
  147. data/plugins/ib/order-prototypes/combo.rb +0 -46
  148. data/plugins/ib/order-prototypes/forex.rb +0 -40
  149. data/plugins/ib/order-prototypes/limit.rb +0 -193
  150. data/plugins/ib/order-prototypes/market.rb +0 -116
  151. data/plugins/ib/order-prototypes/pegged.rb +0 -169
  152. data/plugins/ib/order-prototypes/premarket.rb +0 -31
  153. data/plugins/ib/order-prototypes/stop.rb +0 -202
  154. data/plugins/ib/order-prototypes/volatility.rb +0 -39
  155. data/plugins/ib/order-prototypes.rb +0 -118
  156. data/plugins/ib/probability-of-expiring.rb +0 -109
  157. data/plugins/ib/process-orders.rb +0 -155
  158. data/plugins/ib/roll.rb +0 -86
  159. data/plugins/ib/spread-prototypes/butterfly.rb +0 -77
  160. data/plugins/ib/spread-prototypes/calendar.rb +0 -97
  161. data/plugins/ib/spread-prototypes/stock-spread.rb +0 -56
  162. data/plugins/ib/spread-prototypes/straddle.rb +0 -70
  163. data/plugins/ib/spread-prototypes/strangle.rb +0 -93
  164. data/plugins/ib/spread-prototypes/vertical.rb +0 -83
  165. data/plugins/ib/spread-prototypes.rb +0 -70
  166. data/plugins/ib/symbols/abstract.rb +0 -136
  167. data/plugins/ib/symbols/bonds.rb +0 -28
  168. data/plugins/ib/symbols/cfd.rb +0 -19
  169. data/plugins/ib/symbols/combo.rb +0 -46
  170. data/plugins/ib/symbols/commodity.rb +0 -17
  171. data/plugins/ib/symbols/forex.rb +0 -41
  172. data/plugins/ib/symbols/futures.rb +0 -127
  173. data/plugins/ib/symbols/index.rb +0 -43
  174. data/plugins/ib/symbols/options.rb +0 -99
  175. data/plugins/ib/symbols/stocks.rb +0 -44
  176. data/plugins/ib/symbols/version.rb +0 -5
  177. data/plugins/ib/symbols.rb +0 -118
  178. data/plugins/ib/verify.rb +0 -226
  179. data/symbols/w20.yml +0 -210
  180. data/t.txt +0 -20
  181. 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
- Connection.logger.debug to_s
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.reject{ |x| x == "do not include"}.map {|data| data == true ? 1 : data == false ? 0 : data }
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
- # If the version is zero, omit its apperance (for redesigned message-types as place-order, historical-data, etc)
50
+ #
51
+ # If the version is zero, omit its apperance (for historical data)
47
52
  def encode
48
- ## create a proper request_id and erase :id and :ticker_id if nessesary
49
- if self.class.properties?.include?(:request_id)
50
- @data[:request_id] = if @data[:request_id].blank? && @data[:ticker_id].blank? && @data[:id].blank?
51
- rand(9999)
52
- else
53
- @data[:id] || @data[:ticker_id] || @data[:request_id]
54
- end
55
- @data[:id] = @data[:ticker_id] = nil
56
- end
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
- self.class.version.zero? ? self.class.message_id : [ self.class.message_id, self.class.version ],
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] || [], # do not appear in data_map
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
- RequestAccountSummary = def_message( 62,
63
- :request_id, # autogenerated if not specified
64
- [:group, 'All'],
65
- :tags )
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
- end # module outgoing
70
- end # module messages
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
- unless data[:contract].is_a? IB::Contract
23
- error "contract must be a valid IB::Contract" , :args
24
- end
25
- [data_type, nil, data[:contract]]
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
- :request_id # autogenerated if not specified
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
- "" # not suported realtimebars option string
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
- :request_id # autogenerated if not specified
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
- @data[:keep_up_todate], # 0 / 1
190
- '' # chartOptions:TagValueList - For internal use only. Use default value XYZ.
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
- PlaceOrder = def_message [ 3,0 ]
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
- contract = order.contract unless contract.is_a? IB::Contract
13
-
14
- error 'contract has to be specified' unless contract.is_a? IB::Contract
15
-
16
- # send place order msg
17
- fields = [ super ,
18
- contract.serialize_short(:primary_exchange, :sec_id_type),
19
- order.serialize_main_order_fields,
20
- order.serialize_extended_order_fields,
21
- order.serialize_combo_legs(contract),
22
- order.serialize_auxilery_order_fields # including advisory order fields
23
- ]
24
-
25
- # if server_version >= KNOWN_SERVERS[:min_server_ver_models_support] # 103
26
- fields.push(order.model_code )
27
- # end
28
-
29
- fields += [
30
- order[:short_sale_slot] , # 0 only for retail, 1 or 2 for institution (Institutional)
31
- order.designated_location # only populate when short_sale_slot == 2 (Institutional)
32
- ]
33
-
34
- fields.push(order.exempt_code) #if server_version >= KNOWN_SERVERS[:min_server_ver_sshortx_old]
35
-
36
- fields.push(order[:oca_type])
37
- fields += [
38
- order[:rule_80a], # .to_sup[0..0],
39
- order.settling_firm,
40
- order.all_or_none,
41
- order.min_quantity,
42
- order.percent_offset,
43
- false, # etrade_only , desupported in TWS > 981
44
- false, # firm_quote_only , desupported in TWS > 981
45
- '', ## desupported in TWS > 981, too.
46
- order[:auction_strategy], # one of: AUCTION_MATCH, AUCTION_IMPROVEMENT, AUCTION_TRANSPARENT
47
- order.serialize_advanced_option_order_fields,
48
- order.override_percentage_constraints,
49
- order.serialize_volatility_order_fields,
50
- order.serialize_delta_neutral_order_fields
51
- ]
52
-
53
- fields += [
54
- order.continuous_update,
55
- order[:reference_price_type] ,
56
- order.trail_stop_price,
57
- order.trailing_percent
58
- ]
59
-
60
- fields << order.serialize_scale_order_fields
61
-
62
- fields.push order.hedge_type
63
- fields.push order.hedge_param # default is [] --> omitted if left default
64
- fields.push order.opt_out_smart_routing
65
-
66
- fields.push order.clearing_account
67
- fields.push order.clearing_intent
68
-
69
- fields.push(order.not_held)
70
-
71
- fields << contract.serialize_under_comp
72
- fields << order.serialize_algo
73
-
74
- fields.push(order.algo_id)
75
- fields.push(order.what_if)
76
- fields.push(order.serialize_misc_options)
77
- fields.push(order.solicided)
78
- fields << [ order.random_size, order.random_price ]
79
-
80
- fields << order.serialize_pegged_order_fields
81
- fields << order.serialize_conditions
82
- fields << [
83
- order.adjusted_order_type,
84
- order.trigger_price,
85
- order.limit_price_offset,
86
- order.adjusted_stop_price,
87
- order.adjusted_stop_limit_price,
88
- order.adjusted_trailing_amount,
89
- order.adjustable_trailing_unit
90
- ]
91
-
92
- fields.push(order.ext_operator) # if server_version >= KNOWN_SERVERS[:min_server_ver_ext_operator] # 105
93
-
94
- fields << order.serialize_soft_dollar_tier
95
-
96
- fields.push(order.cash_qty) # if server_version >= KNOWN_SERVERS[:min_server_ver_cash_qty] # 111
97
-
98
- fields << order.serialize_mifid_order_fields
99
-
100
- # if server_version >= KNOWN_SERVERS[:min_server_ver_auto_price_for_hedge] # 141
101
- fields.push(order.dont_use_auto_price_for_hedge)
102
- # end
103
-
104
- fields.push(order.is_O_ms_container) #if server_version >= KNOWN_SERVERS[:min_server_ver_order_container] # 145
105
-
106
- if server_version >= KNOWN_SERVERS[:min_server_ver_d_peg_orders] # 148
107
- fields.push(order.discretionary_up_to_limit_price)
108
- end
109
-
110
- if server_version >= KNOWN_SERVERS[:min_server_ver_price_mgmt_algo] # 151
111
- fields.push(order.use_price_management_algo)
112
- end
113
-
114
- if server_version >= KNOWN_SERVERS[:min_server_ver_duration] # 158
115
- fields.push(order.duration)
116
- end
117
-
118
- if server_version >= KNOWN_SERVERS[:min_server_ver_post_to_ats] # 160
119
- fields.push(order.post_to_ats)
120
- end
121
-
122
- if server_version >= KNOWN_SERVERS[:min_server_ver_auto_cancel_parent] # 162
123
- fields.push(order.auto_cancel_parent)
124
- end
125
-
126
- if server_version >= KNOWN_SERVERS[:min_server_ver_advanced_order_reject] # 166
127
- fields.push(order.advanced_order_reject)
128
- end
129
-
130
- if server_version >= KNOWN_SERVERS[:min_server_ver_manual_order_time] # 169
131
- fields.push(order.manual_order_time)
132
- end
133
-
134
- fields << order.serialize_peg_best_and_mid
135
-
136
- if server_version >= KNOWN_SERVERS[:min_server_ver_customer_account] # 183
137
- fields.push(order.customer_account)
138
- end
139
-
140
- if server_version >= KNOWN_SERVERS[:min_server_ver_professional_customer] # 184
141
- fields.push(order.professional_account)
142
- end
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
- end
148
- end
149
- end
204
+ end # PlaceOrder
205
+
206
+
207
+ end # module Outgoing
208
+ end # module Messages
209
+ end # module IB