lib/ib-ruby/models/contract.rb in ib-ruby-0.7.11 vs lib/ib-ruby/models/contract.rb in ib-ruby-0.7.12

- old
+ new

@@ -47,18 +47,18 @@ # Specifies a Put or Call. Valid input values are: P, PUT, C, CALL :right => {:set => proc { |val| self[:right] = case val.to_s.upcase - when 'NONE', '', '0', '?' - '' - when 'PUT', 'P' - 'P' - when 'CALL', 'C' - 'C' - else - val + when 'NONE', '', '0', '?' + '' + when 'PUT', 'P' + 'P' + when 'CALL', 'C' + 'C' + else + val end }, :validate => {:format => {:with => /^put$|^call$|^none$/, :message => "should be put, call or none"}} } @@ -68,17 +68,24 @@ has_many :orders # Placed for this Contract has_one :contract_detail # Volatile info about this Contract - has_many :combo_legs # for Combo/BAG Contracts only + # For Contracts that are part of BAG + has_one :leg, :class_name => 'ComboLeg', :foreign_key => :leg_contract_id + has_one :combo, :class_name => 'Contract', :through => :leg + + # for Combo/BAG Contracts that contain ComboLegs + has_many :combo_legs, :foreign_key => :combo_id + has_many :leg_contracts, :class_name => 'Contract', :through => :combo_legs alias legs combo_legs alias legs= combo_legs= alias combo_legs_description legs_description alias combo_legs_description= legs_description= - has_one :underlying # for Delta-Neutral Combo Contracts only + # for Delta-Neutral Combo Contracts + has_one :underlying alias under_comp underlying alias under_comp= underlying= ### Extra validations @@ -140,15 +147,15 @@ end # Defined in Contract, not BAG subclass to keep code DRY def serialize_legs *fields case - when !bag? - [] - when legs.empty? - [0] - else - [legs.size, legs.map { |leg| leg.serialize *fields }].flatten + when !bag? + [] + when legs.empty? + [0] + else + [legs.size, legs.map { |leg| leg.serialize *fields }].flatten end end # This produces a string uniquely identifying this contract, in the format used # for command line arguments in the IB-Ruby examples. The format is: