class IB::Messages::Incoming::OpenOrder

Public Instance Methods

client_id() click to toggle source

Accessors to make OpenOrder API-compatible with OrderStatus message

# File lib/ib/messages/incoming/open_order.rb, line 77
def client_id
  order.client_id
end
contract() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 114
def contract
  @contract ||= IB::Contract.build(
      @data[:contract].merge(:underlying => underlying)
  )
end
filled?(value) click to toggle source

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

# File lib/ib/messages/incoming/open_order.rb, line 214
def filled? value
  case value
    when String
      !value.empty?
    when Float, Integer
      value > 0
    else
      !!value # to_bool
  end
end
load() click to toggle source
Calls superclass method
# File lib/ib/messages/incoming/open_order.rb, line 126
def load
  super

  load_map [proc { | | filled?(@data[:order][:delta_neutral_order_type]) },
              # 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, :continuous_update, :int],
           [:order, :reference_price_type, :int],
           [:order, :trail_stop_price, :decimal_max],
           [:order, :trailing_percent, :decimal_max],
           [:order, :basis_points, :decimal_max],
           [:order, :basis_points_type, :int_max],
           [:contract, :legs_description, :string],

           # As of client v.55, we receive in OpenOrder for Combos:
           #    Contract.orderComboLegs Array
           #    Order.leg_prices Array
           [:contract, :legs, :array, proc do |_|
             IB::ComboLeg.new :con_id => socket.read_int,
                              :ratio => socket.read_int,
                              :action => socket.read_string,
                              :exchange => socket.read_string,
                              :open_close => socket.read_int,
                              :short_sale_slot => socket.read_int,
                              :designated_location => socket.read_string,
                              :exempt_code => socket.read_int
           end],
           [:order, :leg_prices, :array, proc { |_| socket.read_decimal_max }],
           [:smart_combo_routing_params, :hash],

           [:order, :scale_init_level_size, :int_max],
           [:order, :scale_subs_level_size, :int_max],

           [:order, :scale_price_increment, :decimal_max],
           [proc { | | filled?(@data[:order][:scale_price_increment]) },
             # As of client v.54, we may receive scale order fields
             [:order, :scale_price_adjust_value, :decimal_max],
             [:order, :scale_price_adjust_interval, :int_max],
             [:order, :scale_profit_offset, :decimal_max],
             [:order, :scale_auto_reset, :boolean],
             [:order, :scale_init_position, :int_max],
             [:order, :scale_init_fill_qty, :decimal_max],
             [: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, :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_max], # :string],
           [:order_state, :maint_margin, :decimal_max], # :string],
           [:order_state, :equity_with_loan, :decimal_max], # :string],
           [:order_state, :commission, :decimal_max], # May be nil!
           [:order_state, :min_commission, :decimal_max], # May be nil!
           [:order_state, :max_commission, :decimal_max], # May be nil!
           [:order_state, :commission_currency, :string],
           [:order_state, :warning_text, :string]
end
local_id() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 89
 def local_id
  order.local_id
end
Also aliased as: order_id
order() click to toggle source

Object accessors

# File lib/ib/messages/incoming/open_order.rb, line 101
def order
  @order ||= IB::Order.new @data[:order].merge(:order_state => order_state)
end
order_id()
Alias for: local_id
order_state() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 105
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_id() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 81
def parent_id
  order.parent_id
end
perm_id() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 85
def perm_id
  order.perm_id
end
status() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 95
def status
  order.status
end
to_human() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 225
def to_human
  "<OpenOrder: #{contract.to_human} #{order.to_human}>"
end
under_comp()
Alias for: underlying
underlying() click to toggle source
# File lib/ib/messages/incoming/open_order.rb, line 120
def underlying
  @underlying = @data[:underlying_present] ? IB::Underlying.new(@data[:underlying]) : nil
end
Also aliased as: under_comp