ib-api 10.33.1

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 (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +52 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CLAUDE.md +131 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +17 -0
  8. data/Gemfile.lock +120 -0
  9. data/Guardfile +24 -0
  10. data/LICENSE +674 -0
  11. data/LLM_GUIDE.md +388 -0
  12. data/README.md +114 -0
  13. data/Rakefile +11 -0
  14. data/VERSION +1 -0
  15. data/api.gemspec +50 -0
  16. data/bin/console +96 -0
  17. data/bin/console.yml +3 -0
  18. data/bin/setup +8 -0
  19. data/bin/simple +91 -0
  20. data/changelog.md +32 -0
  21. data/conditions/ib/execution_condition.rb +31 -0
  22. data/conditions/ib/margin_condition.rb +28 -0
  23. data/conditions/ib/order_condition.rb +29 -0
  24. data/conditions/ib/percent_change_condition.rb +34 -0
  25. data/conditions/ib/price_condition.rb +44 -0
  26. data/conditions/ib/time_condition.rb +42 -0
  27. data/conditions/ib/volume_condition.rb +36 -0
  28. data/lib/class_extensions.rb +167 -0
  29. data/lib/ib/base.rb +109 -0
  30. data/lib/ib/base_properties.rb +178 -0
  31. data/lib/ib/connection.rb +573 -0
  32. data/lib/ib/constants.rb +402 -0
  33. data/lib/ib/contract.rb +30 -0
  34. data/lib/ib/errors.rb +52 -0
  35. data/lib/ib/messages/abstract_message.rb +68 -0
  36. data/lib/ib/messages/incoming/abstract_message.rb +116 -0
  37. data/lib/ib/messages/incoming/abstract_tick.rb +25 -0
  38. data/lib/ib/messages/incoming/account_message.rb +26 -0
  39. data/lib/ib/messages/incoming/alert.rb +34 -0
  40. data/lib/ib/messages/incoming/contract_data.rb +105 -0
  41. data/lib/ib/messages/incoming/contract_message.rb +13 -0
  42. data/lib/ib/messages/incoming/delta_neutral_validation.rb +23 -0
  43. data/lib/ib/messages/incoming/execution_data.rb +50 -0
  44. data/lib/ib/messages/incoming/histogram_data.rb +30 -0
  45. data/lib/ib/messages/incoming/historical_data.rb +65 -0
  46. data/lib/ib/messages/incoming/historical_data_update.rb +50 -0
  47. data/lib/ib/messages/incoming/managed_accounts.rb +21 -0
  48. data/lib/ib/messages/incoming/market_depth.rb +34 -0
  49. data/lib/ib/messages/incoming/market_depth_l2.rb +15 -0
  50. data/lib/ib/messages/incoming/next_valid_id.rb +19 -0
  51. data/lib/ib/messages/incoming/open_order.rb +290 -0
  52. data/lib/ib/messages/incoming/order_status.rb +85 -0
  53. data/lib/ib/messages/incoming/portfolio_value.rb +47 -0
  54. data/lib/ib/messages/incoming/position_data.rb +21 -0
  55. data/lib/ib/messages/incoming/positions_multi.rb +15 -0
  56. data/lib/ib/messages/incoming/real_time_bar.rb +32 -0
  57. data/lib/ib/messages/incoming/receive_fa.rb +30 -0
  58. data/lib/ib/messages/incoming/scanner_data.rb +54 -0
  59. data/lib/ib/messages/incoming/tick_by_tick.rb +77 -0
  60. data/lib/ib/messages/incoming/tick_efp.rb +18 -0
  61. data/lib/ib/messages/incoming/tick_generic.rb +12 -0
  62. data/lib/ib/messages/incoming/tick_option.rb +60 -0
  63. data/lib/ib/messages/incoming/tick_price.rb +60 -0
  64. data/lib/ib/messages/incoming/tick_size.rb +55 -0
  65. data/lib/ib/messages/incoming/tick_string.rb +13 -0
  66. data/lib/ib/messages/incoming.rb +292 -0
  67. data/lib/ib/messages/outgoing/abstract_message.rb +84 -0
  68. data/lib/ib/messages/outgoing/bar_request_message.rb +247 -0
  69. data/lib/ib/messages/outgoing/new-place-order.rb +193 -0
  70. data/lib/ib/messages/outgoing/old-place-order.rb +147 -0
  71. data/lib/ib/messages/outgoing/place_order.rb +149 -0
  72. data/lib/ib/messages/outgoing/request_account_summary.rb +79 -0
  73. data/lib/ib/messages/outgoing/request_historical_data.rb +182 -0
  74. data/lib/ib/messages/outgoing/request_market_data.rb +102 -0
  75. data/lib/ib/messages/outgoing/request_market_depth.rb +57 -0
  76. data/lib/ib/messages/outgoing/request_real_time_bars.rb +48 -0
  77. data/lib/ib/messages/outgoing/request_scanner_subscription.rb +73 -0
  78. data/lib/ib/messages/outgoing/request_tick_by_tick_data.rb +21 -0
  79. data/lib/ib/messages/outgoing.rb +410 -0
  80. data/lib/ib/messages.rb +139 -0
  81. data/lib/ib/order_condition.rb +26 -0
  82. data/lib/ib/plugins.rb +27 -0
  83. data/lib/ib/prepare_data.rb +61 -0
  84. data/lib/ib/raw_message_parser.rb +99 -0
  85. data/lib/ib/socket.rb +83 -0
  86. data/lib/ib/support.rb +236 -0
  87. data/lib/ib/version.rb +6 -0
  88. data/lib/ib-api.rb +44 -0
  89. data/lib/server_versions.rb +145 -0
  90. data/lib/support/array_function.rb +28 -0
  91. data/lib/support/logging.rb +45 -0
  92. data/models/ib/account.rb +72 -0
  93. data/models/ib/account_value.rb +33 -0
  94. data/models/ib/bag.rb +55 -0
  95. data/models/ib/bar.rb +31 -0
  96. data/models/ib/combo_leg.rb +127 -0
  97. data/models/ib/contract.rb +411 -0
  98. data/models/ib/contract_detail.rb +118 -0
  99. data/models/ib/execution.rb +67 -0
  100. data/models/ib/forex.rb +12 -0
  101. data/models/ib/future.rb +64 -0
  102. data/models/ib/index.rb +14 -0
  103. data/models/ib/option.rb +149 -0
  104. data/models/ib/option_detail.rb +84 -0
  105. data/models/ib/order.rb +720 -0
  106. data/models/ib/order_state.rb +155 -0
  107. data/models/ib/portfolio_value.rb +86 -0
  108. data/models/ib/spread.rb +176 -0
  109. data/models/ib/stock.rb +25 -0
  110. data/models/ib/underlying.rb +32 -0
  111. data/plugins/ib/advanced-account.rb +442 -0
  112. data/plugins/ib/alerts/base-alert.rb +125 -0
  113. data/plugins/ib/alerts/gateway-alerts.rb +15 -0
  114. data/plugins/ib/alerts/order-alerts.rb +73 -0
  115. data/plugins/ib/auto-adjust.rb +0 -0
  116. data/plugins/ib/connection-tools.rb +122 -0
  117. data/plugins/ib/eod.rb +326 -0
  118. data/plugins/ib/greeks.rb +102 -0
  119. data/plugins/ib/managed-accounts.rb +274 -0
  120. data/plugins/ib/market-price.rb +150 -0
  121. data/plugins/ib/option-chain.rb +167 -0
  122. data/plugins/ib/order-flow.rb +157 -0
  123. data/plugins/ib/order-prototypes/abstract.rb +67 -0
  124. data/plugins/ib/order-prototypes/adaptive.rb +40 -0
  125. data/plugins/ib/order-prototypes/all-in-one.rb +46 -0
  126. data/plugins/ib/order-prototypes/combo.rb +46 -0
  127. data/plugins/ib/order-prototypes/forex.rb +40 -0
  128. data/plugins/ib/order-prototypes/limit.rb +193 -0
  129. data/plugins/ib/order-prototypes/market.rb +116 -0
  130. data/plugins/ib/order-prototypes/pegged.rb +169 -0
  131. data/plugins/ib/order-prototypes/premarket.rb +31 -0
  132. data/plugins/ib/order-prototypes/stop.rb +202 -0
  133. data/plugins/ib/order-prototypes/volatility.rb +39 -0
  134. data/plugins/ib/order-prototypes.rb +118 -0
  135. data/plugins/ib/probability-of-expiring.rb +109 -0
  136. data/plugins/ib/process-orders.rb +155 -0
  137. data/plugins/ib/roll.rb +86 -0
  138. data/plugins/ib/spread-prototypes/butterfly.rb +77 -0
  139. data/plugins/ib/spread-prototypes/calendar.rb +97 -0
  140. data/plugins/ib/spread-prototypes/stock-spread.rb +56 -0
  141. data/plugins/ib/spread-prototypes/straddle.rb +70 -0
  142. data/plugins/ib/spread-prototypes/strangle.rb +93 -0
  143. data/plugins/ib/spread-prototypes/vertical.rb +83 -0
  144. data/plugins/ib/spread-prototypes.rb +70 -0
  145. data/plugins/ib/symbols/abstract.rb +136 -0
  146. data/plugins/ib/symbols/bonds.rb +28 -0
  147. data/plugins/ib/symbols/cfd.rb +19 -0
  148. data/plugins/ib/symbols/combo.rb +46 -0
  149. data/plugins/ib/symbols/commodity.rb +17 -0
  150. data/plugins/ib/symbols/forex.rb +41 -0
  151. data/plugins/ib/symbols/futures.rb +127 -0
  152. data/plugins/ib/symbols/index.rb +43 -0
  153. data/plugins/ib/symbols/options.rb +99 -0
  154. data/plugins/ib/symbols/stocks.rb +44 -0
  155. data/plugins/ib/symbols/version.rb +5 -0
  156. data/plugins/ib/symbols.rb +118 -0
  157. data/plugins/ib/verify.rb +226 -0
  158. data/symbols/w20.yml +210 -0
  159. data/t.txt +20 -0
  160. data/update.md +71 -0
  161. metadata +327 -0
@@ -0,0 +1,73 @@
1
+ module IB
2
+ module Messages
3
+ module Outgoing
4
+ extend Messages # def_message macros
5
+ # Start receiving market scanner results through the ScannerData messages.
6
+ # @data = { :id => ticker_id (int),
7
+ # :number_of_rows => int: number of rows of data to return for a query.
8
+ # :instrument => The instrument type for the scan. Values include
9
+ # 'STK', - US stocks
10
+ # 'STOCK.HK' - Asian stocks
11
+ # 'STOCK.EU' - European stocks
12
+ # :location_code => Legal Values include:
13
+ # - STK.US - US stocks
14
+ # - STK.US.MAJOR - US stocks (without pink sheet)
15
+ # - STK.US.MINOR - US stocks (only pink sheet)
16
+ # - STK.HK.SEHK - Hong Kong stocks
17
+ # - STK.HK.ASX - Australian Stocks
18
+ # - STK.EU - European stocks
19
+ # :scan_code => The type of the scan, such as HIGH_OPT_VOLUME_PUT_CALL_RATIO.
20
+ # :above_price => double: Only contracts with a price above this value.
21
+ # :below_price => double: Only contracts with a price below this value.
22
+ # :above_volume => int: Only contracts with a volume above this value.
23
+ # :market_cap_above => double: Only contracts with a market cap above this
24
+ # :market_cap_below => double: Only contracts with a market cap below this value.
25
+ # :moody_rating_above => Only contracts with a Moody rating above this value.
26
+ # :moody_rating_below => Only contracts with a Moody rating below this value.
27
+ # :sp_rating_above => Only contracts with an S&P rating above this value.
28
+ # :sp_rating_below => Only contracts with an S&P rating below this value.
29
+ # :maturity_date_above => Only contracts with a maturity date later than this
30
+ # :maturity_date_below => Only contracts with a maturity date earlier than this
31
+ # :coupon_rate_above => double: Only contracts with a coupon rate above this
32
+ # :coupon_rate_below => double: Only contracts with a coupon rate below this
33
+ # :exclude_convertible => Exclude convertible bonds.
34
+ # :scanner_setting_pairs => Used with the scan_code to help further narrow your query.
35
+ # Scanner Setting Pairs are delimited by slashes, making
36
+ # this parameter open ended. Example is "Annual,true" -
37
+ # when used with 'Top Option Implied Vol % Gainers' scan
38
+ # would return annualized volatilities.
39
+ # :average_option_volume_above => int: Only contracts with average volume above this
40
+ # :stock_type_filter => Valid values are:
41
+ # 'ALL' (excludes nothing)
42
+ # 'STOCK' (excludes ETFs)
43
+ # 'ETF' (includes ETFs) }
44
+ # ------------
45
+ # To learn all valid parameter values that a scanner subscription can have,
46
+ # first subscribe to ScannerParameters and send RequestScannerParameters message.
47
+ # Available scanner parameters values will be listed in received XML document.
48
+ RequestScannerSubscription =
49
+ def_message([22, 3], :request_id ,
50
+ [:number_of_rows, -1], # was: EOL,
51
+ :instrument,
52
+ :location_code,
53
+ :scan_code,
54
+ :above_price,
55
+ :below_price,
56
+ :above_volume,
57
+ :market_cap_above,
58
+ :market_cap_below,
59
+ :moody_rating_above,
60
+ :moody_rating_below,
61
+ :sp_rating_above,
62
+ :sp_rating_below,
63
+ :maturity_date_above,
64
+ :maturity_date_below,
65
+ :coupon_rate_above,
66
+ :coupon_rate_below,
67
+ :exclude_convertible,
68
+ :average_option_volume_above, # ?
69
+ :scanner_setting_pairs,
70
+ :stock_type_filter)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module IB
3
+ module Messages
4
+ module Outgoing
5
+ extend Messages # def_message macros
6
+
7
+
8
+
9
+ RequestTickByTickData =
10
+ def_message [0, 97], :request_id, # autogenerated if not specified
11
+ [:contract, :serialize_short, :primary_exchange], # include primary exchange in request
12
+ :tick_type, # a string supported: "Last", "AllLast", "BidAsk" or "MidPoint".
13
+ # Server_version >= 140
14
+ :number_of_ticks, # int
15
+ :ignore_size # bool
16
+
17
+ CancelTickByTickData =
18
+ def_message [0, 98], :request_id
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,410 @@
1
+ #require 'ib/messages/outgoing/abstract_message'
2
+
3
+ # TODO: Don't instantiate messages, use their classes as just namespace for .encode/decode
4
+
5
+ module IB
6
+ module Messages
7
+
8
+ # Outgoing IB messages (sent to TWS/Gateway)
9
+ module Outgoing
10
+ extend Messages # def_message macros
11
+
12
+ ### Defining (short) Outgoing Message classes for IB:
13
+
14
+ ## Empty messages (no data)
15
+
16
+ # Request the open orders that were placed from THIS client. Each open order
17
+ # will be fed back through the OpenOrder and OrderStatus messages ONCE.
18
+ # NB: Client with a client_id of 0 will also receive the TWS-owned open orders.
19
+ # These orders will be associated with the client and a new orderId will be
20
+ # generated. This association will persist over multiple API and TWS sessions.
21
+ RequestOpenOrders = def_message 5
22
+
23
+ # Request the open orders placed from all clients and also from TWS. Each open
24
+ # order will be fed back through the OpenOrder and OrderStatus messages ONCE.
25
+ # Note this does not re-bind those Orders to requesting Client!
26
+ # Use RequestAutoOpenOrders to request such re-binding.
27
+ RequestAllOpenOrders = def_message 16
28
+
29
+ # Request that newly created TWS orders be implicitly associated with this client.
30
+ # When a new TWS order is created, the order will be associated with this client
31
+ # and automatically fed back through the OpenOrder and OrderStatus messages.
32
+ # It is a 'continuous' request such that it gets turned 'on' when called with a
33
+ # TRUE auto_bind parameter. When it's called with FALSE auto_bind, new TWS orders
34
+ # will not bind to this client going forward. Note that TWS orders can only be
35
+ # bound to clients with a client_id of 0. TODO: how to properly test this?
36
+ # data = { :auto_bind => boolean }
37
+ RequestAutoOpenOrders = def_message 15, :auto_bind
38
+
39
+ # Requests an XML document that describes the valid parameters that a scanner
40
+ # subscription can have (for outgoing RequestScannerSubscription message).
41
+ RequestScannerParameters = def_message 24
42
+
43
+ RequestNewsArticle = def_message 84,
44
+ :request_id , # autogenerated
45
+ :provider_code,
46
+ :article_id,
47
+ :options # taglist
48
+
49
+
50
+ RequestNewsProviders = def_message 85 # no further parameters
51
+ RequestHistoricalNews = def_message 86,
52
+ :request_id , # autogenerated
53
+ :con_id,
54
+ :provider_code,
55
+ :start, # date
56
+ :total_results,
57
+ :options # taglist
58
+
59
+
60
+ CancelNewsBulletins = def_message 13
61
+ RequestCurrentTime = def_message 49
62
+ RequestGlobalCancel = def_message 58
63
+
64
+ ## Data format is: @data = { :id => ticker_id}
65
+ CancelMarketData = def_message [2, 2]
66
+ # CancelMarketDepth = def_message 11 ## moved to outgoing/request_market_depth.rb
67
+ CancelScannerSubscription = def_message 23
68
+ CancelHistoricalData = def_message 25
69
+ CancelRealTimeBars = def_message 51
70
+
71
+ ## Data format is: @data = { :id => request_id }
72
+ CancelFundamentalData = def_message 53
73
+ CancelCalculateImpliedVolatility = CancelImpliedVolatility = def_message 56
74
+ CancelCalculateOptionPrice = CancelOptionPrice = def_message 57
75
+
76
+ ## Data format is: @data ={ :id => local_id of order to cancel }
77
+ CancelOrder = def_message 4
78
+
79
+ # Request the next valid ID that can be used when placing an order. Responds with
80
+ # NextValidId message, and the id returned is that next valid Id for orders.
81
+ # That ID will reflect any autobinding that has occurred (which generates new
82
+ # IDs and increments the next valid ID therein).
83
+ # @data = { :number of ids requested => int } NB: :number option is ignored by TWS!
84
+ RequestIds = def_message 8, [:number, 1]
85
+ # data = { :all_messages => boolean }
86
+ RequestNewsBulletins = def_message 12, :all_messages
87
+ # data = { :log_level => int }
88
+ SetServerLoglevel = def_message 14, :log_level
89
+ # data = { :fa_data_type => int } 1 -> groups, 2 -> Profiles, 3 -> Account Aliases
90
+ RequestFA = def_message 18, :fa_data_type
91
+ # data = { :fa_data_type => int, :xml => String }
92
+ ReplaceFA = def_message 19, :fa_data_type, :xml
93
+
94
+
95
+ ## RequestContractDetails
96
+ # parameters :id => request_id(int), (autogenerated if absent)
97
+ # :contract => Contract }
98
+ #
99
+ # Special case for options: "wildcards" in the Contract fields retrieve Option chains
100
+ # strike = 0 means all strikes
101
+ # right = "" meanns both call and put
102
+ # expiry = "" means all expiries
103
+ # expiry = "2013" means all expiries in 2013
104
+ # expiry = "201311" means all expiries in Nov 2013
105
+ # You'll get several ContractData (10) messages back if there is more than one match.
106
+ # When all the matches are delivered you'll get ContractDataEnd (52) message.
107
+ RequestContractDetails = RequestContractData =
108
+ def_message([9, 8], :request_id , # autogenerated
109
+ [:contract, :serialize_long, [:sec_id_type]])
110
+
111
+ # Requests security definition option parameters for viewing a contract's option chain
112
+ # request_id: The ID chosen for the request
113
+ # underlyingSymbol
114
+ # futFopExchange: The exchange on which the returned options are trading.
115
+ # Can be set to the empty string "" for all exchanges.
116
+ # underlyingSecType: The type of the underlying security, i.e. STK
117
+ # underlyingConId: the contract ID of the underlying security.
118
+ # con_id:
119
+ # Responses via Messages::Incoming::SecurityDefinitionOptionParameter
120
+
121
+
122
+ RequestSecurityDefinitionOptionParameters = ReqSecDefOptParams = RequestOptionChainDefinition = def_message [78,0],
123
+ :request_id, # autogenerated if not specified
124
+ :symbol, # underlyingSymbol
125
+ [:exchange, ""], # futOptExchange
126
+ :sec_type, # underlyingSecType
127
+ :con_id # underlyingConId (required)
128
+ # data = { :id => ticker_id (int), :contract => Contract, :num_rows => int }
129
+
130
+
131
+ # Requests venues for which market data is returned to updateMktDepthL2
132
+ # returns MarketDepthExchanges-Message
133
+ #
134
+ RequestMarketDepthExchanges = # requires ServerVersion >= 112
135
+ def_message 82
136
+
137
+
138
+ ## actual Version supported is: 137
139
+ ## changes: MIN_SERVER_VER_SMART_DEPTH: 146 --> insert 'is_smarth_depth' after 'num_rows'
140
+ ## then: 'is_smart_depth' (bool) has to be specified in CancelMarketDepth, too
141
+ #
142
+ RequestMarketDepth = def_message([10, 5],
143
+ :request_id, # autogenerated if not specified
144
+ [:contract, :serialize_supershort ],
145
+ :num_rows,
146
+ "") # mktDataOptionsStr. ## not supported by api
147
+
148
+ # When this message is sent, TWS responds with ExecutionData messages, each
149
+ # containing the execution report that meets the specified criteria.
150
+ # @data={:id => int: :request_id,
151
+ # :client_id => int: Filter the results based on the clientId.
152
+ # :account => Filter the results based on based on account code.
153
+ # Note: this is only relevant for Financial Advisor accts.
154
+ # :sec_type => Filter the results based on the order security type.
155
+ # :time => Filter the results based on execution reports received
156
+ # after the specified time - format "yyyymmdd-hh:mm:ss"
157
+ # :symbol => Filter the results based on the order symbol.
158
+ # :exchange => Filter the results based on the order exchange
159
+ # :side => Filter the results based on the order action: BUY/SELL/SSHORT
160
+ RequestExecutions = def_message([7, 3],
161
+ :request_id, # autogenerated if not specified
162
+ :client_id,
163
+ :account,
164
+ :time, # Format "yyyymmdd-hh:mm:ss"
165
+ :symbol,
166
+ :sec_type,
167
+ :exchange,
168
+ :side)
169
+
170
+ # data = { :id => ticker_id (int),
171
+ # :contract => IB::Contract,
172
+ # :exercise_action => int, 1 = exercise, 2 = lapse
173
+ # :exercise_quantity => int, The number of contracts to be exercised
174
+ # :account => string,
175
+ # :override => int: Specifies whether your setting will override the
176
+ # system's natural action. For example, if your action
177
+ # is "exercise" and the option is not in-the-money, by
178
+ # natural action the option would not exercise. If you
179
+ # have override set to "yes" the natural action would be
180
+ # overridden and the out-of-the money option would be
181
+ # exercised. Values are:
182
+ # - 0 = do not override
183
+ # - 1 = override
184
+ ExerciseOptions = def_message([ 21, 2 ],
185
+ # :request_id, # id -> required # todo : TEST
186
+ [:contract, :serialize_short],
187
+ :exercise_action,
188
+ :exercise_quantity,
189
+ :account,
190
+ :override)
191
+
192
+
193
+ # The API can receive frozen market data from Trader Workstation. Frozen market
194
+ # data is the last data recorded in our system. During normal trading hours,
195
+ # the API receives real-time market data. If you use this function, you are
196
+ # telling TWS to automatically switch to frozen market data AFTER the close.
197
+ # Then, before the opening of the next trading day, market data will automatically
198
+ # switch back to real-time market data.
199
+ # :market_data_type = 1 (:real_time) for real-time streaming, 2 (:frozen) for frozen market data
200
+ # = 3 (:delayed) for delayed streaming , 4 (:frozen_delayed) for frozen delayed
201
+ RequestMarketDataType =
202
+ def_message 59, [:market_data_type,
203
+ lambda { |type| MARKET_DATA_TYPES.invert[type] || type }, []]
204
+
205
+ # Send this message to receive Reuters global fundamental data. There must be
206
+ # a subscription to Reuters Fundamental set up in Account Management before
207
+ # you can receive this data.
208
+ # data = { :id => int: :request_id,
209
+ # :contract => Contract,
210
+ # :report_type => String: one of the following:
211
+ # 'estimates' - Estimates
212
+ # 'finstat' - Financial statements
213
+ # 'snapshot' - Summary }a
214
+ # ReportsFinSummary Financial summary
215
+ #ReportsOwnership Company's ownership (Can be large in size)
216
+ #ReportSnapshot Company's financial overview
217
+ #ReportsFinStatements Financial Statements
218
+ #RESC Analyst Estimates
219
+ #CalendarReport Company's calendar
220
+ RequestFundamentalData =
221
+ def_message([52,2],
222
+ :request_id, # autogenerated if not specified
223
+ [:contract, :serialize, :primary_exchange],
224
+ :report_type,
225
+ "" )
226
+
227
+ # Returns the timestamp of earliest available historical data for a contract and data type.
228
+ # :what_to_show: type of data for head timestamp - "BID", "ASK", "TRADES", etc
229
+ # :use_rth : use regular trading hours only, 1 for yes or 0 for no
230
+ # format_data : set to 2 to obtain it like system time format in second ---> don't change
231
+ RequestHeadTimeStamp =
232
+ def_message( [87,0], :request_id, # autogenerated
233
+ [:contract, :serialize_short, [:primary_exchange,:include_expired] ],
234
+ [:use_rth, 1 ],
235
+ [:what_to_show, 'Trades' ],
236
+ [:format_date, 2 ] ) ## don't change!
237
+
238
+ CancelHeadTimeStamp =
239
+ def_message [90,0 ] # , :(request_)id #required
240
+
241
+
242
+
243
+ RequestHistogramData =
244
+ def_message( [88, 0], :request_id, # autogenerated
245
+ [:contract, :serialize_short, [:primary_exchange,:include_expired] ],
246
+ [:use_rth, 1 ],
247
+ [:time_period ] )
248
+
249
+ CancelHistogramData =
250
+ def_message [89,0 ] # , :(request_)id required
251
+
252
+ ## Attention: If not reasonable data are used, simply nothing is returned.
253
+ ## There is no error message either.
254
+ RequestCalculateImpliedVolatility = CalculateImpliedVolatility =
255
+ RequestImpliedVolatility =
256
+ def_message([ 54,3 ],:request_id, # autogenerated
257
+ [:contract, :serialize_short],
258
+ :option_price,
259
+ :under_price,
260
+ [:implied_volatility_options_count, 0],
261
+ [:implied_volatility_options_conditions, ''])
262
+
263
+ # data = { :request_id => int, :contract => Contract,
264
+ # :volatility => double, :under_price => double }
265
+ RequestCalculateOptionPrice = CalculateOptionPrice = RequestOptionPrice =
266
+ def_message([ 55, 3], :request_id, #autogenerated if not specified
267
+ [:contract, :serialize_short],
268
+ :volatility,
269
+ :under_price,
270
+ [:implied_volatility_options_count, 0],
271
+ [:implied_volatility_options_conditions, ''])
272
+
273
+
274
+
275
+ RequestAccountUpdates = RequestAccountData = def_message([6, 2],
276
+ [:subscribe, true],
277
+ :account_code)
278
+ CancelAccountSummary = def_message 63 # :request_id required
279
+ #
280
+ # Note: The reqPositions function is not available in Introducing
281
+ # Broker or Financial Advisor master accounts that have very large
282
+ # numbers of subaccounts (> 50) to optimize the performance of TWS/IB
283
+ # Gateway v973+. Instead the function reqPositionsMulti can be used
284
+ # to subscribe to updates from individual subaccounts. Also not
285
+ # available with IBroker accounts configured for on-demand account
286
+ # lookup.
287
+ RequestPositions = def_message 61
288
+ CancelPositions = def_message 64
289
+
290
+ # The function reqPositionsMulti can be used with any
291
+ # account structure to subscribe to positions updates for multiple
292
+ # accounts and/or models. The account and model parameters are
293
+ # optional if there are not multiple accounts or models available.
294
+ RequestPositionsMulti = def_message( 74, :request_id, # autogenerated
295
+ [ :account, 'ALL' ],
296
+ [:model_code, nil ] )
297
+
298
+ CancelPositionsMulti = def_message( 75, :request_id ) # required
299
+
300
+ RequestAccountUpdatesMulti = def_message( 76, :request_id, # autogenerated
301
+ [ :account, 'ALL'], # account or account-group
302
+ [:model_code, nil],
303
+ [:leger_and_nlv, nil ])
304
+ CancelAccountUpdatesMulti = def_message 77, :request_id # required
305
+ CancelMarketDepth = def_message([11, 1], :is_smart_depth)
306
+ # require 'ib/messages/outgoing/place_order'
307
+ # require 'ib/messages/outgoing/bar_requests'
308
+ # require 'ib/messages/outgoing/account_requests'
309
+ # require 'ib/messages/outgoing/request_marketdata'
310
+ # require 'ib/messages/outgoing/request_market_depth'
311
+ # require 'ib/messages/outgoing/request_tick_data'
312
+
313
+ end # module Outgoing
314
+ end # module Messages
315
+ end # module IB
316
+
317
+ __END__
318
+ ## python: message.py
319
+ REQ_MKT_DATA = 1
320
+ CANCEL_MKT_DATA = 2
321
+ PLACE_ORDER = 3
322
+ CANCEL_ORDER = 4
323
+ REQ_OPEN_ORDERS = 5
324
+ REQ_ACCT_DATA = 6
325
+ REQ_EXECUTIONS = 7
326
+ REQ_IDS = 8
327
+ REQ_CONTRACT_DATA = 9
328
+ REQ_MKT_DEPTH = 10
329
+ CANCEL_MKT_DEPTH = 11
330
+ REQ_NEWS_BULLETINS = 12
331
+ CANCEL_NEWS_BULLETINS = 13
332
+ SET_SERVER_LOGLEVEL = 14
333
+ REQ_AUTO_OPEN_ORDERS = 15
334
+ REQ_ALL_OPEN_ORDERS = 16
335
+ REQ_MANAGED_ACCTS = 17
336
+ REQ_FA = 18
337
+ REPLACE_FA = 19
338
+ REQ_HISTORICAL_DATA = 20
339
+ EXERCISE_OPTIONS = 21
340
+ REQ_SCANNER_SUBSCRIPTION = 22
341
+ CANCEL_SCANNER_SUBSCRIPTION = 23
342
+ REQ_SCANNER_PARAMETERS = 24
343
+ CANCEL_HISTORICAL_DATA = 25
344
+ REQ_CURRENT_TIME = 49
345
+ REQ_REAL_TIME_BARS = 50
346
+ CANCEL_REAL_TIME_BARS = 51
347
+ REQ_FUNDAMENTAL_DATA = 52
348
+ CANCEL_FUNDAMENTAL_DATA = 53
349
+ REQ_CALC_IMPLIED_VOLAT = 54
350
+ REQ_CALC_OPTION_PRICE = 55
351
+ CANCEL_CALC_IMPLIED_VOLAT = 56
352
+ CANCEL_CALC_OPTION_PRICE = 57
353
+ REQ_GLOBAL_CANCEL = 58
354
+ REQ_MARKET_DATA_TYPE = 59 --> supported by ib-ruby 0.94
355
+
356
+ REQ_POSITIONS = 61 supported now
357
+ REQ_ACCOUNT_SUMMARY = 62 supported now
358
+
359
+ CANCEL_ACCOUNT_SUMMARY = 63 supported now
360
+
361
+ CANCEL_POSITIONS = 64 supported now
362
+ VERIFY_REQUEST = 65
363
+ VERIFY_MESSAGE = 66
364
+ QUERY_DISPLAY_GROUPS = 67
365
+ SUBSCRIBE_TO_GROUP_EVENTS = 68
366
+ UPDATE_DISPLAY_GROUP = 69
367
+ UNSUBSCRIBE_FROM_GROUP_EVENTS = 70
368
+ START_API = 71
369
+ VERIFY_AND_AUTH_REQUEST = 72
370
+ VERIFY_AND_AUTH_MESSAGE = 73
371
+ REQ_POSITIONS_MULTI = 74 supported now
372
+ CANCEL_POSITIONS_MULTI = 75 supported now
373
+
374
+ REQ_ACCOUNT_UPDATES_MULTI = 76 supported now
375
+
376
+ CANCEL_ACCOUNT_UPDATES_MULTI = 77 supported now
377
+
378
+ REQ_SEC_DEF_OPT_PARAMS = 78 supported now
379
+ REQ_SOFT_DOLLAR_TIERS = 79
380
+ REQ_FAMILY_CODES = 80
381
+ REQ_MATCHING_SYMBOLS = 81
382
+ REQ_MKT_DEPTH_EXCHANGES = 82
383
+ REQ_SMART_COMPONENTS = 83
384
+ REQ_NEWS_ARTICLE = 84 in preparation
385
+ REQ_NEWS_PROVIDERS = 85 in preparatino
386
+ REQ_HISTORICAL_NEWS = 86 in preparation
387
+
388
+ REQ_HEAD_TIMESTAMP = 87 supported now
389
+
390
+ REQ_HISTOGRAM_DATA = 88 supported now
391
+
392
+ CANCEL_HISTOGRAM_DATA = 89 supported now
393
+
394
+ CANCEL_HEAD_TIMESTAMP = 90 supported now
395
+
396
+ REQ_MARKET_RULE = 91
397
+ REQ_PNL = 92
398
+ CANCEL_PNL = 93
399
+ REQ_PNL_SINGLE = 94
400
+ CANCEL_PNL_SINGLE = 95
401
+ REQ_HISTORICAL_TICKS = 96
402
+ REQ_TICK_BY_TICK_DATA = 97
403
+ CANCEL_TICK_BY_TICK_DATA = 98
404
+ # ver10
405
+ REQ_COMPLETED_ORDERS = 99
406
+ REQ_WSH_META_DATA = 100
407
+ CANCEL_WSH_META_DATA = 101
408
+ REQ_WSH_EVENT_DATA = 102
409
+ CANCEL_WSH_EVENT_DATA = 103
410
+
@@ -0,0 +1,139 @@
1
+ require 'server_versions'
2
+ module IB
3
+
4
+ module Messages
5
+ # This gem supports incoming/outgoing IB messages compatible with the following
6
+ # IB client/server versions:
7
+ CLIENT_VERSION = 66 # => API V 9.71
8
+ SERVER_VERSION = "v"+ MIN_CLIENT_VER.to_s + ".." + MAX_CLIENT_VER.to_s # extracted from the python-client
9
+
10
+
11
+
12
+ # Macro that defines short message classes using a one-liner.
13
+ # First arg is either a [message_id, version] pair or just message_id (version 1)
14
+ # data_map contains instructions for processing @data Hash. Format:
15
+ # Incoming messages: [field, type] or [group, field, type]
16
+ # Outgoing messages: field, [field, default] or [field, method, [args]]
17
+ def def_message message_id_version, *data_map, &to_human
18
+ base = data_map.first.is_a?(Class) ? data_map.shift : self::AbstractMessage
19
+ message_id, version = message_id_version
20
+
21
+ # Define new message class
22
+ message_class = Class.new(base) do
23
+ @message_id, @version = message_id, version || 1
24
+ @data_map = data_map
25
+ @given_arguments =[]
26
+
27
+ @data_map.each do |(name, _, type_args)|
28
+ dont_process = name == :request_id # [ :request_id, :local_id, :id ].include? name.to_sym
29
+ @given_arguments << name.to_sym
30
+ # Avoid redefining existing accessor methods
31
+ unless instance_methods.include?(name.to_s) || instance_methods.include?(name.to_sym) || dont_process
32
+ if type_args.is_a?(Symbol) # This is Incoming with [group, field, type]
33
+ attr_reader name
34
+ else
35
+ define_method(name) { @data[name] }
36
+ end
37
+ end
38
+ end
39
+
40
+ define_method(:to_human, &to_human) if to_human
41
+ end
42
+
43
+ # Add defined message class to Classes Hash keyed by its message_id
44
+ self::Classes[message_id] = message_class
45
+
46
+ message_class
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ #require 'ib/messages/outgoing'
53
+ #require 'ib/messages/incoming'
54
+
55
+ __END__
56
+ // Client version history
57
+ //
58
+ // 6 = Added parentId to orderStatus
59
+ // 7 = The new execDetails event returned for an order filled status and reqExecDetails
60
+ // Also market depth is available.
61
+ // 8 = Added lastFillPrice to orderStatus() event and permId to execution details
62
+ // 9 = Added 'averageCost', 'unrealizedPNL', and 'unrealizedPNL' to updatePortfolio event
63
+ // 10 = Added 'serverId' to the 'open order' & 'order status' events.
64
+ // We send back all the API open orders upon connection.
65
+ // Added new methods reqAllOpenOrders, reqAutoOpenOrders()
66
+ // Added FA support - reqExecution has filter.
67
+ // - reqAccountUpdates takes acct code.
68
+ // 11 = Added permId to openOrder event.
69
+ // 12 = requsting open order attributes ignoreRth, hidden, and discretionary
70
+ // 13 = added goodAfterTime
71
+ // 14 = always send size on bid/ask/last tick
72
+ // 15 = send allocation description string on openOrder
73
+ // 16 = can receive account name in account and portfolio updates, and fa params in openOrder
74
+ // 17 = can receive liquidation field in exec reports, and notAutoAvailable field in mkt data
75
+ // 18 = can receive good till date field in open order messages, and request intraday backfill
76
+ // 19 = can receive rthOnly flag in ORDER_STATUS
77
+ // 20 = expects TWS time string on connection after server version >= 20.
78
+ // 21 = can receive bond contract details.
79
+ // 22 = can receive price magnifier in version 2 contract details message
80
+ // 23 = support for scanner
81
+ // 24 = can receive volatility order parameters in open order messages
82
+ // 25 = can receive HMDS query start and end times
83
+ // 26 = can receive option vols in option market data messages
84
+ // 27 = can receive delta neutral order type and delta neutral aux price in place order version 20: API 8.85
85
+ // 28 = can receive option model computation ticks: API 8.9
86
+ // 29 = can receive trail stop limit price in open order and can place them: API 8.91
87
+ // 30 = can receive extended bond contract def, new ticks, and trade count in bars
88
+ // 31 = can receive EFP extensions to scanner and market data, and combo legs on open orders
89
+ // ; can receive RT bars
90
+ // 32 = can receive TickType.LAST_TIMESTAMP
91
+ // ; can receive "whyHeld" in order status messages
92
+ // 33 = can receive ScaleNumComponents and ScaleComponentSize is open order messages
93
+ // 34 = can receive whatIf orders / order state
94
+ // 35 = can receive contId field for Contract objects
95
+ // 36 = can receive outsideRth field for Order objects
96
+ // 37 = can receive clearingAccount and clearingIntent for Order objects
97
+ // 38 = can receive multiplier and primaryExchange in portfolio updates
98
+ // ; can receive cumQty and avgPrice in execution
99
+ // ; can receive fundamental data
100
+ // ; can receive underComp for Contract objects
101
+ // ; can receive reqId and end marker in contractDetails/bondContractDetails
102
+ // ; can receive ScaleInitComponentSize and ScaleSubsComponentSize for Order objects
103
+ // 39 = can receive underConId in contractDetails
104
+ // 40 = can receive algoStrategy/algoParams in openOrder
105
+ // 41 = can receive end marker for openOrder
106
+ // ; can receive end marker for account download
107
+ // ; can receive end marker for executions download
108
+ // 42 = can receive deltaNeutralValidation
109
+ // 43 = can receive longName(companyName)
110
+ // ; can receive listingExchange
111
+ // ; can receive RTVolume tick
112
+ // 44 = can receive end market for ticker snapshot
113
+ // 45 = can receive notHeld field in openOrder
114
+ // 46 = can receive contractMonth, industry, category, subcategory fields in contractDetails
115
+ // ; can receive timeZoneId, tradingHours, liquidHours fields in contractDetails
116
+ // 47 = can receive gamma, vega, theta, undPrice fields in TICK_OPTION_COMPUTATION
117
+ // 48 = can receive exemptCode in openOrder
118
+ // 49 = can receive hedgeType and hedgeParam in openOrder
119
+ // 50 = can receive optOutSmartRouting field in openOrder
120
+ // 51 = can receive smartComboRoutingParams in openOrder
121
+ // 52 = can receive deltaNeutralConId, deltaNeutralSettlingFirm, deltaNeutralClearingAccount and deltaNeutralClearingIntent in openOrder
122
+ // 53 = can receive orderRef in execution
123
+ // 54 = can receive scale order fields (PriceAdjustValue, PriceAdjustInterval, ProfitOffset, AutoReset,
124
+ // InitPosition, InitFillQty and RandomPercent) in openOrder
125
+ // 55 = can receive orderComboLegs (price) in openOrder
126
+ // 56 = can receive trailingPercent in openOrder
127
+ // 57 = can receive commissionReport message
128
+ // 58 = can receive CUSIP/ISIN/etc. in contractDescription/bondContractDescription
129
+ // 59 = can receive evRule, evMultiplier in contractDescription/bondContractDescription/executionDetails
130
+ // can receive multiplier in executionDetails
131
+ // 60 = can receive deltaNeutralOpenClose, deltaNeutralShortSale, deltaNeutralShortSaleSlot and …deltaNeutralDesignatedLocation in openOrder
132
+ // 61 = can receive multiplier in openOrder
133
+ // can receive tradingClass in openOrder, updatePortfolio, execDetails and position
134
+ // 62 = can receive avgCost in position message
135
+ // 63 = can receive verifyMessageAPI, verifyCompleted, displayGroupList and displayGroupUpdated messages
136
+ // 64 = can receive solicited attrib in openOrder message
137
+ // 65 = can receive verifyAndAuthMessageAPI and verifyAndAuthCompleted messages
138
+ // 66 = can receive randomize size and randomize price order fields
139
+ // not updated since Vers. 9.71
@@ -0,0 +1,26 @@
1
+ module IB
2
+
3
+
4
+
5
+
6
+ class OrderCondition
7
+ using IB::Support # refine Array-method for decoding of IB-Messages
8
+ # subclasses representing specialized condition types.
9
+
10
+ Subclasses = Hash.new(OrderCondition)
11
+ Subclasses[1] = IB::PriceCondition
12
+ Subclasses[3] = IB::TimeCondition
13
+ Subclasses[5] = IB::ExecutionCondition
14
+ Subclasses[4] = IB::MarginCondition
15
+ Subclasses[6] = IB::VolumeCondition
16
+ Subclasses[7] = IB::PercentChangeCondition
17
+
18
+
19
+ # This builds an appropriate subclass based on its type
20
+ #
21
+ def self.make_from buffer
22
+ condition_type = buffer.read_int
23
+ OrderCondition::Subclasses[condition_type].make( buffer )
24
+ end
25
+ end # class
26
+ end # module