Class: IB::Messages::Incoming::OpenOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/ib-ruby/messages/incoming/open_order.rb

Instance Method Summary collapse

Instance Method Details

#filled?(value) ⇒ Boolean

Check if given value was set by TWS to something vaguely “positive”

Returns:

  • (Boolean)


184
185
186
187
188
189
190
191
192
193
# File 'lib/ib-ruby/messages/incoming/open_order.rb', line 184

def filled? value
  case value
    when String
      !value.empty?
    when Float, Integer
      value > 0
    else
      !!value # to_bool
  end
end

#loadObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/ib-ruby/messages/incoming/open_order.rb', line 85

def load
  super

  load_map [27, [proc { | | filled?(@data[:order][:delta_neutral_order_type]) },
                 # As of client v.52, we receive delta... params in openOrder
                 [:order, :delta_neutral_con_id, :int],
                 [:order, :delta_neutral_settling_firm, :string],
                 [:order, :delta_neutral_clearing_account, :string],
                 [:order, :delta_neutral_clearing_intent, :string]]
           ],
           [:order, :continuous_update, :int],
           [:order, :reference_price_type, :int],
           [:order, :trail_stop_price, :decimal_max],

           # As of client v.56, we receive trailing_percent in openOrder
           [30, [:order, :trailing_percent, :decimal_max]], # Never! 28 currently

           [:order, :basis_points, :decimal_max],
           [:order, :basis_points_type, :int_max],
           [:contract, :legs_description, :string],

           # Never happens! 28 is the max supported version currently
           # As of client v.55, we receive orderComboLegs (price) in openOrder
           [29, [:contract, :legs, :array, proc do |_|
             Models::ComboLeg.new :con_id => socket.read_int,
                                  :ratio => socket.read_int,
                                  :action => socket.read_string,
                                  :exchange => socket.read_string,
                                  :open_close => socket.read_int,
                                  :short_sale_slot => socket.read_int,
                                  :designated_location => socket.read_string,
                                  :exempt_code => socket.read_int
           end],

            # Order keeps received leg prices in a separate Array for some reason ?!
            [:order, :leg_prices, :array, proc { |_| socket.read_decimal_max }],
           ],
           # As of client v.51, we can receive smartComboRoutingParams in openOrder
           [26, [:smart_combo_routing_params, :hash]],

           [:order, :scale_init_level_size, :int_max],
           [:order, :scale_subs_level_size, :int_max],
           [:order, :scale_price_increment, :decimal_max],

           # As of client v.54, we can receive scale order fields
           [28, [proc { | | filled?(@data[:order][:scale_price_increment]) },
                 [:order, :scale_price_adjust_value, :decimal_max],
                 [:order, :scale_price_adjust_interval, :int_max],
                 [:order, :scale_profit_offset, :decimal_max],
                 [:order, :scale_auto_reset, :boolean],
                 [:order, :scale_init_position, :int_max],
                 [:order, :scale_init_position, :int_max],
                 [:order, :scale_init_fill_qty, :decimal_max],
                 [:order, :scale_random_percent, :boolean]]
           ],

           # As of client v.49/50, we can receive hedgeType, hedgeParam, optOutSmartRouting
           [25,
            [:order, :hedge_type, :string],
            [proc { | | filled?(@data[:order][:hedge_type]) },
             [:order, :hedge_param, :string],
            ],
            [:order, :opt_out_smart_routing, :boolean]
           ],

           [:order, :clearing_account, :string],
           [:order, :clearing_intent, :string],
           [:order, :not_held, :boolean],
           [:contract, :under_comp, :boolean],

           [proc { | | filled?(@data[:contract][:under_comp]) },
            [:contract, :under_con_id, :int],
            [:contract, :under_delta, :decimal],
            [:contract, :under_price, :decimal]
           ],

           [:order, :algo_strategy, :string],

           # TODO: Test Order with algo_params, scale and legs!
           [proc { | | filled?(@data[:order][:algo_strategy]) },
            [:order, :algo_params, :hash]
           ],

           [:order, :what_if, :boolean],
           [:order, :status, :string],
           [:order, :init_margin, :string],
           [:order, :maint_margin, :string],
           [:order, :equity_with_loan, :string],
           [:order, :commission, :decimal_max], # May be nil!
           [:order, :min_commission, :decimal_max], # May be nil!
           [:order, :max_commission, :decimal_max], # May be nil!
           [:order, :commission_currency, :string],
           [:order, :warning_text, :string]

  @order = Models::Order.new @data[:order]
  @contract = Models::Contract.build @data[:contract]
end

#order_idObject

Accessors to make OpenOrder API-compatible with OrderStatus message



77
78
79
# File 'lib/ib-ruby/messages/incoming/open_order.rb', line 77

def order_id
  order && order.order_id
end

#statusObject



81
82
83
# File 'lib/ib-ruby/messages/incoming/open_order.rb', line 81

def status
  order && order.status
end

#to_humanObject



195
196
197
# File 'lib/ib-ruby/messages/incoming/open_order.rb', line 195

def to_human
  "<OpenOrder: #{@contract.to_human} #{@order.to_human}>"
end