Class: IB::Messages::Outgoing::PlaceOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/ib/messages/outgoing/place_order.rb

Instance Method Summary collapse

Instance Method Details

#encodeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
# File 'lib/ib/messages/outgoing/place_order.rb', line 12

def encode

  order = @data[:order]
  contract = @data[:contract]

  [super,

   contract.serialize_long(:con_id, :sec_id),

   # main order fields
   (order.side == :short ? 'SSHORT' : order.side == :short_exempt ? 'SSHORTX' : order.side.to_sup),
   order.quantity,
   order[:order_type], # Internal code, 'LMT' instead of :limit
   order.limit_price,
   order.aux_price,
   order[:tif],
   order.oca_group,
   order.,
   order.open_close.to_sup[0..0],
   order[:origin],
   order.order_ref,
   order.transmit,
   order.parent_id,
   order.block_order || false,
   order.sweep_to_fill || false,
   order.display_size,
   order[:trigger_method],
   order.outside_rth || false, # was: ignore_rth
   order.hidden || false,
   contract.serialize_legs(:extended),


   if contract.bag?
     [
       ## Support for per-leg prices in Order
       [contract.legs.size] + contract.legs.map { |_| nil },
       ## Support for combo routing params in Order
       order.combo_params.empty? ? 0 : [order.combo_params.size] + order.combo_params.to_a
     ]
   else
     []
   end,

   '', # deprecated shares_allocation field
   order.discretionary_amount,
   order.good_after_time,
   order.good_till_date,
   order.fa_group,
   order.fa_method,
   order.fa_percentage,
   order.fa_profile,
   order[:short_sale_slot], # 0 only for retail, 1 or 2 for institution  (Institutional)
   order.designated_location, # only populate when short_sale_slot == 2    (Institutional)
   order.exempt_code,
   order[:oca_type],
   order[:rule_80a], #.to_sup[0..0],
   order.settling_firm,
   order.all_or_none || false,
   order.min_quantity,
   order.percent_offset,
   order.etrade_only || false,
   order.firm_quote_only || false,
   order.nbbo_price_cap,
   order[:auction_strategy],
   order.starting_price,
   order.stock_ref_price,
   order.delta,
   order.stock_range_lower,
   order.stock_range_upper,
   order.override_percentage_constraints || false,
   order.volatility, #              Volatility orders
   order[:volatility_type], #       Volatility orders

   # Support for delta neutral orders with parameters
   if order.delta_neutral_order_type && order.delta_neutral_order_type != :none
     [order[:delta_neutral_order_type],
      order.delta_neutral_aux_price,
      order.delta_neutral_con_id,
      order.delta_neutral_settling_firm,
      order.,
      order[:delta_neutral_clearing_intent]
      ]
   else
     ['', '']
   end,

   order.continuous_update, #        Volatility orders
   order[:reference_price_type], #   Volatility orders

   order.trail_stop_price, #         TRAIL_STOP_LIMIT stop price
   order.trailing_percent, #         Support for trailing percent

   order.scale_init_level_size, #    Scale Orders
   order.scale_subs_level_size, #    Scale Orders
   order.scale_price_increment, #    Scale Orders

   # Support for extended scale orders parameters
   if order.scale_price_increment && order.scale_price_increment > 0
     [order.scale_price_adjust_value,
      order.scale_price_adjust_interval,
      order.scale_profit_offset,
      order.scale_auto_reset || false,
      order.scale_init_position,
      order.scale_init_fill_qty,
      order.scale_random_percent || false
      ]
   else
     []
   end,

   # Support for hedgeType
   order.hedge_type, # MIN_SERVER_VER_HEDGE_ORDERS
   order.hedge_param || [],

   order.opt_out_smart_routing || false, # MIN_SERVER_VER_OPT_OUT_SMART_ROUTING

   order.,
   order.clearing_intent,
   order.not_held || false,
   contract.serialize_under_comp,
   order.serialize_algo(),
   order.what_if]

end