ib 3.0.0

A Rust client to the Interactive Brokers HTTP REST API
Documentation
1
2
3
4
5
6
7
8
9
10
11
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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/* 
 * Client Portal Web API
 *
 * Client Poral Web API
 *
 * OpenAPI spec version: 1.0.0
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 */


#[allow(unused_imports)]
use serde_json::Value;

#[derive(Debug, Serialize, Deserialize)]
pub struct OrderRequest {
  /// acctId is optional. It should be one of the accounts returned by /iserver/accounts. If not passed, the first one in the list is selected. 
  #[serde(rename = "acctId")]
  acct_id: Option<String>,
  /// Set the allocation method when placing an order using an FA account for a group Possible allocation methods are \"NetLiquidity\", \"AvailableEquity\", \"EqualQuantity\" and \"PctChange\". 
  #[serde(rename = "allocationMethod")]
  allocation_method: Option<String>,
  /// optional if order is STOP_LIMIT, this is the stop price. You must specify both price and auxPrice for STOP_LIMIT orders. 
  #[serde(rename = "auxPrice")]
  aux_price: Option<Value>,
  /// Customer Order ID. An arbitrary string that can be used to identify the order, e.g \"my-fb-order\". The value must be unique for a 24h span. Please do not set this value for child orders when placing a bracket order. 
  #[serde(rename = "cOID")]
  c_oid: Option<String>,
  /// conid is the identifier of the security you want to trade, you can find the conid with /iserver/secdef/search. 
  #[serde(rename = "conid")]
  conid: Option<i32>,
  /// double number, this is the cash quantity field which can only be used for FX conversion order. When using 'fxQty' you don't need to specify 'quantity'. 
  #[serde(rename = "fxQty")]
  fx_qty: Option<f32>,
  /// set to true if the order is a FX conversion order 
  #[serde(rename = "isCcyConv")]
  is_ccy_conv: Option<bool>,
  /// set to true if you want to place a single group orders(OCA) 
  #[serde(rename = "isSingleGroup")]
  is_single_group: Option<bool>,
  /// listingExchange is optional. By default we use \"SMART\" routing. Possible values are available via this end point: /v1/portal/iserver/contract/{conid}/info, see valid_exchange: e.g: SMART,AMEX,NYSE, CBOE,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JE FFALGO,BYX,IEX,FOXRIVER,TPLUS1,NYSENAT,PSX 
  #[serde(rename = "listingExchange")]
  listing_exchange: Option<String>,
  /// The order-type determines what type of order you want to send. LMT - A limit order is an order to buy or sell at the specified price or better. MKT - A market order is an order to buy or sell at the markets current NBBO. STP - A stop order becomes a market order once the specified stop price is attained or penetrated. STOP_LIMIT - A stop limit order becomes a limit order once the specified stop price is attained or penetrated. MIDPRICE - A MidPrice order attempts to fill at the current midpoint of the NBBO or better. 
  #[serde(rename = "orderType")]
  order_type: Option<String>,
  /// set to true if the order can be executed outside regular trading hours. 
  #[serde(rename = "outsideRTH")]
  outside_rth: Option<bool>,
  /// Only specify for child orders when placing bracket orders. The parentId for the child order(s) must be equal to the cOId (customer order id) of the parent. 
  #[serde(rename = "parentId")]
  parent_id: Option<String>,
  /// optional if order is LMT, or STOP_LIMIT, this is the limit price. For STP this is the stop price. For MIDPRICE this is the option price cap. 
  #[serde(rename = "price")]
  price: Option<f32>,
  /// usually integer, for some special cases can be float numbers
  #[serde(rename = "quantity")]
  quantity: Option<f32>,
  /// Custom order reference 
  #[serde(rename = "referrer")]
  referrer: Option<String>,
  /// The contract-identifier (conid) and security type (type) specified as a concatenated value, conid:type
  #[serde(rename = "secType")]
  sec_type: Option<String>,
  /// SELL or BUY
  #[serde(rename = "side")]
  side: Option<String>,
  /// Specify which IB Algo algorithm to use for this order. 
  #[serde(rename = "strategy")]
  strategy: Option<String>,
  /// The IB Algo parameters for the specified algorithm. 
  #[serde(rename = "strategyParameters")]
  strategy_parameters: Option<Value>,
  /// This is the  underlying symbol for the contract. 
  #[serde(rename = "ticker")]
  ticker: Option<String>,
  /// The Time-In-Force determines how long the order remains active on the market.   * GTC - use Good-Till-Cancel for orders to remain active until it executes or cancelled.   * OPG - use Open-Price-Guarantee for Limit-On-Open (LOO) or Market-On-Open (MOO) orders.   * DAY - if not executed a Day order will automatically cancel at the end of the markets regular trading hours.   * IOC - any portion of an Immediate-or-Cancel order that is not filled as soon as it becomes available in the market is cancelled. 
  #[serde(rename = "tif")]
  tif: Option<String>,
  /// If true, the system will use the Price Management Algo to submit the order. https://www.interactivebrokers.com/en/index.php?f=43423 
  #[serde(rename = "useAdaptive")]
  use_adaptive: Option<bool>
}

impl OrderRequest {
  pub fn new() -> OrderRequest {
    OrderRequest {
      acct_id: None,
      allocation_method: None,
      aux_price: None,
      c_oid: None,
      conid: None,
      fx_qty: None,
      is_ccy_conv: None,
      is_single_group: None,
      listing_exchange: None,
      order_type: None,
      outside_rth: None,
      parent_id: None,
      price: None,
      quantity: None,
      referrer: None,
      sec_type: None,
      side: None,
      strategy: None,
      strategy_parameters: None,
      ticker: None,
      tif: None,
      use_adaptive: None
    }
  }

  pub fn set_acct_id(&mut self, acct_id: String) {
    self.acct_id = Some(acct_id);
  }

  pub fn with_acct_id(mut self, acct_id: String) -> OrderRequest {
    self.acct_id = Some(acct_id);
    self
  }

  pub fn acct_id(&self) -> Option<&String> {
    self.acct_id.as_ref()
  }

  pub fn reset_acct_id(&mut self) {
    self.acct_id = None;
  }

  pub fn set_allocation_method(&mut self, allocation_method: String) {
    self.allocation_method = Some(allocation_method);
  }

  pub fn with_allocation_method(mut self, allocation_method: String) -> OrderRequest {
    self.allocation_method = Some(allocation_method);
    self
  }

  pub fn allocation_method(&self) -> Option<&String> {
    self.allocation_method.as_ref()
  }

  pub fn reset_allocation_method(&mut self) {
    self.allocation_method = None;
  }

  pub fn set_aux_price(&mut self, aux_price: Value) {
    self.aux_price = Some(aux_price);
  }

  pub fn with_aux_price(mut self, aux_price: Value) -> OrderRequest {
    self.aux_price = Some(aux_price);
    self
  }

  pub fn aux_price(&self) -> Option<&Value> {
    self.aux_price.as_ref()
  }

  pub fn reset_aux_price(&mut self) {
    self.aux_price = None;
  }

  pub fn set_c_oid(&mut self, c_oid: String) {
    self.c_oid = Some(c_oid);
  }

  pub fn with_c_oid(mut self, c_oid: String) -> OrderRequest {
    self.c_oid = Some(c_oid);
    self
  }

  pub fn c_oid(&self) -> Option<&String> {
    self.c_oid.as_ref()
  }

  pub fn reset_c_oid(&mut self) {
    self.c_oid = None;
  }

  pub fn set_conid(&mut self, conid: i32) {
    self.conid = Some(conid);
  }

  pub fn with_conid(mut self, conid: i32) -> OrderRequest {
    self.conid = Some(conid);
    self
  }

  pub fn conid(&self) -> Option<&i32> {
    self.conid.as_ref()
  }

  pub fn reset_conid(&mut self) {
    self.conid = None;
  }

  pub fn set_fx_qty(&mut self, fx_qty: f32) {
    self.fx_qty = Some(fx_qty);
  }

  pub fn with_fx_qty(mut self, fx_qty: f32) -> OrderRequest {
    self.fx_qty = Some(fx_qty);
    self
  }

  pub fn fx_qty(&self) -> Option<&f32> {
    self.fx_qty.as_ref()
  }

  pub fn reset_fx_qty(&mut self) {
    self.fx_qty = None;
  }

  pub fn set_is_ccy_conv(&mut self, is_ccy_conv: bool) {
    self.is_ccy_conv = Some(is_ccy_conv);
  }

  pub fn with_is_ccy_conv(mut self, is_ccy_conv: bool) -> OrderRequest {
    self.is_ccy_conv = Some(is_ccy_conv);
    self
  }

  pub fn is_ccy_conv(&self) -> Option<&bool> {
    self.is_ccy_conv.as_ref()
  }

  pub fn reset_is_ccy_conv(&mut self) {
    self.is_ccy_conv = None;
  }

  pub fn set_is_single_group(&mut self, is_single_group: bool) {
    self.is_single_group = Some(is_single_group);
  }

  pub fn with_is_single_group(mut self, is_single_group: bool) -> OrderRequest {
    self.is_single_group = Some(is_single_group);
    self
  }

  pub fn is_single_group(&self) -> Option<&bool> {
    self.is_single_group.as_ref()
  }

  pub fn reset_is_single_group(&mut self) {
    self.is_single_group = None;
  }

  pub fn set_listing_exchange(&mut self, listing_exchange: String) {
    self.listing_exchange = Some(listing_exchange);
  }

  pub fn with_listing_exchange(mut self, listing_exchange: String) -> OrderRequest {
    self.listing_exchange = Some(listing_exchange);
    self
  }

  pub fn listing_exchange(&self) -> Option<&String> {
    self.listing_exchange.as_ref()
  }

  pub fn reset_listing_exchange(&mut self) {
    self.listing_exchange = None;
  }

  pub fn set_order_type(&mut self, order_type: String) {
    self.order_type = Some(order_type);
  }

  pub fn with_order_type(mut self, order_type: String) -> OrderRequest {
    self.order_type = Some(order_type);
    self
  }

  pub fn order_type(&self) -> Option<&String> {
    self.order_type.as_ref()
  }

  pub fn reset_order_type(&mut self) {
    self.order_type = None;
  }

  pub fn set_outside_rth(&mut self, outside_rth: bool) {
    self.outside_rth = Some(outside_rth);
  }

  pub fn with_outside_rth(mut self, outside_rth: bool) -> OrderRequest {
    self.outside_rth = Some(outside_rth);
    self
  }

  pub fn outside_rth(&self) -> Option<&bool> {
    self.outside_rth.as_ref()
  }

  pub fn reset_outside_rth(&mut self) {
    self.outside_rth = None;
  }

  pub fn set_parent_id(&mut self, parent_id: String) {
    self.parent_id = Some(parent_id);
  }

  pub fn with_parent_id(mut self, parent_id: String) -> OrderRequest {
    self.parent_id = Some(parent_id);
    self
  }

  pub fn parent_id(&self) -> Option<&String> {
    self.parent_id.as_ref()
  }

  pub fn reset_parent_id(&mut self) {
    self.parent_id = None;
  }

  pub fn set_price(&mut self, price: f32) {
    self.price = Some(price);
  }

  pub fn with_price(mut self, price: f32) -> OrderRequest {
    self.price = Some(price);
    self
  }

  pub fn price(&self) -> Option<&f32> {
    self.price.as_ref()
  }

  pub fn reset_price(&mut self) {
    self.price = None;
  }

  pub fn set_quantity(&mut self, quantity: f32) {
    self.quantity = Some(quantity);
  }

  pub fn with_quantity(mut self, quantity: f32) -> OrderRequest {
    self.quantity = Some(quantity);
    self
  }

  pub fn quantity(&self) -> Option<&f32> {
    self.quantity.as_ref()
  }

  pub fn reset_quantity(&mut self) {
    self.quantity = None;
  }

  pub fn set_referrer(&mut self, referrer: String) {
    self.referrer = Some(referrer);
  }

  pub fn with_referrer(mut self, referrer: String) -> OrderRequest {
    self.referrer = Some(referrer);
    self
  }

  pub fn referrer(&self) -> Option<&String> {
    self.referrer.as_ref()
  }

  pub fn reset_referrer(&mut self) {
    self.referrer = None;
  }

  pub fn set_sec_type(&mut self, sec_type: String) {
    self.sec_type = Some(sec_type);
  }

  pub fn with_sec_type(mut self, sec_type: String) -> OrderRequest {
    self.sec_type = Some(sec_type);
    self
  }

  pub fn sec_type(&self) -> Option<&String> {
    self.sec_type.as_ref()
  }

  pub fn reset_sec_type(&mut self) {
    self.sec_type = None;
  }

  pub fn set_side(&mut self, side: String) {
    self.side = Some(side);
  }

  pub fn with_side(mut self, side: String) -> OrderRequest {
    self.side = Some(side);
    self
  }

  pub fn side(&self) -> Option<&String> {
    self.side.as_ref()
  }

  pub fn reset_side(&mut self) {
    self.side = None;
  }

  pub fn set_strategy(&mut self, strategy: String) {
    self.strategy = Some(strategy);
  }

  pub fn with_strategy(mut self, strategy: String) -> OrderRequest {
    self.strategy = Some(strategy);
    self
  }

  pub fn strategy(&self) -> Option<&String> {
    self.strategy.as_ref()
  }

  pub fn reset_strategy(&mut self) {
    self.strategy = None;
  }

  pub fn set_strategy_parameters(&mut self, strategy_parameters: Value) {
    self.strategy_parameters = Some(strategy_parameters);
  }

  pub fn with_strategy_parameters(mut self, strategy_parameters: Value) -> OrderRequest {
    self.strategy_parameters = Some(strategy_parameters);
    self
  }

  pub fn strategy_parameters(&self) -> Option<&Value> {
    self.strategy_parameters.as_ref()
  }

  pub fn reset_strategy_parameters(&mut self) {
    self.strategy_parameters = None;
  }

  pub fn set_ticker(&mut self, ticker: String) {
    self.ticker = Some(ticker);
  }

  pub fn with_ticker(mut self, ticker: String) -> OrderRequest {
    self.ticker = Some(ticker);
    self
  }

  pub fn ticker(&self) -> Option<&String> {
    self.ticker.as_ref()
  }

  pub fn reset_ticker(&mut self) {
    self.ticker = None;
  }

  pub fn set_tif(&mut self, tif: String) {
    self.tif = Some(tif);
  }

  pub fn with_tif(mut self, tif: String) -> OrderRequest {
    self.tif = Some(tif);
    self
  }

  pub fn tif(&self) -> Option<&String> {
    self.tif.as_ref()
  }

  pub fn reset_tif(&mut self) {
    self.tif = None;
  }

  pub fn set_use_adaptive(&mut self, use_adaptive: bool) {
    self.use_adaptive = Some(use_adaptive);
  }

  pub fn with_use_adaptive(mut self, use_adaptive: bool) -> OrderRequest {
    self.use_adaptive = Some(use_adaptive);
    self
  }

  pub fn use_adaptive(&self) -> Option<&bool> {
    self.use_adaptive.as_ref()
  }

  pub fn reset_use_adaptive(&mut self) {
    self.use_adaptive = None;
  }

}