Class: IB::Models::ComboLeg

Inherits:
Model
  • Object
show all
Defined in:
lib/ib-ruby/models/combo_leg.rb

Overview

ComboLeg objects represent individual securities in a “BAG” contract - which is not really a contract, but a combination (combo) of securities. AKA basket or bag of securities.

Constant Summary collapse

SAME =

// open/close leg value is same as combo Specifies whether the order is an open or close order. Valid values are:

0
OPEN =

Same as the parent security. The only option for retail customers.

1
CLOSE =

Open. This value is only valid for institutional customers.

2
UNKNOWN =

Close. This value is only valid for institutional customers.

3
DEFAULT_PROPS =

int: ?

{:con_id => 0,
:open_close => SAME,
:short_sale_slot => 0,
:designated_location => '',
:exempt_code => -1, }

Instance Attribute Summary

Attributes inherited from Model

#created_at

Instance Method Summary collapse

Methods inherited from Model

#[], #[]=, #initialize

Methods included from ModelProperties

#define_property, #define_property_methods, #prop

Constructor Details

This class inherits a constructor from IB::Models::Model

Instance Method Details

#serialize(*fields) ⇒ Object

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



59
60
61
62
63
64
65
66
67
# File 'lib/ib-ruby/models/combo_leg.rb', line 59

def serialize *fields
  [con_id,
   ratio,
   action,
   exchange,
   (fields.include?(:extended) ? [open_close, short_sale_slot,
                                  designated_location, exempt_code] : [])
  ].flatten
end

#weightObject

Leg’s weight is a combination of action and ratio



43
44
45
# File 'lib/ib-ruby/models/combo_leg.rb', line 43

def weight
  action == 'BUY' ? ratio : -ratio
end

#weight=(value) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/ib-ruby/models/combo_leg.rb', line 47

def weight= value
  value = value.to_i
  if value > 0
    self.action = 'BUY'
    self.ratio = value
  else
    self.action = 'SELL'
    self.ratio = -value
  end
end