Class: IB::OrderState

Inherits:
Model show all
Includes:
BaseProperties
Defined in:
lib/models/ib/order_state.rb

Overview

OrderState represents dynamic (changeable) info about a single Order, isolating these changes and making Order essentially immutable

Instance Method Summary collapse

Methods included from BaseProperties

#content_attributes, #default_attributes, #set_attribute_defaults, #update_missing

Instance Method Details

#==(other) ⇒ Object

Comparison



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/models/ib/order_state.rb', line 96

def == other

  super(other) ||
    other.is_a?(self.class) &&
    status == other.status &&
    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 &&
    init_margin == other.init_margin &&
    maint_margin == other.maint_margin &&
    equity_with_loan == other.equity_with_loan &&
    why_held == other.why_held &&
    warning_text == other.warning_text &&
    commission == other.commission
end

#active?Boolean

Order is in invalid state

Returns:

  • (Boolean)


82
83
84
# File 'lib/models/ib/order_state.rb', line 82

def active?
  new? || pending?
end

#complete_fill?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/models/ib/order_state.rb', line 91

def complete_fill?
  status == 'Filled' && remaining == 0 # filled >= total_quantity # Manually corrected
end

#inactive?Boolean

Order is in invalid state

Returns:

  • (Boolean)


87
88
89
# File 'lib/models/ib/order_state.rb', line 87

def inactive?
  !active? # status == 'Inactive'
end

#new?Boolean

Testing Order state:

Returns:

  • (Boolean)


67
68
69
# File 'lib/models/ib/order_state.rb', line 67

def new?
  status.empty? || status == 'New'
end

#pending?Boolean

Order is in a valid, working state on TWS side

Returns:

  • (Boolean)


77
78
79
# File 'lib/models/ib/order_state.rb', line 77

def pending?
   || status == 'PendingSubmit'
end

#submitted?Boolean

Order is in a valid, working state on TWS side

Returns:

  • (Boolean)


72
73
74
# File 'lib/models/ib/order_state.rb', line 72

def 
  status == 'PreSubmitted' || status == 'Submitted'
end

#to_humanObject Also known as: to_s



115
116
117
118
119
120
121
122
123
124
# File 'lib/models/ib/order_state.rb', line 115

def to_human
  "<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}" : "") +
    (why_held ? " why_held #{why_held}" : '') +
    ((warning_text && warning_text != '') ? " warning #{warning_text}" : '') + ">"
end