class IB::ComboLeg

ComboLeg is essentially a join Model between Combo (BAG) Contract and individual Contracts (securities) that this BAG contains.

Public Instance Methods

==(other) click to toggle source

Order comparison

Calls superclass method IB::BaseProperties#==
# File lib/models/ib/combo_leg.rb, line 89
def == other
  super(other) ||
    other.is_a?(self.class) &&
    con_id == other.con_id &&
    ratio == other.ratio &&
    open_close == other.open_close && 
    short_sale_slot == other.short_sale_slot &&
    exempt_code == other.exempt_code &&
    side == other.side &&
    exchange == other.exchange &&
    designated_location == other.designated_location
end
default_attributes() click to toggle source
Calls superclass method IB::BaseProperties#default_attributes
# File lib/models/ib/combo_leg.rb, line 42
def default_attributes
  super.merge :con_id => 0,
    :ratio => 1,
    :side => :buy,
    :open_close => :same, # The only option for retail customers.
    :short_sale_slot => :default,
    :designated_location => '',
    :exchange => 'SMART', # Unless SMART, Order modification fails
    :exempt_code => -1
end
serialize(*fields) click to toggle source

Some messages include open_close, some don't. wtf.

# File lib/models/ib/combo_leg.rb, line 70
def serialize *fields
  [con_id,
   ratio,
   side.to_sup,
   exchange,
   (fields.include?(:extended) ?
    [self[:open_close],
     self[:short_sale_slot],
     designated_location,
     exempt_code] :
    [])
   ].flatten
end
to_human() click to toggle source
# File lib/models/ib/combo_leg.rb, line 84
def to_human
  "<ComboLeg: #{side} #{ratio} con_id #{con_id} at #{exchange}>"
end
weight() click to toggle source

Leg's weight is a combination of action and ratio

# File lib/models/ib/combo_leg.rb, line 54
def weight
  side == :buy ? ratio : -ratio
end
weight=(value) click to toggle source
# File lib/models/ib/combo_leg.rb, line 58
def weight= value
  value = value.to_i
  if value > 0
    self.side = :buy
    self.ratio = value
  else
    self.side = :sell
    self.ratio = -value
  end
end