lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.9 vs lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.10
- old
+ new
@@ -25,11 +25,11 @@
[:price, :last_fill_price,], # double
[:average_price, :average_fill_price], # double
:why_held # String: comma-separated list of reasons for order to be held.
# Properties arriving in both messages:
- prop [:local_id, :order_id], # int: Order id associated with client (volatile).
+ prop :local_id, # int: Order id associated with client (volatile).
:perm_id, # int: TWS permanent id, remains the same over TWS sessions.
:client_id, # int: The id of the client that placed this order.
:parent_id, # int: The order ID of the parent (original) order, used
:status => :s # String: Displays the order status. Possible values include:
# - PendingSubmit - indicates that you have transmitted the order, but
@@ -61,18 +61,30 @@
validates_format_of :status, :without => /^$/, :message => 'must not be empty'
validates_numericality_of :price, :average_price, :allow_nil => true
validates_numericality_of :local_id, :perm_id, :client_id, :parent_id, :filled,
:remaining, :only_integer => true, :allow_nil => true
+ def default_attributes
+ super.merge :filled => 0,
+ :remaining => 0,
+ :price => 0.0,
+ :average_price => 0.0
+ end
+
## Testing Order state:
def new?
status.empty? || status == 'New'
end
# Order is in a valid, working state on TWS side
+ def submitted?
+ status == 'PreSubmitted' || status == 'Submitted'
+ end
+
+ # Order is in a valid, working state on TWS side
def pending?
- status == 'PendingSubmit' || status == 'PreSubmitted' || status == 'Submitted'
+ submitted? || status == 'PendingSubmit'
end
# Order is in invalid state
def active?
new? || pending?