lib/ib-ruby/models/contracts/bag.rb in ib-ruby-0.7.4 vs lib/ib-ruby/models/contracts/bag.rb in ib-ruby-0.7.6
- old
+ new
@@ -9,15 +9,24 @@
# by ComboLeg objects.
class Bag < Contract
# General Notes:
# 1. :exchange for the leg definition must match that of the combination order.
# The exception is for a STK legs, which must specify the SMART exchange.
- # 2. :symbol => "USD" For combo Contract, this is an arbitrary value (like “USD”)
+ # 2. :symbol => "USD" For combo Contract, this is an arbitrary value (like "USD")
+ validates_format_of :sec_type, :with => /^bag$/, :message => "should be a bag"
+ validates_format_of :right, :with => /^none$/, :message => "should be none"
+ validates_format_of :expiry, :with => /^$/, :message => "should be blank"
+ validate :legs_cannot_be_empty
+
+ def legs_cannot_be_empty
+ errors.add(:legs, "legs cannot be empty") if legs.empty?
+ end
+
def initialize opts = {}
@legs = Array.new
- self[:sec_type] = IB::SECURITY_TYPES[:bag]
+ self.sec_type = :bag
super opts
end
def description
self[:description] || to_human
@@ -32,14 +41,9 @@
# TODO: Find a way to serialize legs without references...
# IB-equivalent leg description.
def legs_description
self[:legs_description] || legs.map { |leg| "#{leg.con_id}|#{leg.weight}" }.join(',')
- end
-
- def serialize_legs *fields
- return [0] if legs.empty?
- [legs.size, legs.map { |leg| leg.serialize *fields }]
end
# Check if two Contracts have same legs (maybe in different order)
def same_legs? other
legs == other.legs ||