ib-ruby 0.5.21 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/HISTORY +8 -0
  2. data/README.md +46 -27
  3. data/TODO +13 -2
  4. data/VERSION +1 -1
  5. data/bin/generic_data.rb +26 -0
  6. data/bin/place_order +1 -1
  7. data/lib/ib-ruby/connection.rb +126 -65
  8. data/lib/ib-ruby/messages/incoming.rb +3 -3
  9. data/lib/ib-ruby/models/bar.rb +11 -11
  10. data/lib/ib-ruby/models/combo_leg.rb +23 -29
  11. data/lib/ib-ruby/models/contract/bag.rb +34 -2
  12. data/lib/ib-ruby/models/contract/option.rb +2 -2
  13. data/lib/ib-ruby/models/contract.rb +151 -197
  14. data/lib/ib-ruby/models/execution.rb +27 -45
  15. data/lib/ib-ruby/models/model.rb +10 -4
  16. data/lib/ib-ruby/models/model_properties.rb +63 -0
  17. data/lib/ib-ruby/models/order.rb +274 -320
  18. data/lib/ib-ruby/symbols/stocks.rb +11 -5
  19. data/spec/account_helper.rb +80 -0
  20. data/spec/ib-ruby/connection_spec.rb +195 -52
  21. data/spec/ib-ruby/messages/incoming_spec.rb +4 -4
  22. data/spec/ib-ruby/models/combo_leg_spec.rb +1 -0
  23. data/spec/ib-ruby/models/contract_spec.rb +1 -1
  24. data/spec/ib-ruby/models/execution_spec.rb +73 -0
  25. data/spec/integration/account_info_spec.rb +12 -59
  26. data/spec/integration/contract_info_spec.rb +23 -37
  27. data/spec/integration/depth_data_spec.rb +4 -4
  28. data/spec/integration/historic_data_spec.rb +15 -27
  29. data/spec/integration/market_data_spec.rb +74 -61
  30. data/spec/integration/option_data_spec.rb +5 -48
  31. data/spec/integration/orders/execution_spec.rb +26 -31
  32. data/spec/integration/orders/open_order +2 -0
  33. data/spec/integration/orders/placement_spec.rb +28 -28
  34. data/spec/integration/orders/valid_ids_spec.rb +11 -11
  35. data/spec/integration_helper.rb +46 -32
  36. data/spec/message_helper.rb +4 -38
  37. data/spec/spec_helper.rb +2 -3
  38. metadata +9 -2
@@ -46,326 +46,280 @@ module IB
46
46
  Max_Value = 99999999
47
47
 
48
48
  # Main order fields
49
- attr_accessor :order_id, # int: m_orderId? Order id associated with client (volatile).
50
- :client_id, # int: The id of the client that placed this order.
51
- :perm_id, # int: TWS id used to identify orders, remains
52
- # the same over TWS sessions.
53
- :action, # String: Identifies the side: BUY/SELL/SSHORT
54
- :total_quantity, # int: The order quantity.
55
-
56
- :order_type, # String: Identifies the order type. Valid values are:
57
- # Limit Risk:
58
- # MTL Market-to-Limit
59
- # MKT PRT Market with Protection
60
- # QUOTE Request for Quote
61
- # STP Stop
62
- # STP LMT Stop Limit
63
- # TRAIL Trailing Stop
64
- # TRAIL LIMIT Trailing Stop Limit
65
- # TRAIL LIT Trailing Limit if Touched
66
- # TRAIL MIT Trailing Market If Touched
67
- # Speed of Execution:
68
- # MKT Market
69
- # MIT Market-if-Touched
70
- # MOC Market-on-Close MKTCLSL ?
71
- # MOO Market-on-Open
72
- # PEG MKT Pegged-to-Market
73
- # REL Relative
74
- # Price Improvement:
75
- # BOX TOP Box Top
76
- # LOC Limit-on-Close LMTCLS ?
77
- # LOO Limit-on-Open
78
- # LIT Limit if Touched
79
- # PEG MID Pegged-to-Midpoint
80
- # VWAP VWAP-Guaranteed
81
- # Advanced Trading:
82
- # OCA One-Cancels-All
83
- # VOL Volatility
84
- # SCALE Scale
85
- # Other (no abbreviation):
86
- # Bracket
87
- # At Auction
88
- # Discretionary
89
- # Sweep-to-Fill
90
- # Price Improvement Auction
91
- # Block
92
- # Hidden
93
- # Iceberg/Reserve
94
- # All-or-None
95
- # Fill-or-Kill
96
-
97
- :limit_price, # double: This is the LIMIT price, used for limit,
98
- # stop-limit and relative orders. In all other cases
99
- # specify zero. For relative orders with no limit price,
100
- # also specify zero.
101
-
102
- :aux_price, # double: This is the STOP price for stop-limit orders,
103
- # and the offset amount for relative orders. In all other
104
- # cases, specify zero.
105
- #:shares_allocation, # deprecated sharesAllocation field
106
-
107
- # Extended order fields
108
- :tif, # String: Time to Market:
109
- # DAY
110
- # GAT Good-after-Time/Date
111
- # GTD Good-till-Date/Time
112
- # GTC Good-till-Canceled
113
- # IOC Immediate-or-Cancel
114
- :oca_group, # String: one cancels all group name
115
- :oca_type, # int: Tells how to handle remaining orders in an OCA group
116
- # when one order or part of an order executes. Valid values:
117
- # - 1 = Cancel all remaining orders with block
118
- # - 2 = Remaining orders are reduced in size with block
119
- # - 3 = Remaining orders are reduced in size with no block
120
- # If you use a value "with block" your order has
121
- # overfill protection. This means that only one order in
122
- # the group will be routed at a time to remove the
123
- # possibility of an overfill.
124
- :transmit, # bool:if false, order will be created but not transmitted.
125
- :parent_id, # int: The order ID of the parent (original) order, used
126
- # for bracket (STP) and auto trailing stop (TRAIL) orders.
127
- :block_order, # bool: the order is an ISE Block order.
128
- :sweep_to_fill, # bool: the order is a Sweep-to-Fill order.
129
- :display_size, # int: publicly disclosed order size for Iceberg orders.
130
-
131
- :trigger_method, # Specifies how Simulated Stop, Stop-Limit and Trailing
132
- # Stop orders are triggered. Valid values are:
133
- # 0 - Default, "double bid/ask" method will be used for OTC stocks
134
- # and US options orders, "last" method will be used all others.
135
- # 1 - "double bid/ask" method, stop orders are triggered based on
136
- # two consecutive bid or ask prices.
137
- # 2 - "last" method, stops are triggered based on the last price.
138
- # 3 - double last method.
139
- # 4 - bid/ask method. For a buy order, a single occurrence of the
140
- # bid price must be at or above the trigger price. For a sell
141
- # order, a single occurrence of the ask price must be at or
142
- # below the trigger price.
143
- # 7 - last or bid/ask method. For a buy order, a single bid price
144
- # or the last price must be at or above the trigger price.
145
- # For a sell order, a single ask price or the last price
146
- # must be at or below the trigger price.
147
- # 8 - mid-point method, where the midpoint must be at or above
148
- # (for a buy) or at or below (for a sell) the trigger price,
149
- # and the spread between the bid and ask must be less than
150
- # 0.1% of the midpoint
151
-
152
- :outside_rth, # bool: allows orders to also trigger or fill outside
153
- # of regular trading hours. (WAS: ignore_rth)
154
- :hidden, # bool: the order will not be visible when viewing
155
- # the market depth. Only for ISLAND exchange.
156
- :good_after_time, # FORMAT: 20060505 08:00:00 {time zone}
157
- # Use an empty String if not applicable.
158
- :good_till_date, # FORMAT: 20060505 08:00:00 {time zone}
159
- # Use an empty String if not applicable.
160
- :override_percentage_constraints, # bool: Precautionary constraints
161
- # are defined on the TWS Presets page, and help ensure that your
162
- # price and size order values are reasonable. Orders sent from the API
163
- # are also validated against these safety constraints, and may be
164
- # rejected if any constraint is violated. To override validation,
165
- # set this parameter�s value to True.
166
-
167
- :rule_80a, # Individual = 'I', Agency = 'A', AgentOtherMember = 'W',
168
- # IndividualPTIA = 'J', AgencyPTIA = 'U', AgentOtherMemberPTIA = 'M',
169
- # IndividualPT = 'K', AgencyPT = 'Y', AgentOtherMemberPT = 'N'
170
- :all_or_none, # bool: yes=1, no=0
171
- :min_quantity, # int: Identifies a minimum quantity order type.
172
- :percent_offset, # double: percent offset amount for relative (REL)orders only
173
- :trail_stop_price, # double: for TRAILLIMIT orders only
174
-
175
- # Financial advisors only - use an empty String if not applicable.
176
- :fa_group, :fa_profile, :fa_method, :fa_percentage,
177
-
178
- # Institutional orders only!
179
- :open_close, # String: O=Open, C=Close
180
- :origin, # 0=Customer, 1=Firm
181
- :order_ref, # String: The order reference. For institutional customers only.
182
- :short_sale_slot, # 1 - you hold the shares,
183
- # 2 - they will be delivered from elsewhere.
184
- # Only for Action="SSHORT
185
- :designated_location, # String: set when slot==2 only
186
- :exempt_code, # int
187
-
188
- # Clearing info
189
- :account, # String: The account. For institutional customers only.
190
- :settling_firm, # String: Institutional only
191
- :clearing_account, # String: For IBExecution customers: Specifies the
192
- # true beneficiary of the order. This value is required
193
- # for FUT/FOP orders for reporting to the exchange.
194
- :clearing_intent, # For IBExecution customers: "", IB, Away,
195
- # and PTA (post trade allocation).
196
-
197
- # SMART routing only
198
- :discretionary_amount, # double: The amount off the limit price
199
- # allowed for discretionary orders.
200
- :etrade_only, # bool: Trade with electronic quotes.
201
- :firm_quote_only, # bool: Trade with firm quotes.
202
- :nbbo_price_cap, # double: Maximum Smart order distance from the NBBO.
203
-
204
- # BOX or VOL ORDERS ONLY
205
- :auction_strategy, # For BOX exchange only. Valid values:
206
- # 1=AUCTION_MATCH, 2=AUCTION_IMPROVEMENT, 3=AUCTION_TRANSPARENT
207
- :starting_price, # double: Starting price. Valid on BOX orders only.
208
- :stock_ref_price, # double: The stock reference price, used for VOL
209
- # orders to compute the limit price sent to an exchange (whether or not
210
- # Continuous Update is selected), and for price range monitoring.
211
- :delta, # double: Stock delta. Valid on BOX orders only.
212
-
213
- # Pegged to stock or VOL orders. For price improvement option orders
214
- # on BOX and VOL orders with dynamic management:
215
- :stock_range_lower, # double: The lower value for the acceptable
216
- # underlying stock price range.
217
- :stock_range_upper, # double The upper value for the acceptable
218
- # underlying stock price range.
219
-
220
- # VOLATILITY ORDERS ONLY:
221
- :volatility, # double: What the price is, computed via TWSs Options
222
- # Analytics. For VOL orders, the limit price sent to an
223
- # exchange is not editable, as it is the output of a
224
- # function. Volatility is expressed as a percentage.
225
- :volatility_type, # int: How the volatility is calculated: 1=daily, 2=annual
226
- :reference_price_type, # int: For dynamic management of volatility orders:
227
- # - 1 = Average of National Best Bid or Ask,
228
- # - 2 = National Best Bid when buying a call or selling a put;
229
- # and National Best Ask when selling a call or buying a put.
230
- :delta_neutral_order_type, # String: Enter an order type to instruct TWS
231
- # to submit a delta neutral trade on full or partial execution of the
232
- # VOL order. For no hedge delta order to be sent, specify NONE.
233
- :delta_neutral_aux_price, # double: Use this field to enter a value if
234
- # the value in the deltaNeutralOrderType field is an order
235
- # type that requires an Aux price, such as a REL order.
236
- :continuous_update, # int: Used for dynamic management of volatility
237
- # orders. Determines whether TWS is supposed to update the order price
238
- # as the underlying moves. If selected, the limit price sent to an
239
- # exchange is modified by TWS if the computed price of the option
240
- # changes enough to warrant doing so. This is very helpful in keeping
241
- # the limit price sent to the exchange up to date as the underlying price changes.
242
-
243
- # COMBO ORDERS ONLY:
244
- :basis_points, # double: EFP orders only
245
- :basis_points_type, # double: EFP orders only
246
-
247
- # SCALE ORDERS ONLY
248
- :scale_init_level_size, # int: Size of the first (initial) order component.
249
- :scale_subs_level_size, # int: Order size of the subsequent scale order
250
- # components. Used in conjunction with scaleInitLevelSize().
251
- :scale_price_increment, # double: Defines the price increment between
252
- # scale components. This field is required for Scale orders.
253
-
254
- # ALGO ORDERS ONLY
255
- :algo_strategy, # String
256
- :algo_params, # public Vector<TagValue> m_algoParams; ?!
257
-
258
- # WTF?!
259
- :what_if, # bool: Use to request pre-trade commissions and margin
260
- # information. If set to true, margin and commissions data is received
261
- # back via the OrderState() object for the openOrder() callback.
262
- :not_held # public boolean m_notHeld; // Not Held
49
+ prop :order_id, # int: Order id associated with client (volatile).
50
+ :client_id, # int: The id of the client that placed this order.
51
+ :perm_id, # int: TWS permanent id, remains the same over TWS sessions.
52
+ :action, # String: Identifies the side: BUY/SELL/SSHORT
53
+ :total_quantity, # int: The order quantity.
54
+
55
+ :order_type, # String: Identifies the order type. Valid values are:
56
+ # Limit Risk:
57
+ # MTL Market-to-Limit
58
+ # MKT PRT Market with Protection
59
+ # QUOTE Request for Quote
60
+ # STP Stop
61
+ # STP LMT Stop Limit
62
+ # TRAIL Trailing Stop
63
+ # TRAIL LIMIT Trailing Stop Limit
64
+ # TRAIL LIT Trailing Limit if Touched
65
+ # TRAIL MIT Trailing Market If Touched
66
+ # Speed of Execution:
67
+ # MKT Market
68
+ # MIT Market-if-Touched
69
+ # MOC Market-on-Close MKTCLSL ?
70
+ # MOO Market-on-Open
71
+ # PEG MKT Pegged-to-Market
72
+ # REL Relative
73
+ # Price Improvement:
74
+ # BOX TOP Box Top
75
+ # LOC Limit-on-Close LMTCLS ?
76
+ # LOO Limit-on-Open
77
+ # LIT Limit if Touched
78
+ # PEG MID Pegged-to-Midpoint
79
+ # VWAP VWAP-Guaranteed
80
+ # Advanced Trading:
81
+ # OCA One-Cancels-All
82
+ # VOL Volatility
83
+ # SCALE Scale
84
+ # Other (no abbreviation):
85
+ # Bracket
86
+ # At Auction
87
+ # Discretionary
88
+ # Sweep-to-Fill
89
+ # Price Improvement Auction
90
+ # Block
91
+ # Hidden
92
+ # Iceberg/Reserve
93
+ # All-or-None
94
+ # Fill-or-Kill
95
+
96
+ :limit_price, # double: LIMIT price, used for limit, stop-limit and relative
97
+ # orders. In all other cases specify zero. For relative
98
+ # orders with no limit price, also specify zero.
99
+
100
+ :aux_price, # double: STOP price for stop-limit orders, and the OFFSET amount
101
+ # for relative orders. In all other cases, specify zero.
102
+
103
+ :tif, # String: Time to Market:
104
+ # DAY
105
+ # GAT Good-after-Time/Date
106
+ # GTD Good-till-Date/Time
107
+ # GTC Good-till-Canceled
108
+ # IOC Immediate-or-Cancel
109
+ :oca_group, # String: one cancels all group name
110
+ :oca_type, # int: Tells how to handle remaining orders in an OCA group
111
+ # when one order or part of an order executes. Valid values:
112
+ # - 1 = Cancel all remaining orders with block
113
+ # - 2 = Remaining orders are reduced in size with block
114
+ # - 3 = Remaining orders are reduced in size with no block
115
+ # If you use a value "with block" your order has
116
+ # overfill protection. This means that only one order in
117
+ # the group will be routed at a time to remove the
118
+ # possibility of an overfill.
119
+ :transmit, # bool:if false, order will be created but not transmitted.
120
+ :parent_id, # int: The order ID of the parent (original) order, used
121
+ # for bracket (STP) and auto trailing stop (TRAIL) orders.
122
+ :block_order, # bool: the order is an ISE Block order.
123
+ :sweep_to_fill, # bool: the order is a Sweep-to-Fill order.
124
+ :display_size, # int: publicly disclosed order size for Iceberg orders.
125
+
126
+ :trigger_method, # Specifies how Simulated Stop, Stop-Limit and Trailing
127
+ # Stop orders are triggered. Valid values are:
128
+ # 0 - Default, "double bid/ask" method will be used for OTC stocks
129
+ # and US options orders, "last" method will be used all others.
130
+ # 1 - "double bid/ask" method, stop orders are triggered based on
131
+ # two consecutive bid or ask prices.
132
+ # 2 - "last" method, stops are triggered based on the last price.
133
+ # 3 - double last method.
134
+ # 4 - bid/ask method. For a buy order, a single occurrence of the
135
+ # bid price must be at or above the trigger price. For a sell
136
+ # order, a single occurrence of the ask price must be at or
137
+ # below the trigger price.
138
+ # 7 - last or bid/ask method. For a buy order, a single bid price
139
+ # or the last price must be at or above the trigger price.
140
+ # For a sell order, a single ask price or the last price
141
+ # must be at or below the trigger price.
142
+ # 8 - mid-point method, where the midpoint must be at or above
143
+ # (for a buy) or at or below (for a sell) the trigger price,
144
+ # and the spread between the bid and ask must be less than
145
+ # 0.1% of the midpoint
146
+
147
+ :outside_rth, # bool: allows orders to also trigger or fill outside
148
+ # of regular trading hours. (WAS: ignore_rth)
149
+ :hidden, # bool: the order will not be visible when viewing
150
+ # the market depth. Only for ISLAND exchange.
151
+ :good_after_time, # FORMAT: 20060505 08:00:00 {time zone}
152
+ # Use an empty String if not applicable.
153
+ :good_till_date, # FORMAT: 20060505 08:00:00 {time zone}
154
+ # Use an empty String if not applicable.
155
+ :override_percentage_constraints, # bool: Precautionary constraints defined on
156
+ # the TWS Presets page ensure that your price and size order values are reasonable.
157
+ # Orders sent from the API are also validated against these safety constraints,
158
+ # unless this parameter is set to True.
159
+
160
+ :rule_80a, # Individual = 'I', Agency = 'A', AgentOtherMember = 'W',
161
+ # IndividualPTIA = 'J', AgencyPTIA = 'U', AgentOtherMemberPTIA = 'M',
162
+ # IndividualPT = 'K', AgencyPT = 'Y', AgentOtherMemberPT = 'N'
163
+ :all_or_none, # bool: yes=1, no=0
164
+ :min_quantity, # int: Identifies a minimum quantity order type.
165
+ :percent_offset, # double: percent offset amount for relative (REL)orders only
166
+ :trail_stop_price, # double: for TRAILLIMIT orders only
167
+
168
+ # Financial advisors only - use an empty String if not applicable.
169
+ :fa_group, :fa_profile, :fa_method, :fa_percentage,
170
+
171
+ # Institutional orders only!
172
+ :open_close, # String: O=Open, C=Close
173
+ :origin, # 0=Customer, 1=Firm
174
+ :order_ref, # String: The order reference. For institutional customers only.
175
+ :short_sale_slot, # 1 - you hold the shares,
176
+ # 2 - they will be delivered from elsewhere.
177
+ # Only for Action="SSHORT
178
+ :designated_location, # String: set when slot==2 only
179
+ :exempt_code, # int
180
+
181
+ # Clearing info
182
+ :account, # String: The account. For institutional customers only.
183
+ :settling_firm, # String: Institutional only
184
+ :clearing_account, # String: For IBExecution customers: Specifies the
185
+ # true beneficiary of the order. This value is required
186
+ # for FUT/FOP orders for reporting to the exchange.
187
+ :clearing_intent, # IBExecution customers: "", IB, Away, PTA (post trade allocation).
188
+
189
+ # SMART routing only
190
+ :discretionary_amount, # double: The amount off the limit price
191
+ # allowed for discretionary orders.
192
+ :etrade_only, # bool: Trade with electronic quotes.
193
+ :firm_quote_only, # bool: Trade with firm quotes.
194
+ :nbbo_price_cap, # double: Maximum Smart order distance from the NBBO.
195
+
196
+ # BOX or VOL ORDERS ONLY
197
+ :auction_strategy, # For BOX exchange only. Valid values:
198
+ # 1=AUCTION_MATCH, 2=AUCTION_IMPROVEMENT, 3=AUCTION_TRANSPARENT
199
+ :starting_price, # double: Starting price. Valid on BOX orders only.
200
+ :stock_ref_price, # double: The stock reference price, used for VOL
201
+ # orders to compute the limit price sent to an exchange (whether or not
202
+ # Continuous Update is selected), and for price range monitoring.
203
+ :delta, # double: Stock delta. Valid on BOX orders only.
204
+
205
+ # Pegged to stock or VOL orders. For price improvement option orders
206
+ # on BOX and VOL orders with dynamic management:
207
+ :stock_range_lower, # double: The lower value for the acceptable
208
+ # underlying stock price range.
209
+ :stock_range_upper, # double The upper value for the acceptable
210
+ # underlying stock price range.
211
+
212
+ # VOLATILITY ORDERS ONLY:
213
+ :volatility, # double: What the price is, computed via TWSs Options
214
+ # Analytics. For VOL orders, the limit price sent to an
215
+ # exchange is not editable, as it is the output of a
216
+ # function. Volatility is expressed as a percentage.
217
+ :volatility_type, # int: How the volatility is calculated: 1=daily, 2=annual
218
+ :reference_price_type, # int: For dynamic management of volatility orders:
219
+ # - 1 = Average of National Best Bid or Ask,
220
+ # - 2 = National Best Bid when buying a call or selling a put;
221
+ # and National Best Ask when selling a call or buying a put.
222
+ :delta_neutral_order_type, # String: Enter an order type to instruct TWS
223
+ # to submit a delta neutral trade on full or partial execution of the
224
+ # VOL order. For no hedge delta order to be sent, specify NONE.
225
+ :delta_neutral_aux_price, # double: Use this field to enter a value if
226
+ # the value in the deltaNeutralOrderType field is an order
227
+ # type that requires an Aux price, such as a REL order.
228
+ :continuous_update, # int: Used for dynamic management of volatility orders.
229
+ # Determines whether TWS is supposed to update the order price as the underlying
230
+ # moves. If selected, the limit price sent to an exchange is modified by TWS
231
+ # if the computed price of the option changes enough to warrant doing so. This
232
+ # is helpful in keeping the limit price up to date as the underlying price changes.
233
+
234
+ # COMBO ORDERS ONLY:
235
+ :basis_points, # double: EFP orders only
236
+ :basis_points_type, # double: EFP orders only
237
+
238
+ # SCALE ORDERS ONLY
239
+ :scale_init_level_size, # int: Size of the first (initial) order component.
240
+ :scale_subs_level_size, # int: Order size of the subsequent scale order
241
+ # components. Used in conjunction with scaleInitLevelSize().
242
+ :scale_price_increment, # double: Defines the price increment between
243
+ # scale components. This field is required for Scale orders.
244
+
245
+ # ALGO ORDERS ONLY
246
+ :algo_strategy, # String
247
+ :algo_params, # public Vector<TagValue> m_algoParams; ?!
248
+
249
+ # WTF?!
250
+ :what_if, # bool: Use to request pre-trade commissions and margin
251
+ # information. If set to true, margin and commissions data is received
252
+ # back via the OrderState() object for the openOrder() callback.
253
+ :not_held # public boolean m_notHeld; // Not Held
263
254
 
264
255
  # Some Order properties (received back from IB) are separated into
265
256
  # OrderState object. Here, they are lumped into Order proper: see OrderState.java
266
257
  # TODO: Extract OrderState object, for better record keeping
267
- attr_accessor :status, # String: Displays the order status.Possible values include:
268
- # � PendingSubmit - indicates that you have transmitted the order, but
269
- # have not yet received confirmation that it has been accepted by the
270
- # order destination. NOTE: This order status is NOT sent back by TWS
271
- # and should be explicitly set by YOU when an order is submitted.
272
- # � PendingCancel - indicates that you have sent a request to cancel
273
- # the order but have not yet received cancel confirmation from the
274
- # order destination. At this point, your order cancel is not confirmed.
275
- # You may still receive an execution while your cancellation request
276
- # is pending. NOTE: This order status is not sent back by TWS and
277
- # should be explicitly set by YOU when an order is canceled.
278
- # � PreSubmitted - indicates that a simulated order type has been
279
- # accepted by the IB system and that this order has yet to be elected.
280
- # The order is held in the IB system until the election criteria are
281
- # met. At that time the order is transmitted to the order destination
282
- # as specified.
283
- # � Submitted - indicates that your order has been accepted at the order
284
- # destination and is working.
285
- # � Cancelled - indicates that the balance of your order has been
286
- # confirmed canceled by the IB system. This could occur unexpectedly
287
- # when IB or the destination has rejected your order.
288
- # � ApiCancelled - canceled via API
289
- # � Filled - indicates that the order has been completely filled.
290
- # � Inactive - indicates that the order has been accepted by the system
291
- # (simulated orders) or an exchange (native orders) but that currently
292
- # the order is inactive due to system, exchange or other issues.
293
- :init_margin, # String: Shows the impact the order would have on your
294
- # initial margin.
295
- :maint_margin, # String: Shows the impact the order would have on your
296
- # maintenance margin.
297
- :equity_with_loan, # String: Shows the impact the order would have on
298
- # your equity with loan value.
299
- :commission, # double: Shows the commission amount on the order.
300
- :commission_currency, # String: Shows the currency of the commission.
301
-
302
- #The possible range of the actual order commission:
303
- :min_commission,
304
- :max_commission,
305
-
306
- :warning_text # String: Displays a warning message if warranted.
307
-
308
- #alias order_id id # TODO: Change due to ActiveRecord specifics
309
- #alias order_id= id= # TODO: Change due to ActiveRecord specifics
258
+ prop :status, # String: Displays the order status.Possible values include:
259
+ # � PendingSubmit - indicates that you have transmitted the order, but
260
+ # have not yet received confirmation that it has been accepted by the
261
+ # order destination. NOTE: This order status is NOT sent back by TWS
262
+ # and should be explicitly set by YOU when an order is submitted.
263
+ # � PendingCancel - indicates that you have sent a request to cancel
264
+ # the order but have not yet received cancel confirmation from the
265
+ # order destination. At this point, your order cancel is not confirmed.
266
+ # You may still receive an execution while your cancellation request
267
+ # is pending. NOTE: This order status is not sent back by TWS and
268
+ # should be explicitly set by YOU when an order is canceled.
269
+ # � PreSubmitted - indicates that a simulated order type has been
270
+ # accepted by the IB system and that this order has yet to be elected.
271
+ # The order is held in the IB system until the election criteria are
272
+ # met. At that time the order is transmitted to the order destination
273
+ # as specified.
274
+ # � Submitted - indicates that your order has been accepted at the order
275
+ # destination and is working.
276
+ # � Cancelled - indicates that the balance of your order has been
277
+ # confirmed canceled by the IB system. This could occur unexpectedly
278
+ # when IB or the destination has rejected your order.
279
+ # � ApiCancelled - canceled via API
280
+ # � Filled - indicates that the order has been completely filled.
281
+ # � Inactive - indicates that the order has been accepted by the system
282
+ # (simulated orders) or an exchange (native orders) but that currently
283
+ # the order is inactive due to system, exchange or other issues.
284
+ :commission, # double: Shows the commission amount on the order.
285
+ :commission_currency, # String: Shows the currency of the commission.
286
+
287
+ #The possible range of the actual order commission:
288
+ :min_commission,
289
+ :max_commission,
290
+
291
+ :warning_text, # String: Displays a warning message if warranted.
292
+
293
+ # String: Shows the impact the order would have on your initial margin.
294
+ :init_margin => proc { |val| self[:init_margin] = filter_max val },
295
+
296
+ # String: Shows the impact the order would have on your maintenance margin.
297
+ :maint_margin => proc { |val| self[:maint_margin] = filter_max val },
298
+
299
+ # String: Shows the impact the order would have on your equity with loan value.
300
+ :equity_with_loan => proc { |val| self[:equity_with_loan] = filter_max val }
310
301
 
311
302
  # IB uses weird String with Java Double.MAX_VALUE to indicate no value here
312
- def init_margin= val
313
- @init_margin = val == "1.7976931348623157E308" ? nil : val
303
+ def filter_max val
304
+ val == "1.7976931348623157E308" ? nil : val.to_f
314
305
  end
315
306
 
316
- # IB uses weird String with Java Double.MAX_VALUE to indicate no value here
317
- def maint_margin= val
318
- @maint_margin = val == "1.7976931348623157E308" ? nil : val
319
- end
320
-
321
- # IB uses weird String with Java Double.MAX_VALUE to indicate no value here
322
- def equity_with_loan= val
323
- @equity_with_loan = val == "1.7976931348623157E308" ? nil : val
324
- end
307
+ DEFAULT_PROPS = {:aux_price => 0.0,
308
+ :parent_id => 0,
309
+ :tif => 'DAY',
310
+ :outside_rth => false,
311
+ :open_close => "O",
312
+ :origin => Origin_Customer,
313
+ :transmit => true,
314
+ :designated_location => '',
315
+ :exempt_code => -1,
316
+ :delta_neutral_order_type => '',
317
+ :what_if => false,
318
+ :not_held => false,
319
+ :algo_strategy => '', }
325
320
 
326
321
  def initialize opts = {}
327
- # Assign defaults first!
328
- @aux_price = 0.0
329
- @parent_id=0
330
- @tif='DAY'
331
-
332
- @outside_rth = false
333
- @open_close = "O"
334
- @origin = Origin_Customer
335
- @transmit = true
336
- @designated_location = ''
337
- @exempt_code = -1
338
- @delta_neutral_order_type = ''
339
- @what_if = false
340
- @not_held = false
341
- @algo_strategy = ''
342
322
  @algo_params = []
343
-
344
- # TODO: Initialize with nil instead of Max_Value, or change
345
- # Order sending code in IB::Messages::Outgoing::PlaceOrder
346
- #@min_quantity = Max_Value
347
- #@percent_offset = Max_Value # -"-
348
- #@nbbo_price_cap = Max_Value # -"-
349
- #@starting_price = Max_Value # -"-
350
- #@stock_ref_price = Max_Value # -"-
351
- #@delta = Max_Value
352
- #@stock_range_lower = Max_Value # -"-
353
- #@stock_range_upper = Max_Value # -"-
354
- #@volatility = Max_Value # -"-
355
- #@volatility_type = Max_Value # -"-
356
- #@delta_neutral_aux_price = Max_Value # -"-
357
- #@reference_price_type = Max_Value # -"-
358
- #@trail_stop_price = Max_Value # -"-
359
- #@basis_points = Max_Value # -"-
360
- #@basis_points_type = Max_Value # -"-
361
- #@scale_init_level_size = Max_Value # -"-
362
- #@scale_subs_level_size = Max_Value # -"-
363
- #@scale_price_increment = Max_Value # -"-
364
- #@reference_price_type = Max_Value # -"-
365
- #@reference_price_type = Max_Value # -"-
366
- #@reference_price_type = Max_Value # -"-
367
- #@reference_price_type = Max_Value # -"-
368
-
369
323
  super opts
370
324
  end
371
325
 
@@ -433,10 +387,20 @@ module IB
433
387
  clearing_intent,
434
388
  not_held,
435
389
  contract.serialize_under_comp,
436
- serialize_algo,
390
+ serialize_algo(),
437
391
  what_if]
438
392
  end
439
393
 
394
+ def serialize_algo
395
+ if algo_strategy.nil? || algo_strategy.empty?
396
+ ['']
397
+ else
398
+ [algo_strategy,
399
+ algo_params.size,
400
+ algo_params.to_a]
401
+ end
402
+ end
403
+
440
404
  # Order comparison
441
405
  def == other
442
406
  perm_id && perm_id == other.perm_id ||
@@ -462,16 +426,6 @@ module IB
462
426
  # TODO: || compare all attributes!
463
427
  end
464
428
 
465
- def serialize_algo
466
- if algo_strategy.nil? || algo_strategy.empty?
467
- ['']
468
- else
469
- [algo_strategy,
470
- algo_params.size,
471
- algo_params.to_a]
472
- end
473
- end
474
-
475
429
  def to_s #human
476
430
  "<Order:" + instance_variables.map do |key|
477
431
  value = instance_variable_get(key)