Class: IB::Messages::Incoming::OpenOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/ib/messages/incoming/open_order.rb

Instance Method Summary collapse

Instance Method Details

#client_idObject

Accessors to make OpenOrder API-compatible with OrderStatus message



72
73
74
# File 'lib/ib/messages/incoming/open_order.rb', line 72

def client_id
  order.client_id
end

#conditionsObject



94
95
96
# File 'lib/ib/messages/incoming/open_order.rb', line 94

def conditions
	order.conditions
end

#contractObject



113
114
115
116
117
# File 'lib/ib/messages/incoming/open_order.rb', line 113

def contract
  @contract ||= IB::Contract.build(
      @data[:contract].merge(:underlying => underlying)
  )
end

#filled?(value) ⇒ Boolean

Check if given value was set by TWS to something vaguely “positive”

Returns:

  • (Boolean)


258
259
260
261
262
263
264
265
266
267
268
# File 'lib/ib/messages/incoming/open_order.rb', line 258

def filled? value
#	  puts "filled: #{value.class} --> #{value.to_s}"
  case value
    when String
      (!value.empty?)# && (value != :none) && (value !='None')  
    when Float, Integer, BigDecimal
      value > 0
    else
      !!value # to_bool
  end
end

#loadObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/ib/messages/incoming/open_order.rb', line 125

def load
  super

#          load_map [proc { | | (@data[:order][:delta_neutral_order_type] != 'None') },
  load_map [proc { | | filled?(@data[:order][:delta_neutral_order_type]) }, # todo Testcase!
              # As of client v.52, we may receive delta... params in openOrder
             [:order, :delta_neutral_con_id, :int],
             [:order, :delta_neutral_settling_firm, :string],
             [:order, :delta_neutral_clearing_account, :string],
             [:order, :delta_neutral_clearing_intent, :string],
             [:order, :delta_neutral_open_close, :string],
             [:order, :delta_neutral_short_sale, :bool],
		     [:order, :delta_neutral_short_sale_slot, :int],
		     [:order, :delta_neutral_designated_location, :string] ],  # end proc
		   [:order, :continuous_update, :int],
           [:order, :reference_price_type, :int],
           [:order, :trail_stop_price, :decimal],   # not trail-orders. see below
           [:order, :trailing_percent, :decimal],
           [:order, :basis_points, :decimal],
           [:order, :basis_points_type, :int],

           [:contract, :legs_description, :string],

           # As of client v.55, we receive in OpenOrder for Combos:
           #    Contract.orderComboLegs Array
           #    Order.leg_prices Array
           [:contract, :combo_legs, :array, proc do |_|
             IB::ComboLeg.new :con_id => @buffer.read_int,
                              :ratio => @buffer.read_int,
                              :action => @buffer.read_string,
                              :exchange => @buffer.read_string,
                              :open_close => @buffer.read_int,
                              :short_sale_slot => @buffer.read_int,
                              :designated_location => @buffer.read_string,
                              :exempt_code => @buffer.read_int
           end],
           [:order, :leg_prices, :array, proc { |_| buffer.read_decimal }],   #  needs testing
           [:order, :combo_params, :hash ],
		   #, proc do |_|
		#		      { tag: buffer.read_string, value: buffer.read_string }  # needs testing
		 #  end],

           [:order, :scale_init_level_size, :int],
           [:order, :scale_subs_level_size, :int],

           [:order, :scale_price_increment, :decimal],
           [proc { | | filled?(@data[:order][:scale_price_increment]) },
             # As of client v.54, we may receive scale order fields
             [:order, :scale_price_adjust_value, :decimal],
             [:order, :scale_price_adjust_interval, :int],
             [:order, :scale_profit_offset, :decimal],
             [:order, :scale_auto_reset, :boolean],
             [:order, :scale_init_position, :int],
             [:order, :scale_init_fill_qty, :decimal],
             [:order, :scale_random_percent, :boolean]
           ],

           [:order, :hedge_type, :string],
           [proc { | | filled?(@data[:order][:hedge_type]) },
             # As of client v.49/50, we can receive hedgeType, hedgeParam
             [:order, :hedge_param, :string]
          ],

           [:order, :opt_out_smart_routing, :boolean],
           [:order, :clearing_account, :string],
           [:order, :clearing_intent, :string],
           [:order, :not_held, :boolean],

           [:underlying_present, :boolean],
           [proc { | | filled?(@data[:underlying_present]) },
            [:underlying, :con_id, :int],
            [:underlying, :delta, :decimal],
            [:underlying, :price, :decimal]
           ],

           # TODO: Test Order with algo_params, scale and legs!
           [:order, :algo_strategy, :string],
           [proc { | | filled?(@data[:order][:algo_strategy]) },
            [:order, :algo_params, :hash]  
           ],
           [:order, :solicided, :boolean],
           [:order, :what_if, :boolean],
		   [:order_state, :status, :string],
           # IB uses weird String with Java Double.MAX_VALUE to indicate no value here
           [:order_state, :init_margin, :decimal], # :string],
           [:order_state, :maint_margin, :decimal], # :string],
           [:order_state, :equity_with_loan, :decimal], # :string],
           [:order_state, :commission, :decimal], # May be nil!
           [:order_state, :min_commission, :decimal], # May be nil!
           [:order_state, :max_commission, :decimal], # May be nil!
           [:order_state, :commission_currency, :string],
           [:order_state, :warning_text, :string],


           [:order, :random_size, :boolean],
           [:order, :random_price, :boolean],

		   ## todo: ordertype = PEG BENCH  --  -> test!
		   [proc{ @data[:order][:order_type] == 'PEG BENCH' },
[:order, :reference_contract_id, :int ],
[:order, :is_pegged_change_amount_decrease, :bool ],
[:order, :pegged_change_amount, :decimal ],
[:order, :reference_change_amount, :decimal ],
[:order, :reference_exchange_id, :string ]
		   ],
		    [:order , :conditions, :array, proc {  IB::OrderCondition.make_from( @buffer ) } ],
				[proc { !@data[:order][:conditions].blank?  },
						[:order, :conditions_ignore_rth, :bool],
						[:order, :conditions_cancel_order,:bool]
					], 
		    [:order, :adjusted_order_type, :string],
		    [:order, :trigger_price,  :decimal],
		    [:order, :trail_stop_price,  :decimal],	    # cpp -source: Traillimit orders 
		    [:order, :adjusted_stop_limit_price,  :decimal],
		    [:order, :adjusted_trailing_amount,  :decimal],
		    [:order, :adjustable_trailing_unit,  :int],

		    [:order, :soft_dollar_tier_name,  :string_not_null],
		    [:order, :soft_dollar_tier_value, :string_not_null],
		    [:order, :soft_dollar_tier_display_name,  :string_not_null],
		    [:order, :cash_qty,  :decimal],
				[:order, :mifid_2_decision_maker, :string_not_null ],   ## correct appearance of fields below
				[:order, :mifid_2_decision_algo, :string_not_null ],		##  is not tested yet
				[:order, :mifid_2_execution_maker, :string ],
				[:order, :mifid_2_execution_algo, :string_not_null ],
				[:order, :dont_use_auto_price_for_hedge, :string ],
				[:order, :is_O_ms_container, :bool ],
				[ :order, :discretionary_up_to_limit_price, :decimal ]

    
end

#local_idObject Also known as: order_id



84
85
86
# File 'lib/ib/messages/incoming/open_order.rb', line 84

def local_id
  order.local_id
end

#orderObject

Object accessors



100
101
102
# File 'lib/ib/messages/incoming/open_order.rb', line 100

def order
  @order ||= IB::Order.new @data[:order].merge(:order_state => order_state)
end

#order_stateObject



104
105
106
107
108
109
110
111
# File 'lib/ib/messages/incoming/open_order.rb', line 104

def order_state
  @order_state ||= IB::OrderState.new(
      @data[:order_state].merge(
          :local_id => @data[:order][:local_id],
          :perm_id => @data[:order][:perm_id],
          :parent_id => @data[:order][:parent_id],
          :client_id => @data[:order][:client_id]))
end

#parent_idObject



76
77
78
# File 'lib/ib/messages/incoming/open_order.rb', line 76

def parent_id
  order.parent_id
end

#perm_idObject



80
81
82
# File 'lib/ib/messages/incoming/open_order.rb', line 80

def perm_id
  order.perm_id
end

#statusObject



90
91
92
# File 'lib/ib/messages/incoming/open_order.rb', line 90

def status
  order.status
end

#to_humanObject



270
271
272
# File 'lib/ib/messages/incoming/open_order.rb', line 270

def to_human
  "<OpenOrder: #{contract.to_human} #{order.to_human}>"
end

#underlyingObject Also known as: under_comp



119
120
121
# File 'lib/ib/messages/incoming/open_order.rb', line 119

def underlying
  @underlying = @data[:underlying_present] ? IB::Underlying.new(@data[:underlying]) : nil
end