Class: IB::OutgoingMessages::PlaceOrder

Inherits:
AbstractMessage show all
Defined in:
lib/ib-ruby/messages.rb

Overview

Data format is { :order_id => int, :contract => Contract, :order => Order }

Instance Attribute Summary

Attributes inherited from ExtremelyAbstractMessage

#created_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractMessage

#initialize, #send

Methods inherited from ExtremelyAbstractMessage

#to_human

Constructor Details

This class inherits a constructor from IB::OutgoingMessages::AbstractMessage

Class Method Details

.message_idObject



132
133
134
# File 'lib/ib-ruby/messages.rb', line 132

def self.message_id
  3
end

Instance Method Details

#queue(server) ⇒ Object



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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/ib-ruby/messages.rb', line 136

def queue(server)
  queue = [ self.class.message_id,
            20, # version
            @data[:order_id],
            @data[:contract].symbol,
            @data[:contract].sec_type,
            @data[:contract].expiry,
            @data[:contract].strike,
            @data[:contract].right
          ]
  queue.push(@data[:contract].multiplier) if server[:version] >= 15
  queue.push(@data[:contract].exchange) if server[:version] >= 14
  queue.push(@data[:contract].currency)
  queue.push(@data[:contract].local_symbol) if server[:version] >= 2

  queue.concat([
                @data[:order].tif,
                @data[:order].oca_group,
                @data[:order].,
                @data[:order].open_close,
                @data[:order].origin,
                @data[:order].order_ref,
                @data[:order].transmit
                ])

  queue.push(@data[:contract].parent_id) if server[:version] >= 4

  queue.concat([
                @data[:order].block_order,
                @data[:order].sweep_to_fill,
                @data[:order].display_size,
                @data[:order].trigger_method,
                @data[:order].ignore_rth
               ]) if server[:version] >= 5

  queue.push(@data[:order].hidden) if server[:version] >= 7


  queue.concat(@data[:contract].serialize_combo_legs(true)) if server[:version] >= 8 && @data[:contract].sec_type.upcase == "BAG" # "BAG" is defined as a constant in EClientSocket.java, line 45

  queue.push(@data[:order].shares_allocation) if server[:version] >= 9 # EClientSocket.java says this is deprecated. No idea.
  queue.push(@data[:order].discretionary_amount) if server[:version] >= 10
  queue.push(@data[:order].good_after_time) if server[:version] >= 11
  queue.push(@data[:order].good_till_date) if server[:version] >= 12

  queue.concat([
                @data[:order].fa_group,
                @data[:order].fa_method,
                @data[:order].fa_percentage,
                @data[:order].fa_profile
               ]) if server[:version] >= 13

  queue.concat([
                @data[:order].short_sale_slot,
                @data[:order].designated_location
               ]) if server[:version] >= 18

  queue.concat([
                @data[:order].oca_type,
                @data[:order].rth_only,
                @data[:order].rule_80a,
                @data[:order].settling_firm,
                @data[:order].all_or_none,
                nilFilter(@data[:order].min_quantity),
                nilFilter(@data[:order].percent_offset),
                @data[:order].etrade_only,
                @data[:order].firm_quote_only,
                nilFilter(@data[:order].nbbo_price_cap),
                nilFilter(@data[:order].auction_strategy),
                nilFilter(@data[:order].starting_price),
                nilFilter(@data[:order].stock_ref_price),
                nilFilter(@data[:order].delta),

                # Says the Java here:
                # "// Volatility orders had specific watermark price attribs in server version 26"
                # I have no idea what this means.

                ((server[:version] == 26 && @data[:order].order_type.upcase == "VOL") ? EOL : @data[:order].stock_range_lower),
                ((server[:version] == 26 && @data[:order].order_type.upcase == "VOL") ? EOL : @data[:order].stock_range_upper),

               ]) if server[:version] >= 19

  queue.push(@data[:order].override_percentage_constraints) if server[:version] >= 22

  # Volatility orders
  if server[:version] >= 26
    queue.concat([nilFilter(@data[:order].volatility),
                  nilFilter(@data[:order].volatility_type) ])

    if server[:version] < 28
      queue.push(@data[:order].delta_neutral_order_type.upcase == "MKT")
    else
      queue.concat([@data[:order].delta_neutral_order_type,
                    nilFilter(@data[:order].delta_neutral_aux_price)
                    ])
    end

    queue.push(@data[:order].continuous_update)
    queue.concat([
                  (@data[:order].order_type.upcase == "VOL" ? @data[:order].stock_range_lower : EOL),
                  (@data[:order].order_type.upcase == "VOL" ? @data[:order].stock_range_upper : EOL)
                 ]) if server[:version] == 26

    queue.push(@data[:order].reference_price_type)

  end # if version >= 26

  queue
end