lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.6 vs lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.8

- old
+ new

@@ -5,11 +5,11 @@ # isolating these changes and making Order essentially immutable class OrderState < Model.for(:order_state) include ModelProperties #p column_names - # has_one :order + belongs_to :order # Properties arriving via OpenOrder message prop :init_margin, # Float: The impact the order would have on your initial margin. :maint_margin, # Float: The impact the order would have on your maintenance margin. :equity_with_loan, # Float: The impact the order would have on your equity @@ -20,20 +20,20 @@ :warning_text # String: Displays a warning message if warranted. # Properties arriving via OrderStatus message: prop :filled, # int :remaining, # int - :average_fill_price, # double - :last_fill_price, # double + [: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 :order_id, # int: Order id associated with client (volatile). + prop [:local_id, :order_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 # String: Displays the order status. Possible values include: + :status => :s # String: Displays the order status. Possible values include: # - PendingSubmit - indicates that you have transmitted the order, but # have not yet received confirmation that it has been accepted by the # order destination. NOTE: This order status is NOT sent back by TWS # and should be explicitly set by YOU when an order is submitted. # - PendingCancel - indicates that you have sent a request to cancel @@ -56,21 +56,20 @@ # - Filled - indicates that the order has been completely filled. # - Inactive - indicates that the order has been accepted by the system # (simulated orders) or an exchange (native orders) but that currently # the order is inactive due to system, exchange or other issues. - prop :tester + 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 - validates_numericality_of :order_id, :perm_id, :client_id, :only_integer => true - - DEFAULT_PROPS = {:status => 'New'} # Starting new Orders with this status - # Comparison def == other other && other.is_a?(OrderState) && status == other.status && - order_id == other.order_id && + local_id == other.local_id && perm_id == other.perm_id && client_id == other.client_id && filled == other.filled && remaining == other.remaining && last_fill_price == other.last_fill_price && @@ -81,10 +80,10 @@ warning_text == other.warning_text && commission == other.commission end def to_human - "<OrderState: #{status} ##{order_id}/#{perm_id} from #{client_id}" + + "<OrderState: #{status} ##{local_id}/#{perm_id} from #{client_id}" + (filled ? " filled #{filled}/#{remaining}" : '') + (last_fill_price ? " at #{last_fill_price}/#{average_fill_price}" : '') + (init_margin ? " margin #{init_margin}/#{maint_margin}" : '') + (equity_with_loan ? " equity #{equity_with_loan}" : '') + (commission && commission > 0 ? " fee #{commission}" : "") +