class IB::Bag

“BAG” is not really a contract, but a combination (combo) of securities. AKA basket or bag of securities. Individual securities in combo are represented by ComboLeg objects.

Public Instance Methods

==(other) click to toggle source

Contract comparison

Calls superclass method
# File lib/models/ib/bag.rb, line 46
def == other
  super && same_legs?(other)
end
default_attributes() click to toggle source
Calls superclass method
# File lib/models/ib/bag.rb, line 18
def default_attributes
  super.merge :sec_type => :bag #,:legs => Array.new,
end
description() click to toggle source
# File lib/models/ib/bag.rb, line 22
def description
  self[:description] || to_human
end
legs_description() click to toggle source

TODO: Rewrite with legs and legs_description being strictly in sync… TODO: Find a way to serialize legs without references… IB-equivalent leg description.

# File lib/models/ib/bag.rb, line 35
def legs_description
  self[:legs_description] || legs.map { |leg| "#{leg.con_id}|#{leg.weight}" }.join(',')
end
same_legs?(other) click to toggle source

Check if two Contracts have same legs (maybe in different order)

# File lib/models/ib/bag.rb, line 40
def same_legs? other
  legs == other.legs ||
    legs_description.split(',').sort == other.legs_description.split(',').sort
end
to_human() click to toggle source
# File lib/models/ib/bag.rb, line 26
def to_human
  "<Bag: #{[symbol, exchange, currency].join(' ')} legs: #{legs_description} >"
end