lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.8 vs lib/ib-ruby/models/order_state.rb in ib-ruby-0.7.9
- old
+ new
@@ -61,9 +61,34 @@
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
+ ## Testing Order state:
+
+ def new?
+ status.empty? || status == 'New'
+ end
+
+ # Order is in a valid, working state on TWS side
+ def pending?
+ status == 'PendingSubmit' || status == 'PreSubmitted' || status == 'Submitted'
+ end
+
+ # Order is in invalid state
+ def active?
+ new? || pending?
+ end
+
+ # Order is in invalid state
+ def inactive?
+ !active? # status == 'Inactive'
+ end
+
+ def complete_fill?
+ status == 'Filled' && remaining == 0 # filled >= total_quantity # Manually corrected
+ end
+
# Comparison
def == other
other && other.is_a?(OrderState) &&
status == other.status &&
local_id == other.local_id &&