Skip to main content

oanda_client/models/
order.rs

1//! OANDA v20 order definitions.
2// Shared imports vary by definition family; unused ones are deliberately allowed.
3#[allow(unused_imports)]
4use super::*;
5#[allow(unused_imports)]
6use crate::ids::*;
7#[allow(unused_imports)]
8use crate::timestamp::Timestamp;
9#[allow(unused_imports)]
10use rust_decimal::Decimal;
11#[allow(unused_imports)]
12use serde::{Deserialize, Serialize};
13
14/// A MarketOrder is an order that is filled immediately upon creation using the current market price.
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct MarketOrder {
18    /// The Order’s identifier, unique within the Order’s Account.
19    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
20    pub id: Option<OrderID>,
21    /// The time when the Order was created.
22    #[serde(
23        rename = "createTime",
24        default,
25        skip_serializing_if = "Option::is_none"
26    )]
27    pub create_time: Option<Timestamp>,
28    /// The current state of the Order.
29    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
30    pub state: Option<OrderState>,
31    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
32    /// associated with MT4.
33    #[serde(
34        rename = "clientExtensions",
35        default,
36        skip_serializing_if = "Option::is_none"
37    )]
38    pub client_extensions: Option<ClientExtensions>,
39    /// The type of the Order. Always set to “MARKET” for Market Orders.
40    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
41    pub r#type: Option<OrderType>,
42    /// The Market Order’s Instrument.
43    #[serde(rename = "instrument")]
44    pub instrument: InstrumentName,
45    /// The quantity requested to be filled by the Market Order. A positive number of units results in a long
46    /// Order, and a negative number of units results in a short Order.
47    #[serde(rename = "units")]
48    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
49    pub units: Decimal,
50    /// The time-in-force requested for the Market Order. Restricted to FOK or IOC for a MarketOrder.
51    #[serde(rename = "timeInForce")]
52    pub time_in_force: TimeInForce,
53    /// The worst price that the client is willing to have the Market Order filled at.
54    #[serde(
55        rename = "priceBound",
56        default,
57        skip_serializing_if = "Option::is_none"
58    )]
59    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
60    pub price_bound: Option<Decimal>,
61    /// Specification of how Positions in the Account are modified when the Order is filled.
62    #[serde(rename = "positionFill")]
63    pub position_fill: OrderPositionFill,
64    /// Details of the Trade requested to be closed, only provided when the Market Order is being used to
65    /// explicitly close a Trade.
66    #[serde(
67        rename = "tradeClose",
68        default,
69        skip_serializing_if = "Option::is_none"
70    )]
71    pub trade_close: Option<MarketOrderTradeClose>,
72    /// Details of the long Position requested to be closed out, only provided when a Market Order is being used
73    /// to explicitly closeout a long Position.
74    #[serde(
75        rename = "longPositionCloseout",
76        default,
77        skip_serializing_if = "Option::is_none"
78    )]
79    pub long_position_closeout: Option<MarketOrderPositionCloseout>,
80    /// Details of the short Position requested to be closed out, only provided when a Market Order is being
81    /// used to explicitly closeout a short Position.
82    #[serde(
83        rename = "shortPositionCloseout",
84        default,
85        skip_serializing_if = "Option::is_none"
86    )]
87    pub short_position_closeout: Option<MarketOrderPositionCloseout>,
88    /// Details of the Margin Closeout that this Market Order was created for
89    #[serde(
90        rename = "marginCloseout",
91        default,
92        skip_serializing_if = "Option::is_none"
93    )]
94    pub margin_closeout: Option<MarketOrderMarginCloseout>,
95    /// Details of the delayed Trade close that this Market Order was created for
96    #[serde(
97        rename = "delayedTradeClose",
98        default,
99        skip_serializing_if = "Option::is_none"
100    )]
101    pub delayed_trade_close: Option<MarketOrderDelayedTradeClose>,
102    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
103    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
104    /// dependent Take Profit Order is modified directly through the Trade.
105    #[serde(
106        rename = "takeProfitOnFill",
107        default,
108        skip_serializing_if = "Option::is_none"
109    )]
110    pub take_profit_on_fill: Option<TakeProfitDetails>,
111    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
112    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
113    /// Stop Loss Order is modified directly through the Trade.
114    #[serde(
115        rename = "stopLossOnFill",
116        default,
117        skip_serializing_if = "Option::is_none"
118    )]
119    pub stop_loss_on_fill: Option<StopLossDetails>,
120    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
121    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
122    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
123    #[serde(
124        rename = "guaranteedStopLossOnFill",
125        default,
126        skip_serializing_if = "Option::is_none"
127    )]
128    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
129    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
130    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
131    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
132    #[serde(
133        rename = "trailingStopLossOnFill",
134        default,
135        skip_serializing_if = "Option::is_none"
136    )]
137    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
138    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
139    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
140    #[serde(
141        rename = "tradeClientExtensions",
142        default,
143        skip_serializing_if = "Option::is_none"
144    )]
145    pub trade_client_extensions: Option<ClientExtensions>,
146    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
147    #[serde(
148        rename = "fillingTransactionID",
149        default,
150        skip_serializing_if = "Option::is_none"
151    )]
152    pub filling_transaction_id: Option<TransactionID>,
153    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
154    #[serde(
155        rename = "filledTime",
156        default,
157        skip_serializing_if = "Option::is_none"
158    )]
159    pub filled_time: Option<Timestamp>,
160    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
161    /// Trade was opened as a result of the fill)
162    #[serde(
163        rename = "tradeOpenedID",
164        default,
165        skip_serializing_if = "Option::is_none"
166    )]
167    pub trade_opened_id: Option<TradeID>,
168    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
169    /// a Trade was reduced as a result of the fill)
170    #[serde(
171        rename = "tradeReducedID",
172        default,
173        skip_serializing_if = "Option::is_none"
174    )]
175    pub trade_reduced_id: Option<TradeID>,
176    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
177    /// one or more Trades were closed as a result of the fill)
178    #[serde(
179        rename = "tradeClosedIDs",
180        default,
181        skip_serializing_if = "Option::is_none"
182    )]
183    pub trade_closed_ids: Option<Vec<TradeID>>,
184    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
185    #[serde(
186        rename = "cancellingTransactionID",
187        default,
188        skip_serializing_if = "Option::is_none"
189    )]
190    pub cancelling_transaction_id: Option<TransactionID>,
191    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
192    #[serde(
193        rename = "cancelledTime",
194        default,
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub cancelled_time: Option<Timestamp>,
198}
199
200/// A FixedPriceOrder is an order that is filled immediately upon creation using a fixed price.
201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
202#[serde(rename_all = "camelCase")]
203pub struct FixedPriceOrder {
204    /// The Order’s identifier, unique within the Order’s Account.
205    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
206    pub id: Option<OrderID>,
207    /// The time when the Order was created.
208    #[serde(
209        rename = "createTime",
210        default,
211        skip_serializing_if = "Option::is_none"
212    )]
213    pub create_time: Option<Timestamp>,
214    /// The current state of the Order.
215    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
216    pub state: Option<OrderState>,
217    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
218    /// associated with MT4.
219    #[serde(
220        rename = "clientExtensions",
221        default,
222        skip_serializing_if = "Option::is_none"
223    )]
224    pub client_extensions: Option<ClientExtensions>,
225    /// The type of the Order. Always set to “FIXED_PRICE” for Fixed Price Orders.
226    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
227    pub r#type: Option<OrderType>,
228    /// The Fixed Price Order’s Instrument.
229    #[serde(rename = "instrument")]
230    pub instrument: InstrumentName,
231    /// The quantity requested to be filled by the Fixed Price Order. A positive number of units results in a
232    /// long Order, and a negative number of units results in a short Order.
233    #[serde(rename = "units")]
234    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
235    pub units: Decimal,
236    /// The price specified for the Fixed Price Order. This price is the exact price that the Fixed Price Order
237    /// will be filled at.
238    #[serde(rename = "price")]
239    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
240    pub price: Decimal,
241    /// Specification of how Positions in the Account are modified when the Order is filled.
242    #[serde(rename = "positionFill")]
243    pub position_fill: OrderPositionFill,
244    /// The state that the trade resulting from the Fixed Price Order should be set to.
245    #[serde(rename = "tradeState")]
246    pub trade_state: String,
247    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
248    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
249    /// dependent Take Profit Order is modified directly through the Trade.
250    #[serde(
251        rename = "takeProfitOnFill",
252        default,
253        skip_serializing_if = "Option::is_none"
254    )]
255    pub take_profit_on_fill: Option<TakeProfitDetails>,
256    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
257    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
258    /// Stop Loss Order is modified directly through the Trade.
259    #[serde(
260        rename = "stopLossOnFill",
261        default,
262        skip_serializing_if = "Option::is_none"
263    )]
264    pub stop_loss_on_fill: Option<StopLossDetails>,
265    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
266    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
267    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
268    #[serde(
269        rename = "guaranteedStopLossOnFill",
270        default,
271        skip_serializing_if = "Option::is_none"
272    )]
273    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
274    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
275    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
276    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
277    #[serde(
278        rename = "trailingStopLossOnFill",
279        default,
280        skip_serializing_if = "Option::is_none"
281    )]
282    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
283    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
284    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
285    #[serde(
286        rename = "tradeClientExtensions",
287        default,
288        skip_serializing_if = "Option::is_none"
289    )]
290    pub trade_client_extensions: Option<ClientExtensions>,
291    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
292    #[serde(
293        rename = "fillingTransactionID",
294        default,
295        skip_serializing_if = "Option::is_none"
296    )]
297    pub filling_transaction_id: Option<TransactionID>,
298    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
299    #[serde(
300        rename = "filledTime",
301        default,
302        skip_serializing_if = "Option::is_none"
303    )]
304    pub filled_time: Option<Timestamp>,
305    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
306    /// Trade was opened as a result of the fill)
307    #[serde(
308        rename = "tradeOpenedID",
309        default,
310        skip_serializing_if = "Option::is_none"
311    )]
312    pub trade_opened_id: Option<TradeID>,
313    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
314    /// a Trade was reduced as a result of the fill)
315    #[serde(
316        rename = "tradeReducedID",
317        default,
318        skip_serializing_if = "Option::is_none"
319    )]
320    pub trade_reduced_id: Option<TradeID>,
321    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
322    /// one or more Trades were closed as a result of the fill)
323    #[serde(
324        rename = "tradeClosedIDs",
325        default,
326        skip_serializing_if = "Option::is_none"
327    )]
328    pub trade_closed_ids: Option<Vec<TradeID>>,
329    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
330    #[serde(
331        rename = "cancellingTransactionID",
332        default,
333        skip_serializing_if = "Option::is_none"
334    )]
335    pub cancelling_transaction_id: Option<TransactionID>,
336    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
337    #[serde(
338        rename = "cancelledTime",
339        default,
340        skip_serializing_if = "Option::is_none"
341    )]
342    pub cancelled_time: Option<Timestamp>,
343}
344
345/// A LimitOrder is an order that is created with a price threshold, and will only be filled by a price that
346/// is equal to or better than the threshold.
347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
348#[serde(rename_all = "camelCase")]
349pub struct LimitOrder {
350    /// The Order’s identifier, unique within the Order’s Account.
351    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
352    pub id: Option<OrderID>,
353    /// The time when the Order was created.
354    #[serde(
355        rename = "createTime",
356        default,
357        skip_serializing_if = "Option::is_none"
358    )]
359    pub create_time: Option<Timestamp>,
360    /// The current state of the Order.
361    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
362    pub state: Option<OrderState>,
363    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
364    /// associated with MT4.
365    #[serde(
366        rename = "clientExtensions",
367        default,
368        skip_serializing_if = "Option::is_none"
369    )]
370    pub client_extensions: Option<ClientExtensions>,
371    /// The type of the Order. Always set to “LIMIT” for Limit Orders.
372    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
373    pub r#type: Option<OrderType>,
374    /// The Limit Order’s Instrument.
375    #[serde(rename = "instrument")]
376    pub instrument: InstrumentName,
377    /// The quantity requested to be filled by the Limit Order. A positive number of units results in a long
378    /// Order, and a negative number of units results in a short Order.
379    #[serde(rename = "units")]
380    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
381    pub units: Decimal,
382    /// The price threshold specified for the Limit Order. The Limit Order will only be filled by a market price
383    /// that is equal to or better than this price.
384    #[serde(rename = "price")]
385    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
386    pub price: Decimal,
387    /// The time-in-force requested for the Limit Order.
388    #[serde(rename = "timeInForce")]
389    pub time_in_force: TimeInForce,
390    /// The date/time when the Limit Order will be cancelled if its timeInForce is “GTD”.
391    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
392    pub gtd_time: Option<Timestamp>,
393    /// Specification of how Positions in the Account are modified when the Order is filled.
394    #[serde(rename = "positionFill")]
395    pub position_fill: OrderPositionFill,
396    /// Specification of which price component should be used when determining if an Order should be triggered
397    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
398    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
399    /// filled using their default price component. This feature is only provided through the REST API. Clients
400    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
401    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
402    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
403    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
404    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
405    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
406    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
407    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
408    #[serde(rename = "triggerCondition")]
409    pub trigger_condition: OrderTriggerCondition,
410    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
411    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
412    /// dependent Take Profit Order is modified directly through the Trade.
413    #[serde(
414        rename = "takeProfitOnFill",
415        default,
416        skip_serializing_if = "Option::is_none"
417    )]
418    pub take_profit_on_fill: Option<TakeProfitDetails>,
419    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
420    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
421    /// Stop Loss Order is modified directly through the Trade.
422    #[serde(
423        rename = "stopLossOnFill",
424        default,
425        skip_serializing_if = "Option::is_none"
426    )]
427    pub stop_loss_on_fill: Option<StopLossDetails>,
428    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
429    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
430    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
431    #[serde(
432        rename = "guaranteedStopLossOnFill",
433        default,
434        skip_serializing_if = "Option::is_none"
435    )]
436    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
437    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
438    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
439    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
440    #[serde(
441        rename = "trailingStopLossOnFill",
442        default,
443        skip_serializing_if = "Option::is_none"
444    )]
445    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
446    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
447    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
448    #[serde(
449        rename = "tradeClientExtensions",
450        default,
451        skip_serializing_if = "Option::is_none"
452    )]
453    pub trade_client_extensions: Option<ClientExtensions>,
454    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
455    #[serde(
456        rename = "fillingTransactionID",
457        default,
458        skip_serializing_if = "Option::is_none"
459    )]
460    pub filling_transaction_id: Option<TransactionID>,
461    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
462    #[serde(
463        rename = "filledTime",
464        default,
465        skip_serializing_if = "Option::is_none"
466    )]
467    pub filled_time: Option<Timestamp>,
468    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
469    /// Trade was opened as a result of the fill)
470    #[serde(
471        rename = "tradeOpenedID",
472        default,
473        skip_serializing_if = "Option::is_none"
474    )]
475    pub trade_opened_id: Option<TradeID>,
476    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
477    /// a Trade was reduced as a result of the fill)
478    #[serde(
479        rename = "tradeReducedID",
480        default,
481        skip_serializing_if = "Option::is_none"
482    )]
483    pub trade_reduced_id: Option<TradeID>,
484    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
485    /// one or more Trades were closed as a result of the fill)
486    #[serde(
487        rename = "tradeClosedIDs",
488        default,
489        skip_serializing_if = "Option::is_none"
490    )]
491    pub trade_closed_ids: Option<Vec<TradeID>>,
492    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
493    #[serde(
494        rename = "cancellingTransactionID",
495        default,
496        skip_serializing_if = "Option::is_none"
497    )]
498    pub cancelling_transaction_id: Option<TransactionID>,
499    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
500    #[serde(
501        rename = "cancelledTime",
502        default,
503        skip_serializing_if = "Option::is_none"
504    )]
505    pub cancelled_time: Option<Timestamp>,
506    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
507    /// a cancel/replace).
508    #[serde(
509        rename = "replacesOrderID",
510        default,
511        skip_serializing_if = "Option::is_none"
512    )]
513    pub replaces_order_id: Option<OrderID>,
514    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
515    /// cancel/replace).
516    #[serde(
517        rename = "replacedByOrderID",
518        default,
519        skip_serializing_if = "Option::is_none"
520    )]
521    pub replaced_by_order_id: Option<OrderID>,
522}
523
524/// A StopOrder is an order that is created with a price threshold, and will only be filled by a price that
525/// is equal to or worse than the threshold.
526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
527#[serde(rename_all = "camelCase")]
528pub struct StopOrder {
529    /// The Order’s identifier, unique within the Order’s Account.
530    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
531    pub id: Option<OrderID>,
532    /// The time when the Order was created.
533    #[serde(
534        rename = "createTime",
535        default,
536        skip_serializing_if = "Option::is_none"
537    )]
538    pub create_time: Option<Timestamp>,
539    /// The current state of the Order.
540    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
541    pub state: Option<OrderState>,
542    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
543    /// associated with MT4.
544    #[serde(
545        rename = "clientExtensions",
546        default,
547        skip_serializing_if = "Option::is_none"
548    )]
549    pub client_extensions: Option<ClientExtensions>,
550    /// The type of the Order. Always set to “STOP” for Stop Orders.
551    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
552    pub r#type: Option<OrderType>,
553    /// The Stop Order’s Instrument.
554    #[serde(rename = "instrument")]
555    pub instrument: InstrumentName,
556    /// The quantity requested to be filled by the Stop Order. A positive number of units results in a long
557    /// Order, and a negative number of units results in a short Order.
558    #[serde(rename = "units")]
559    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
560    pub units: Decimal,
561    /// The price threshold specified for the Stop Order. The Stop Order will only be filled by a market price
562    /// that is equal to or worse than this price.
563    #[serde(rename = "price")]
564    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
565    pub price: Decimal,
566    /// The worst market price that may be used to fill this Stop Order. If the market gaps and crosses through
567    /// both the price and the priceBound, the Stop Order will be cancelled instead of being filled.
568    #[serde(
569        rename = "priceBound",
570        default,
571        skip_serializing_if = "Option::is_none"
572    )]
573    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
574    pub price_bound: Option<Decimal>,
575    /// The time-in-force requested for the Stop Order.
576    #[serde(rename = "timeInForce")]
577    pub time_in_force: TimeInForce,
578    /// The date/time when the Stop Order will be cancelled if its timeInForce is “GTD”.
579    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
580    pub gtd_time: Option<Timestamp>,
581    /// Specification of how Positions in the Account are modified when the Order is filled.
582    #[serde(rename = "positionFill")]
583    pub position_fill: OrderPositionFill,
584    /// Specification of which price component should be used when determining if an Order should be triggered
585    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
586    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
587    /// filled using their default price component. This feature is only provided through the REST API. Clients
588    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
589    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
590    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
591    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
592    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
593    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
594    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
595    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
596    #[serde(rename = "triggerCondition")]
597    pub trigger_condition: OrderTriggerCondition,
598    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
599    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
600    /// dependent Take Profit Order is modified directly through the Trade.
601    #[serde(
602        rename = "takeProfitOnFill",
603        default,
604        skip_serializing_if = "Option::is_none"
605    )]
606    pub take_profit_on_fill: Option<TakeProfitDetails>,
607    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
608    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
609    /// Stop Loss Order is modified directly through the Trade.
610    #[serde(
611        rename = "stopLossOnFill",
612        default,
613        skip_serializing_if = "Option::is_none"
614    )]
615    pub stop_loss_on_fill: Option<StopLossDetails>,
616    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
617    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
618    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
619    #[serde(
620        rename = "guaranteedStopLossOnFill",
621        default,
622        skip_serializing_if = "Option::is_none"
623    )]
624    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
625    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
626    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
627    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
628    #[serde(
629        rename = "trailingStopLossOnFill",
630        default,
631        skip_serializing_if = "Option::is_none"
632    )]
633    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
634    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
635    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
636    #[serde(
637        rename = "tradeClientExtensions",
638        default,
639        skip_serializing_if = "Option::is_none"
640    )]
641    pub trade_client_extensions: Option<ClientExtensions>,
642    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
643    #[serde(
644        rename = "fillingTransactionID",
645        default,
646        skip_serializing_if = "Option::is_none"
647    )]
648    pub filling_transaction_id: Option<TransactionID>,
649    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
650    #[serde(
651        rename = "filledTime",
652        default,
653        skip_serializing_if = "Option::is_none"
654    )]
655    pub filled_time: Option<Timestamp>,
656    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
657    /// Trade was opened as a result of the fill)
658    #[serde(
659        rename = "tradeOpenedID",
660        default,
661        skip_serializing_if = "Option::is_none"
662    )]
663    pub trade_opened_id: Option<TradeID>,
664    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
665    /// a Trade was reduced as a result of the fill)
666    #[serde(
667        rename = "tradeReducedID",
668        default,
669        skip_serializing_if = "Option::is_none"
670    )]
671    pub trade_reduced_id: Option<TradeID>,
672    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
673    /// one or more Trades were closed as a result of the fill)
674    #[serde(
675        rename = "tradeClosedIDs",
676        default,
677        skip_serializing_if = "Option::is_none"
678    )]
679    pub trade_closed_ids: Option<Vec<TradeID>>,
680    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
681    #[serde(
682        rename = "cancellingTransactionID",
683        default,
684        skip_serializing_if = "Option::is_none"
685    )]
686    pub cancelling_transaction_id: Option<TransactionID>,
687    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
688    #[serde(
689        rename = "cancelledTime",
690        default,
691        skip_serializing_if = "Option::is_none"
692    )]
693    pub cancelled_time: Option<Timestamp>,
694    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
695    /// a cancel/replace).
696    #[serde(
697        rename = "replacesOrderID",
698        default,
699        skip_serializing_if = "Option::is_none"
700    )]
701    pub replaces_order_id: Option<OrderID>,
702    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
703    /// cancel/replace).
704    #[serde(
705        rename = "replacedByOrderID",
706        default,
707        skip_serializing_if = "Option::is_none"
708    )]
709    pub replaced_by_order_id: Option<OrderID>,
710}
711
712/// A MarketIfTouchedOrder is an order that is created with a price threshold, and will only be filled by a
713/// market price that touches or crosses the threshold.
714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
715#[serde(rename_all = "camelCase")]
716pub struct MarketIfTouchedOrder {
717    /// The Order’s identifier, unique within the Order’s Account.
718    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
719    pub id: Option<OrderID>,
720    /// The time when the Order was created.
721    #[serde(
722        rename = "createTime",
723        default,
724        skip_serializing_if = "Option::is_none"
725    )]
726    pub create_time: Option<Timestamp>,
727    /// The current state of the Order.
728    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
729    pub state: Option<OrderState>,
730    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
731    /// associated with MT4.
732    #[serde(
733        rename = "clientExtensions",
734        default,
735        skip_serializing_if = "Option::is_none"
736    )]
737    pub client_extensions: Option<ClientExtensions>,
738    /// The type of the Order. Always set to “MARKET_IF_TOUCHED” for Market If Touched Orders.
739    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
740    pub r#type: Option<OrderType>,
741    /// The MarketIfTouched Order’s Instrument.
742    #[serde(rename = "instrument")]
743    pub instrument: InstrumentName,
744    /// The quantity requested to be filled by the MarketIfTouched Order. A positive number of units results in
745    /// a long Order, and a negative number of units results in a short Order.
746    #[serde(rename = "units")]
747    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
748    pub units: Decimal,
749    /// The price threshold specified for the MarketIfTouched Order. The MarketIfTouched Order will only be
750    /// filled by a market price that crosses this price from the direction of the market price at the time when
751    /// the Order was created (the initialMarketPrice). Depending on the value of the Order’s price and
752    /// initialMarketPrice, the MarketIfTouchedOrder will behave like a Limit or a Stop Order.
753    #[serde(rename = "price")]
754    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
755    pub price: Decimal,
756    /// The worst market price that may be used to fill this MarketIfTouched Order.
757    #[serde(
758        rename = "priceBound",
759        default,
760        skip_serializing_if = "Option::is_none"
761    )]
762    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
763    pub price_bound: Option<Decimal>,
764    /// The time-in-force requested for the MarketIfTouched Order. Restricted to “GTC”, “GFD” and “GTD” for
765    /// MarketIfTouched Orders.
766    #[serde(rename = "timeInForce")]
767    pub time_in_force: TimeInForce,
768    /// The date/time when the MarketIfTouched Order will be cancelled if its timeInForce is “GTD”.
769    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
770    pub gtd_time: Option<Timestamp>,
771    /// Specification of how Positions in the Account are modified when the Order is filled.
772    #[serde(rename = "positionFill")]
773    pub position_fill: OrderPositionFill,
774    /// Specification of which price component should be used when determining if an Order should be triggered
775    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
776    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
777    /// filled using their default price component. This feature is only provided through the REST API. Clients
778    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
779    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
780    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
781    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
782    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
783    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
784    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
785    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
786    #[serde(rename = "triggerCondition")]
787    pub trigger_condition: OrderTriggerCondition,
788    /// The Market price at the time when the MarketIfTouched Order was created.
789    #[serde(
790        rename = "initialMarketPrice",
791        default,
792        skip_serializing_if = "Option::is_none"
793    )]
794    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
795    pub initial_market_price: Option<Decimal>,
796    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
797    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
798    /// dependent Take Profit Order is modified directly through the Trade.
799    #[serde(
800        rename = "takeProfitOnFill",
801        default,
802        skip_serializing_if = "Option::is_none"
803    )]
804    pub take_profit_on_fill: Option<TakeProfitDetails>,
805    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
806    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
807    /// Stop Loss Order is modified directly through the Trade.
808    #[serde(
809        rename = "stopLossOnFill",
810        default,
811        skip_serializing_if = "Option::is_none"
812    )]
813    pub stop_loss_on_fill: Option<StopLossDetails>,
814    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
815    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
816    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
817    #[serde(
818        rename = "guaranteedStopLossOnFill",
819        default,
820        skip_serializing_if = "Option::is_none"
821    )]
822    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
823    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
824    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
825    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
826    #[serde(
827        rename = "trailingStopLossOnFill",
828        default,
829        skip_serializing_if = "Option::is_none"
830    )]
831    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
832    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
833    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
834    #[serde(
835        rename = "tradeClientExtensions",
836        default,
837        skip_serializing_if = "Option::is_none"
838    )]
839    pub trade_client_extensions: Option<ClientExtensions>,
840    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
841    #[serde(
842        rename = "fillingTransactionID",
843        default,
844        skip_serializing_if = "Option::is_none"
845    )]
846    pub filling_transaction_id: Option<TransactionID>,
847    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
848    #[serde(
849        rename = "filledTime",
850        default,
851        skip_serializing_if = "Option::is_none"
852    )]
853    pub filled_time: Option<Timestamp>,
854    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
855    /// Trade was opened as a result of the fill)
856    #[serde(
857        rename = "tradeOpenedID",
858        default,
859        skip_serializing_if = "Option::is_none"
860    )]
861    pub trade_opened_id: Option<TradeID>,
862    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
863    /// a Trade was reduced as a result of the fill)
864    #[serde(
865        rename = "tradeReducedID",
866        default,
867        skip_serializing_if = "Option::is_none"
868    )]
869    pub trade_reduced_id: Option<TradeID>,
870    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
871    /// one or more Trades were closed as a result of the fill)
872    #[serde(
873        rename = "tradeClosedIDs",
874        default,
875        skip_serializing_if = "Option::is_none"
876    )]
877    pub trade_closed_ids: Option<Vec<TradeID>>,
878    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
879    #[serde(
880        rename = "cancellingTransactionID",
881        default,
882        skip_serializing_if = "Option::is_none"
883    )]
884    pub cancelling_transaction_id: Option<TransactionID>,
885    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
886    #[serde(
887        rename = "cancelledTime",
888        default,
889        skip_serializing_if = "Option::is_none"
890    )]
891    pub cancelled_time: Option<Timestamp>,
892    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
893    /// a cancel/replace).
894    #[serde(
895        rename = "replacesOrderID",
896        default,
897        skip_serializing_if = "Option::is_none"
898    )]
899    pub replaces_order_id: Option<OrderID>,
900    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
901    /// cancel/replace).
902    #[serde(
903        rename = "replacedByOrderID",
904        default,
905        skip_serializing_if = "Option::is_none"
906    )]
907    pub replaced_by_order_id: Option<OrderID>,
908}
909
910/// A TakeProfitOrder is an order that is linked to an open Trade and created with a price threshold. The
911/// Order will be filled (closing the Trade) by the first price that is equal to or better than the
912/// threshold. A TakeProfitOrder cannot be used to open a new Position.
913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
914#[serde(rename_all = "camelCase")]
915pub struct TakeProfitOrder {
916    /// The Order’s identifier, unique within the Order’s Account.
917    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
918    pub id: Option<OrderID>,
919    /// The time when the Order was created.
920    #[serde(
921        rename = "createTime",
922        default,
923        skip_serializing_if = "Option::is_none"
924    )]
925    pub create_time: Option<Timestamp>,
926    /// The current state of the Order.
927    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
928    pub state: Option<OrderState>,
929    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
930    /// associated with MT4.
931    #[serde(
932        rename = "clientExtensions",
933        default,
934        skip_serializing_if = "Option::is_none"
935    )]
936    pub client_extensions: Option<ClientExtensions>,
937    /// The type of the Order. Always set to “TAKE_PROFIT” for Take Profit Orders.
938    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
939    pub r#type: Option<OrderType>,
940    /// The ID of the Trade to close when the price threshold is breached.
941    #[serde(rename = "tradeID")]
942    pub trade_id: TradeID,
943    /// The client ID of the Trade to be closed when the price threshold is breached.
944    #[serde(
945        rename = "clientTradeID",
946        default,
947        skip_serializing_if = "Option::is_none"
948    )]
949    pub client_trade_id: Option<ClientID>,
950    /// The price threshold specified for the TakeProfit Order. The associated Trade will be closed by a market
951    /// price that is equal to or better than this threshold.
952    #[serde(rename = "price")]
953    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
954    pub price: Decimal,
955    /// The time-in-force requested for the TakeProfit Order. Restricted to “GTC”, “GFD” and “GTD” for
956    /// TakeProfit Orders.
957    #[serde(rename = "timeInForce")]
958    pub time_in_force: TimeInForce,
959    /// The date/time when the TakeProfit Order will be cancelled if its timeInForce is “GTD”.
960    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
961    pub gtd_time: Option<Timestamp>,
962    /// Specification of which price component should be used when determining if an Order should be triggered
963    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
964    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
965    /// filled using their default price component. This feature is only provided through the REST API. Clients
966    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
967    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
968    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
969    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
970    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
971    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
972    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
973    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
974    #[serde(rename = "triggerCondition")]
975    pub trigger_condition: OrderTriggerCondition,
976    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
977    #[serde(
978        rename = "fillingTransactionID",
979        default,
980        skip_serializing_if = "Option::is_none"
981    )]
982    pub filling_transaction_id: Option<TransactionID>,
983    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
984    #[serde(
985        rename = "filledTime",
986        default,
987        skip_serializing_if = "Option::is_none"
988    )]
989    pub filled_time: Option<Timestamp>,
990    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
991    /// Trade was opened as a result of the fill)
992    #[serde(
993        rename = "tradeOpenedID",
994        default,
995        skip_serializing_if = "Option::is_none"
996    )]
997    pub trade_opened_id: Option<TradeID>,
998    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
999    /// a Trade was reduced as a result of the fill)
1000    #[serde(
1001        rename = "tradeReducedID",
1002        default,
1003        skip_serializing_if = "Option::is_none"
1004    )]
1005    pub trade_reduced_id: Option<TradeID>,
1006    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
1007    /// one or more Trades were closed as a result of the fill)
1008    #[serde(
1009        rename = "tradeClosedIDs",
1010        default,
1011        skip_serializing_if = "Option::is_none"
1012    )]
1013    pub trade_closed_ids: Option<Vec<TradeID>>,
1014    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
1015    #[serde(
1016        rename = "cancellingTransactionID",
1017        default,
1018        skip_serializing_if = "Option::is_none"
1019    )]
1020    pub cancelling_transaction_id: Option<TransactionID>,
1021    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
1022    #[serde(
1023        rename = "cancelledTime",
1024        default,
1025        skip_serializing_if = "Option::is_none"
1026    )]
1027    pub cancelled_time: Option<Timestamp>,
1028    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
1029    /// a cancel/replace).
1030    #[serde(
1031        rename = "replacesOrderID",
1032        default,
1033        skip_serializing_if = "Option::is_none"
1034    )]
1035    pub replaces_order_id: Option<OrderID>,
1036    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
1037    /// cancel/replace).
1038    #[serde(
1039        rename = "replacedByOrderID",
1040        default,
1041        skip_serializing_if = "Option::is_none"
1042    )]
1043    pub replaced_by_order_id: Option<OrderID>,
1044}
1045
1046/// A StopLossOrder is an order that is linked to an open Trade and created with a price threshold. The
1047/// Order will be filled (closing the Trade) by the first price that is equal to or worse than the
1048/// threshold. A StopLossOrder cannot be used to open a new Position.
1049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1050#[serde(rename_all = "camelCase")]
1051pub struct StopLossOrder {
1052    /// The Order’s identifier, unique within the Order’s Account.
1053    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
1054    pub id: Option<OrderID>,
1055    /// The time when the Order was created.
1056    #[serde(
1057        rename = "createTime",
1058        default,
1059        skip_serializing_if = "Option::is_none"
1060    )]
1061    pub create_time: Option<Timestamp>,
1062    /// The current state of the Order.
1063    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
1064    pub state: Option<OrderState>,
1065    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
1066    /// associated with MT4.
1067    #[serde(
1068        rename = "clientExtensions",
1069        default,
1070        skip_serializing_if = "Option::is_none"
1071    )]
1072    pub client_extensions: Option<ClientExtensions>,
1073    /// The type of the Order. Always set to “STOP_LOSS” for Stop Loss Orders.
1074    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1075    pub r#type: Option<OrderType>,
1076    /// The premium that will be charged if the Stop Loss Order is guaranteed and the Order is filled at the
1077    /// guaranteed price. It is in price units and is charged for each unit of the Trade. Deprecated: Will be
1078    /// removed in a future API update.
1079    #[serde(
1080        rename = "guaranteedExecutionPremium",
1081        default,
1082        skip_serializing_if = "Option::is_none"
1083    )]
1084    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1085    pub guaranteed_execution_premium: Option<Decimal>,
1086    /// The ID of the Trade to close when the price threshold is breached.
1087    #[serde(rename = "tradeID")]
1088    pub trade_id: TradeID,
1089    /// The client ID of the Trade to be closed when the price threshold is breached.
1090    #[serde(
1091        rename = "clientTradeID",
1092        default,
1093        skip_serializing_if = "Option::is_none"
1094    )]
1095    pub client_trade_id: Option<ClientID>,
1096    /// The price threshold specified for the Stop Loss Order. The associated Trade will be closed by a market
1097    /// price that is equal to or worse than this threshold.
1098    #[serde(rename = "price")]
1099    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1100    pub price: Decimal,
1101    /// Specifies the distance (in price units) from the Account’s current price to use as the Stop Loss Order
1102    /// price. If the Trade is short the Instrument’s bid price is used, and for long Trades the ask is used.
1103    #[serde(rename = "distance", default, skip_serializing_if = "Option::is_none")]
1104    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1105    pub distance: Option<Decimal>,
1106    /// The time-in-force requested for the StopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for StopLoss
1107    /// Orders.
1108    #[serde(rename = "timeInForce")]
1109    pub time_in_force: TimeInForce,
1110    /// The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
1111    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1112    pub gtd_time: Option<Timestamp>,
1113    /// Specification of which price component should be used when determining if an Order should be triggered
1114    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1115    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1116    /// filled using their default price component. This feature is only provided through the REST API. Clients
1117    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1118    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1119    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1120    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1121    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1122    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1123    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1124    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1125    #[serde(rename = "triggerCondition")]
1126    pub trigger_condition: OrderTriggerCondition,
1127    /// Flag indicating that the Stop Loss Order is guaranteed. The default value depends on the
1128    /// GuaranteedStopLossOrderMode of the account, if it is REQUIRED, the default will be true, for DISABLED or
1129    /// ENABLED the default is false. Deprecated: Will be removed in a future API update.
1130    #[serde(
1131        rename = "guaranteed",
1132        default,
1133        skip_serializing_if = "Option::is_none"
1134    )]
1135    pub guaranteed: Option<bool>,
1136    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
1137    #[serde(
1138        rename = "fillingTransactionID",
1139        default,
1140        skip_serializing_if = "Option::is_none"
1141    )]
1142    pub filling_transaction_id: Option<TransactionID>,
1143    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
1144    #[serde(
1145        rename = "filledTime",
1146        default,
1147        skip_serializing_if = "Option::is_none"
1148    )]
1149    pub filled_time: Option<Timestamp>,
1150    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
1151    /// Trade was opened as a result of the fill)
1152    #[serde(
1153        rename = "tradeOpenedID",
1154        default,
1155        skip_serializing_if = "Option::is_none"
1156    )]
1157    pub trade_opened_id: Option<TradeID>,
1158    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
1159    /// a Trade was reduced as a result of the fill)
1160    #[serde(
1161        rename = "tradeReducedID",
1162        default,
1163        skip_serializing_if = "Option::is_none"
1164    )]
1165    pub trade_reduced_id: Option<TradeID>,
1166    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
1167    /// one or more Trades were closed as a result of the fill)
1168    #[serde(
1169        rename = "tradeClosedIDs",
1170        default,
1171        skip_serializing_if = "Option::is_none"
1172    )]
1173    pub trade_closed_ids: Option<Vec<TradeID>>,
1174    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
1175    #[serde(
1176        rename = "cancellingTransactionID",
1177        default,
1178        skip_serializing_if = "Option::is_none"
1179    )]
1180    pub cancelling_transaction_id: Option<TransactionID>,
1181    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
1182    #[serde(
1183        rename = "cancelledTime",
1184        default,
1185        skip_serializing_if = "Option::is_none"
1186    )]
1187    pub cancelled_time: Option<Timestamp>,
1188    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
1189    /// a cancel/replace).
1190    #[serde(
1191        rename = "replacesOrderID",
1192        default,
1193        skip_serializing_if = "Option::is_none"
1194    )]
1195    pub replaces_order_id: Option<OrderID>,
1196    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
1197    /// cancel/replace).
1198    #[serde(
1199        rename = "replacedByOrderID",
1200        default,
1201        skip_serializing_if = "Option::is_none"
1202    )]
1203    pub replaced_by_order_id: Option<OrderID>,
1204}
1205
1206/// A GuaranteedStopLossOrder is an order that is linked to an open Trade and created with a price threshold
1207/// which is guaranteed against slippage that may occur as the market crosses the price set for that order.
1208/// The Order will be filled (closing the Trade) by the first price that is equal to or worse than the
1209/// threshold. The price level specified for the GuaranteedStopLossOrder must be at least the configured
1210/// minimum distance (in price units) away from the entry price for the traded instrument. A
1211/// GuaranteedStopLossOrder cannot be used to open a new Position.
1212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1213#[serde(rename_all = "camelCase")]
1214pub struct GuaranteedStopLossOrder {
1215    /// The Order’s identifier, unique within the Order’s Account.
1216    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
1217    pub id: Option<OrderID>,
1218    /// The time when the Order was created.
1219    #[serde(
1220        rename = "createTime",
1221        default,
1222        skip_serializing_if = "Option::is_none"
1223    )]
1224    pub create_time: Option<Timestamp>,
1225    /// The current state of the Order.
1226    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
1227    pub state: Option<OrderState>,
1228    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
1229    /// associated with MT4.
1230    #[serde(
1231        rename = "clientExtensions",
1232        default,
1233        skip_serializing_if = "Option::is_none"
1234    )]
1235    pub client_extensions: Option<ClientExtensions>,
1236    /// The type of the Order. Always set to “GUARANTEED_STOP_LOSS” for Guaranteed Stop Loss Orders.
1237    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1238    pub r#type: Option<OrderType>,
1239    /// The premium that will be charged if the Guaranteed Stop Loss Order is filled at the guaranteed price. It
1240    /// is in price units and is charged for each unit of the Trade.
1241    #[serde(
1242        rename = "guaranteedExecutionPremium",
1243        default,
1244        skip_serializing_if = "Option::is_none"
1245    )]
1246    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1247    pub guaranteed_execution_premium: Option<Decimal>,
1248    /// The ID of the Trade to close when the price threshold is breached.
1249    #[serde(rename = "tradeID")]
1250    pub trade_id: TradeID,
1251    /// The client ID of the Trade to be closed when the price threshold is breached.
1252    #[serde(
1253        rename = "clientTradeID",
1254        default,
1255        skip_serializing_if = "Option::is_none"
1256    )]
1257    pub client_trade_id: Option<ClientID>,
1258    /// The price threshold specified for the Guaranteed Stop Loss Order. The associated Trade will be closed at
1259    /// this price.
1260    #[serde(rename = "price")]
1261    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1262    pub price: Decimal,
1263    /// Specifies the distance (in price units) from the Account’s current price to use as the Guaranteed Stop
1264    /// Loss Order price. If the Trade is short the Instrument’s bid price is used, and for long Trades the ask
1265    /// is used.
1266    #[serde(rename = "distance", default, skip_serializing_if = "Option::is_none")]
1267    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1268    pub distance: Option<Decimal>,
1269    /// The time-in-force requested for the GuaranteedStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for
1270    /// GuaranteedStopLoss Orders.
1271    #[serde(rename = "timeInForce")]
1272    pub time_in_force: TimeInForce,
1273    /// The date/time when the GuaranteedStopLoss Order will be cancelled if its timeInForce is “GTD”.
1274    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1275    pub gtd_time: Option<Timestamp>,
1276    /// Specification of which price component should be used when determining if an Order should be triggered
1277    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1278    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1279    /// filled using their default price component. This feature is only provided through the REST API. Clients
1280    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1281    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1282    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1283    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1284    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1285    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1286    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1287    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1288    #[serde(rename = "triggerCondition")]
1289    pub trigger_condition: OrderTriggerCondition,
1290    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
1291    #[serde(
1292        rename = "fillingTransactionID",
1293        default,
1294        skip_serializing_if = "Option::is_none"
1295    )]
1296    pub filling_transaction_id: Option<TransactionID>,
1297    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
1298    #[serde(
1299        rename = "filledTime",
1300        default,
1301        skip_serializing_if = "Option::is_none"
1302    )]
1303    pub filled_time: Option<Timestamp>,
1304    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
1305    /// Trade was opened as a result of the fill)
1306    #[serde(
1307        rename = "tradeOpenedID",
1308        default,
1309        skip_serializing_if = "Option::is_none"
1310    )]
1311    pub trade_opened_id: Option<TradeID>,
1312    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
1313    /// a Trade was reduced as a result of the fill)
1314    #[serde(
1315        rename = "tradeReducedID",
1316        default,
1317        skip_serializing_if = "Option::is_none"
1318    )]
1319    pub trade_reduced_id: Option<TradeID>,
1320    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
1321    /// one or more Trades were closed as a result of the fill)
1322    #[serde(
1323        rename = "tradeClosedIDs",
1324        default,
1325        skip_serializing_if = "Option::is_none"
1326    )]
1327    pub trade_closed_ids: Option<Vec<TradeID>>,
1328    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
1329    #[serde(
1330        rename = "cancellingTransactionID",
1331        default,
1332        skip_serializing_if = "Option::is_none"
1333    )]
1334    pub cancelling_transaction_id: Option<TransactionID>,
1335    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
1336    #[serde(
1337        rename = "cancelledTime",
1338        default,
1339        skip_serializing_if = "Option::is_none"
1340    )]
1341    pub cancelled_time: Option<Timestamp>,
1342    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
1343    /// a cancel/replace).
1344    #[serde(
1345        rename = "replacesOrderID",
1346        default,
1347        skip_serializing_if = "Option::is_none"
1348    )]
1349    pub replaces_order_id: Option<OrderID>,
1350    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
1351    /// cancel/replace).
1352    #[serde(
1353        rename = "replacedByOrderID",
1354        default,
1355        skip_serializing_if = "Option::is_none"
1356    )]
1357    pub replaced_by_order_id: Option<OrderID>,
1358}
1359
1360/// A TrailingStopLossOrder is an order that is linked to an open Trade and created with a price distance.
1361/// The price distance is used to calculate a trailing stop value for the order that is in the losing
1362/// direction from the market price at the time of the order’s creation. The trailing stop value will follow
1363/// the market price as it moves in the winning direction, and the order will be filled (closing the Trade)
1364/// by the first price that is equal to or worse than the trailing stop value. A TrailingStopLossOrder
1365/// cannot be used to open a new Position.
1366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1367#[serde(rename_all = "camelCase")]
1368pub struct TrailingStopLossOrder {
1369    /// The Order’s identifier, unique within the Order’s Account.
1370    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
1371    pub id: Option<OrderID>,
1372    /// The time when the Order was created.
1373    #[serde(
1374        rename = "createTime",
1375        default,
1376        skip_serializing_if = "Option::is_none"
1377    )]
1378    pub create_time: Option<Timestamp>,
1379    /// The current state of the Order.
1380    #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
1381    pub state: Option<OrderState>,
1382    /// The client extensions of the Order. Do not set, modify, or delete clientExtensions if your account is
1383    /// associated with MT4.
1384    #[serde(
1385        rename = "clientExtensions",
1386        default,
1387        skip_serializing_if = "Option::is_none"
1388    )]
1389    pub client_extensions: Option<ClientExtensions>,
1390    /// The type of the Order. Always set to “TRAILING_STOP_LOSS” for Trailing Stop Loss Orders.
1391    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1392    pub r#type: Option<OrderType>,
1393    /// The ID of the Trade to close when the price threshold is breached.
1394    #[serde(rename = "tradeID")]
1395    pub trade_id: TradeID,
1396    /// The client ID of the Trade to be closed when the price threshold is breached.
1397    #[serde(
1398        rename = "clientTradeID",
1399        default,
1400        skip_serializing_if = "Option::is_none"
1401    )]
1402    pub client_trade_id: Option<ClientID>,
1403    /// The price distance (in price units) specified for the TrailingStopLoss Order.
1404    #[serde(rename = "distance")]
1405    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1406    pub distance: Decimal,
1407    /// The time-in-force requested for the TrailingStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for
1408    /// TrailingStopLoss Orders.
1409    #[serde(rename = "timeInForce")]
1410    pub time_in_force: TimeInForce,
1411    /// The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
1412    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1413    pub gtd_time: Option<Timestamp>,
1414    /// Specification of which price component should be used when determining if an Order should be triggered
1415    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1416    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1417    /// filled using their default price component. This feature is only provided through the REST API. Clients
1418    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1419    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1420    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1421    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1422    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1423    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1424    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1425    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1426    #[serde(rename = "triggerCondition")]
1427    pub trigger_condition: OrderTriggerCondition,
1428    /// The trigger price for the Trailing Stop Loss Order. The trailing stop value will trail (follow) the
1429    /// market price by the TSL order’s configured “distance” as the market price moves in the winning
1430    /// direction. If the market price moves to a level that is equal to or worse than the trailing stop value,
1431    /// the order will be filled and the Trade will be closed.
1432    #[serde(
1433        rename = "trailingStopValue",
1434        default,
1435        skip_serializing_if = "Option::is_none"
1436    )]
1437    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1438    pub trailing_stop_value: Option<Decimal>,
1439    /// ID of the Transaction that filled this Order (only provided when the Order’s state is FILLED)
1440    #[serde(
1441        rename = "fillingTransactionID",
1442        default,
1443        skip_serializing_if = "Option::is_none"
1444    )]
1445    pub filling_transaction_id: Option<TransactionID>,
1446    /// Date/time when the Order was filled (only provided when the Order’s state is FILLED)
1447    #[serde(
1448        rename = "filledTime",
1449        default,
1450        skip_serializing_if = "Option::is_none"
1451    )]
1452    pub filled_time: Option<Timestamp>,
1453    /// Trade ID of Trade opened when the Order was filled (only provided when the Order’s state is FILLED and a
1454    /// Trade was opened as a result of the fill)
1455    #[serde(
1456        rename = "tradeOpenedID",
1457        default,
1458        skip_serializing_if = "Option::is_none"
1459    )]
1460    pub trade_opened_id: Option<TradeID>,
1461    /// Trade ID of Trade reduced when the Order was filled (only provided when the Order’s state is FILLED and
1462    /// a Trade was reduced as a result of the fill)
1463    #[serde(
1464        rename = "tradeReducedID",
1465        default,
1466        skip_serializing_if = "Option::is_none"
1467    )]
1468    pub trade_reduced_id: Option<TradeID>,
1469    /// Trade IDs of Trades closed when the Order was filled (only provided when the Order’s state is FILLED and
1470    /// one or more Trades were closed as a result of the fill)
1471    #[serde(
1472        rename = "tradeClosedIDs",
1473        default,
1474        skip_serializing_if = "Option::is_none"
1475    )]
1476    pub trade_closed_ids: Option<Vec<TradeID>>,
1477    /// ID of the Transaction that cancelled the Order (only provided when the Order’s state is CANCELLED)
1478    #[serde(
1479        rename = "cancellingTransactionID",
1480        default,
1481        skip_serializing_if = "Option::is_none"
1482    )]
1483    pub cancelling_transaction_id: Option<TransactionID>,
1484    /// Date/time when the Order was cancelled (only provided when the state of the Order is CANCELLED)
1485    #[serde(
1486        rename = "cancelledTime",
1487        default,
1488        skip_serializing_if = "Option::is_none"
1489    )]
1490    pub cancelled_time: Option<Timestamp>,
1491    /// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of
1492    /// a cancel/replace).
1493    #[serde(
1494        rename = "replacesOrderID",
1495        default,
1496        skip_serializing_if = "Option::is_none"
1497    )]
1498    pub replaces_order_id: Option<OrderID>,
1499    /// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a
1500    /// cancel/replace).
1501    #[serde(
1502        rename = "replacedByOrderID",
1503        default,
1504        skip_serializing_if = "Option::is_none"
1505    )]
1506    pub replaced_by_order_id: Option<OrderID>,
1507}
1508
1509/// A MarketOrderRequest specifies the parameters that may be set when creating a Market Order.
1510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1511#[serde(rename_all = "camelCase")]
1512pub struct MarketOrderRequest {
1513    /// The type of the Order to Create. Must be set to “MARKET” when creating a Market Order.
1514    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1515    pub r#type: Option<OrderType>,
1516    /// The Market Order’s Instrument.
1517    #[serde(rename = "instrument")]
1518    pub instrument: InstrumentName,
1519    /// The quantity requested to be filled by the Market Order. A positive number of units results in a long
1520    /// Order, and a negative number of units results in a short Order.
1521    #[serde(rename = "units")]
1522    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1523    pub units: Decimal,
1524    /// The time-in-force requested for the Market Order. Restricted to FOK or IOC for a MarketOrder.
1525    #[serde(rename = "timeInForce")]
1526    pub time_in_force: TimeInForce,
1527    /// The worst price that the client is willing to have the Market Order filled at.
1528    #[serde(
1529        rename = "priceBound",
1530        default,
1531        skip_serializing_if = "Option::is_none"
1532    )]
1533    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1534    pub price_bound: Option<Decimal>,
1535    /// Specification of how Positions in the Account are modified when the Order is filled.
1536    #[serde(rename = "positionFill")]
1537    pub position_fill: OrderPositionFill,
1538    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
1539    /// account is associated with MT4.
1540    #[serde(
1541        rename = "clientExtensions",
1542        default,
1543        skip_serializing_if = "Option::is_none"
1544    )]
1545    pub client_extensions: Option<ClientExtensions>,
1546    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
1547    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
1548    /// dependent Take Profit Order is modified directly through the Trade.
1549    #[serde(
1550        rename = "takeProfitOnFill",
1551        default,
1552        skip_serializing_if = "Option::is_none"
1553    )]
1554    pub take_profit_on_fill: Option<TakeProfitDetails>,
1555    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
1556    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
1557    /// Stop Loss Order is modified directly through the Trade.
1558    #[serde(
1559        rename = "stopLossOnFill",
1560        default,
1561        skip_serializing_if = "Option::is_none"
1562    )]
1563    pub stop_loss_on_fill: Option<StopLossDetails>,
1564    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
1565    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
1566    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
1567    #[serde(
1568        rename = "guaranteedStopLossOnFill",
1569        default,
1570        skip_serializing_if = "Option::is_none"
1571    )]
1572    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
1573    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
1574    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
1575    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
1576    #[serde(
1577        rename = "trailingStopLossOnFill",
1578        default,
1579        skip_serializing_if = "Option::is_none"
1580    )]
1581    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
1582    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
1583    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
1584    #[serde(
1585        rename = "tradeClientExtensions",
1586        default,
1587        skip_serializing_if = "Option::is_none"
1588    )]
1589    pub trade_client_extensions: Option<ClientExtensions>,
1590}
1591
1592/// A LimitOrderRequest specifies the parameters that may be set when creating a Limit Order.
1593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1594#[serde(rename_all = "camelCase")]
1595pub struct LimitOrderRequest {
1596    /// The type of the Order to Create. Must be set to “LIMIT” when creating a Market Order.
1597    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1598    pub r#type: Option<OrderType>,
1599    /// The Limit Order’s Instrument.
1600    #[serde(rename = "instrument")]
1601    pub instrument: InstrumentName,
1602    /// The quantity requested to be filled by the Limit Order. A positive number of units results in a long
1603    /// Order, and a negative number of units results in a short Order.
1604    #[serde(rename = "units")]
1605    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1606    pub units: Decimal,
1607    /// The price threshold specified for the Limit Order. The Limit Order will only be filled by a market price
1608    /// that is equal to or better than this price.
1609    #[serde(rename = "price")]
1610    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1611    pub price: Decimal,
1612    /// The time-in-force requested for the Limit Order.
1613    #[serde(rename = "timeInForce")]
1614    pub time_in_force: TimeInForce,
1615    /// The date/time when the Limit Order will be cancelled if its timeInForce is “GTD”.
1616    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1617    pub gtd_time: Option<Timestamp>,
1618    /// Specification of how Positions in the Account are modified when the Order is filled.
1619    #[serde(rename = "positionFill")]
1620    pub position_fill: OrderPositionFill,
1621    /// Specification of which price component should be used when determining if an Order should be triggered
1622    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1623    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1624    /// filled using their default price component. This feature is only provided through the REST API. Clients
1625    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1626    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1627    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1628    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1629    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1630    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1631    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1632    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1633    #[serde(rename = "triggerCondition")]
1634    pub trigger_condition: OrderTriggerCondition,
1635    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
1636    /// account is associated with MT4.
1637    #[serde(
1638        rename = "clientExtensions",
1639        default,
1640        skip_serializing_if = "Option::is_none"
1641    )]
1642    pub client_extensions: Option<ClientExtensions>,
1643    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
1644    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
1645    /// dependent Take Profit Order is modified directly through the Trade.
1646    #[serde(
1647        rename = "takeProfitOnFill",
1648        default,
1649        skip_serializing_if = "Option::is_none"
1650    )]
1651    pub take_profit_on_fill: Option<TakeProfitDetails>,
1652    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
1653    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
1654    /// Stop Loss Order is modified directly through the Trade.
1655    #[serde(
1656        rename = "stopLossOnFill",
1657        default,
1658        skip_serializing_if = "Option::is_none"
1659    )]
1660    pub stop_loss_on_fill: Option<StopLossDetails>,
1661    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
1662    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
1663    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
1664    #[serde(
1665        rename = "guaranteedStopLossOnFill",
1666        default,
1667        skip_serializing_if = "Option::is_none"
1668    )]
1669    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
1670    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
1671    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
1672    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
1673    #[serde(
1674        rename = "trailingStopLossOnFill",
1675        default,
1676        skip_serializing_if = "Option::is_none"
1677    )]
1678    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
1679    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
1680    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
1681    #[serde(
1682        rename = "tradeClientExtensions",
1683        default,
1684        skip_serializing_if = "Option::is_none"
1685    )]
1686    pub trade_client_extensions: Option<ClientExtensions>,
1687}
1688
1689/// A StopOrderRequest specifies the parameters that may be set when creating a Stop Order.
1690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1691#[serde(rename_all = "camelCase")]
1692pub struct StopOrderRequest {
1693    /// The type of the Order to Create. Must be set to “STOP” when creating a Stop Order.
1694    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1695    pub r#type: Option<OrderType>,
1696    /// The Stop Order’s Instrument.
1697    #[serde(rename = "instrument")]
1698    pub instrument: InstrumentName,
1699    /// The quantity requested to be filled by the Stop Order. A positive number of units results in a long
1700    /// Order, and a negative number of units results in a short Order.
1701    #[serde(rename = "units")]
1702    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1703    pub units: Decimal,
1704    /// The price threshold specified for the Stop Order. The Stop Order will only be filled by a market price
1705    /// that is equal to or worse than this price.
1706    #[serde(rename = "price")]
1707    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1708    pub price: Decimal,
1709    /// The worst market price that may be used to fill this Stop Order. If the market gaps and crosses through
1710    /// both the price and the priceBound, the Stop Order will be cancelled instead of being filled.
1711    #[serde(
1712        rename = "priceBound",
1713        default,
1714        skip_serializing_if = "Option::is_none"
1715    )]
1716    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1717    pub price_bound: Option<Decimal>,
1718    /// The time-in-force requested for the Stop Order.
1719    #[serde(rename = "timeInForce")]
1720    pub time_in_force: TimeInForce,
1721    /// The date/time when the Stop Order will be cancelled if its timeInForce is “GTD”.
1722    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1723    pub gtd_time: Option<Timestamp>,
1724    /// Specification of how Positions in the Account are modified when the Order is filled.
1725    #[serde(rename = "positionFill")]
1726    pub position_fill: OrderPositionFill,
1727    /// Specification of which price component should be used when determining if an Order should be triggered
1728    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1729    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1730    /// filled using their default price component. This feature is only provided through the REST API. Clients
1731    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1732    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1733    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1734    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1735    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1736    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1737    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1738    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1739    #[serde(rename = "triggerCondition")]
1740    pub trigger_condition: OrderTriggerCondition,
1741    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
1742    /// account is associated with MT4.
1743    #[serde(
1744        rename = "clientExtensions",
1745        default,
1746        skip_serializing_if = "Option::is_none"
1747    )]
1748    pub client_extensions: Option<ClientExtensions>,
1749    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
1750    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
1751    /// dependent Take Profit Order is modified directly through the Trade.
1752    #[serde(
1753        rename = "takeProfitOnFill",
1754        default,
1755        skip_serializing_if = "Option::is_none"
1756    )]
1757    pub take_profit_on_fill: Option<TakeProfitDetails>,
1758    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
1759    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
1760    /// Stop Loss Order is modified directly through the Trade.
1761    #[serde(
1762        rename = "stopLossOnFill",
1763        default,
1764        skip_serializing_if = "Option::is_none"
1765    )]
1766    pub stop_loss_on_fill: Option<StopLossDetails>,
1767    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
1768    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
1769    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
1770    #[serde(
1771        rename = "guaranteedStopLossOnFill",
1772        default,
1773        skip_serializing_if = "Option::is_none"
1774    )]
1775    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
1776    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
1777    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
1778    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
1779    #[serde(
1780        rename = "trailingStopLossOnFill",
1781        default,
1782        skip_serializing_if = "Option::is_none"
1783    )]
1784    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
1785    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
1786    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
1787    #[serde(
1788        rename = "tradeClientExtensions",
1789        default,
1790        skip_serializing_if = "Option::is_none"
1791    )]
1792    pub trade_client_extensions: Option<ClientExtensions>,
1793}
1794
1795/// A MarketIfTouchedOrderRequest specifies the parameters that may be set when creating a Market-if-Touched
1796/// Order.
1797#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1798#[serde(rename_all = "camelCase")]
1799pub struct MarketIfTouchedOrderRequest {
1800    /// The type of the Order to Create. Must be set to “MARKET_IF_TOUCHED” when creating a Market If Touched
1801    /// Order.
1802    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1803    pub r#type: Option<OrderType>,
1804    /// The MarketIfTouched Order’s Instrument.
1805    #[serde(rename = "instrument")]
1806    pub instrument: InstrumentName,
1807    /// The quantity requested to be filled by the MarketIfTouched Order. A positive number of units results in
1808    /// a long Order, and a negative number of units results in a short Order.
1809    #[serde(rename = "units")]
1810    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1811    pub units: Decimal,
1812    /// The price threshold specified for the MarketIfTouched Order. The MarketIfTouched Order will only be
1813    /// filled by a market price that crosses this price from the direction of the market price at the time when
1814    /// the Order was created (the initialMarketPrice). Depending on the value of the Order’s price and
1815    /// initialMarketPrice, the MarketIfTouchedOrder will behave like a Limit or a Stop Order.
1816    #[serde(rename = "price")]
1817    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1818    pub price: Decimal,
1819    /// The worst market price that may be used to fill this MarketIfTouched Order.
1820    #[serde(
1821        rename = "priceBound",
1822        default,
1823        skip_serializing_if = "Option::is_none"
1824    )]
1825    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1826    pub price_bound: Option<Decimal>,
1827    /// The time-in-force requested for the MarketIfTouched Order. Restricted to “GTC”, “GFD” and “GTD” for
1828    /// MarketIfTouched Orders.
1829    #[serde(rename = "timeInForce")]
1830    pub time_in_force: TimeInForce,
1831    /// The date/time when the MarketIfTouched Order will be cancelled if its timeInForce is “GTD”.
1832    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1833    pub gtd_time: Option<Timestamp>,
1834    /// Specification of how Positions in the Account are modified when the Order is filled.
1835    #[serde(rename = "positionFill")]
1836    pub position_fill: OrderPositionFill,
1837    /// Specification of which price component should be used when determining if an Order should be triggered
1838    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1839    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1840    /// filled using their default price component. This feature is only provided through the REST API. Clients
1841    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1842    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1843    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1844    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1845    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1846    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1847    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1848    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1849    #[serde(rename = "triggerCondition")]
1850    pub trigger_condition: OrderTriggerCondition,
1851    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
1852    /// account is associated with MT4.
1853    #[serde(
1854        rename = "clientExtensions",
1855        default,
1856        skip_serializing_if = "Option::is_none"
1857    )]
1858    pub client_extensions: Option<ClientExtensions>,
1859    /// TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This
1860    /// may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s
1861    /// dependent Take Profit Order is modified directly through the Trade.
1862    #[serde(
1863        rename = "takeProfitOnFill",
1864        default,
1865        skip_serializing_if = "Option::is_none"
1866    )]
1867    pub take_profit_on_fill: Option<TakeProfitDetails>,
1868    /// StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may
1869    /// happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent
1870    /// Stop Loss Order is modified directly through the Trade.
1871    #[serde(
1872        rename = "stopLossOnFill",
1873        default,
1874        skip_serializing_if = "Option::is_none"
1875    )]
1876    pub stop_loss_on_fill: Option<StopLossDetails>,
1877    /// GuaranteedStopLossDetails specifies the details of a Guaranteed Stop Loss Order to be created on behalf
1878    /// of a client. This may happen when an Order is filled that opens a Trade requiring a Guaranteed Stop
1879    /// Loss, or when a Trade’s dependent Guaranteed Stop Loss Order is modified directly through the Trade.
1880    #[serde(
1881        rename = "guaranteedStopLossOnFill",
1882        default,
1883        skip_serializing_if = "Option::is_none"
1884    )]
1885    pub guaranteed_stop_loss_on_fill: Option<GuaranteedStopLossDetails>,
1886    /// TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a
1887    /// client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or
1888    /// when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
1889    #[serde(
1890        rename = "trailingStopLossOnFill",
1891        default,
1892        skip_serializing_if = "Option::is_none"
1893    )]
1894    pub trailing_stop_loss_on_fill: Option<TrailingStopLossDetails>,
1895    /// Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do
1896    /// not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
1897    #[serde(
1898        rename = "tradeClientExtensions",
1899        default,
1900        skip_serializing_if = "Option::is_none"
1901    )]
1902    pub trade_client_extensions: Option<ClientExtensions>,
1903}
1904
1905/// A TakeProfitOrderRequest specifies the parameters that may be set when creating a Take Profit Order.
1906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1907#[serde(rename_all = "camelCase")]
1908pub struct TakeProfitOrderRequest {
1909    /// The type of the Order to Create. Must be set to “TAKE_PROFIT” when creating a Take Profit Order.
1910    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1911    pub r#type: Option<OrderType>,
1912    /// The ID of the Trade to close when the price threshold is breached.
1913    #[serde(rename = "tradeID")]
1914    pub trade_id: TradeID,
1915    /// The client ID of the Trade to be closed when the price threshold is breached.
1916    #[serde(
1917        rename = "clientTradeID",
1918        default,
1919        skip_serializing_if = "Option::is_none"
1920    )]
1921    pub client_trade_id: Option<ClientID>,
1922    /// The price threshold specified for the TakeProfit Order. The associated Trade will be closed by a market
1923    /// price that is equal to or better than this threshold.
1924    #[serde(rename = "price")]
1925    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1926    pub price: Decimal,
1927    /// The time-in-force requested for the TakeProfit Order. Restricted to “GTC”, “GFD” and “GTD” for
1928    /// TakeProfit Orders.
1929    #[serde(rename = "timeInForce")]
1930    pub time_in_force: TimeInForce,
1931    /// The date/time when the TakeProfit Order will be cancelled if its timeInForce is “GTD”.
1932    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1933    pub gtd_time: Option<Timestamp>,
1934    /// Specification of which price component should be used when determining if an Order should be triggered
1935    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1936    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1937    /// filled using their default price component. This feature is only provided through the REST API. Clients
1938    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1939    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1940    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
1941    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
1942    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
1943    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
1944    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
1945    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
1946    #[serde(rename = "triggerCondition")]
1947    pub trigger_condition: OrderTriggerCondition,
1948    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
1949    /// account is associated with MT4.
1950    #[serde(
1951        rename = "clientExtensions",
1952        default,
1953        skip_serializing_if = "Option::is_none"
1954    )]
1955    pub client_extensions: Option<ClientExtensions>,
1956}
1957
1958/// A StopLossOrderRequest specifies the parameters that may be set when creating a Stop Loss Order. Only
1959/// one of the price and distance fields may be specified.
1960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1961#[serde(rename_all = "camelCase")]
1962pub struct StopLossOrderRequest {
1963    /// The type of the Order to Create. Must be set to “STOP_LOSS” when creating a Stop Loss Order.
1964    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1965    pub r#type: Option<OrderType>,
1966    /// The ID of the Trade to close when the price threshold is breached.
1967    #[serde(rename = "tradeID")]
1968    pub trade_id: TradeID,
1969    /// The client ID of the Trade to be closed when the price threshold is breached.
1970    #[serde(
1971        rename = "clientTradeID",
1972        default,
1973        skip_serializing_if = "Option::is_none"
1974    )]
1975    pub client_trade_id: Option<ClientID>,
1976    /// The price threshold specified for the Stop Loss Order. The associated Trade will be closed by a market
1977    /// price that is equal to or worse than this threshold.
1978    #[serde(rename = "price")]
1979    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
1980    pub price: Decimal,
1981    /// Specifies the distance (in price units) from the Account’s current price to use as the Stop Loss Order
1982    /// price. If the Trade is short the Instrument’s bid price is used, and for long Trades the ask is used.
1983    #[serde(rename = "distance", default, skip_serializing_if = "Option::is_none")]
1984    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
1985    pub distance: Option<Decimal>,
1986    /// The time-in-force requested for the StopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for StopLoss
1987    /// Orders.
1988    #[serde(rename = "timeInForce")]
1989    pub time_in_force: TimeInForce,
1990    /// The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
1991    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
1992    pub gtd_time: Option<Timestamp>,
1993    /// Specification of which price component should be used when determining if an Order should be triggered
1994    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
1995    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
1996    /// filled using their default price component. This feature is only provided through the REST API. Clients
1997    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
1998    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
1999    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
2000    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
2001    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
2002    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
2003    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
2004    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
2005    #[serde(rename = "triggerCondition")]
2006    pub trigger_condition: OrderTriggerCondition,
2007    /// Flag indicating that the Stop Loss Order is guaranteed. The default value depends on the
2008    /// GuaranteedStopLossOrderMode of the account, if it is REQUIRED, the default will be true, for DISABLED or
2009    /// ENABLED the default is false. Deprecated: Will be removed in a future API update.
2010    #[serde(
2011        rename = "guaranteed",
2012        default,
2013        skip_serializing_if = "Option::is_none"
2014    )]
2015    pub guaranteed: Option<bool>,
2016    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
2017    /// account is associated with MT4.
2018    #[serde(
2019        rename = "clientExtensions",
2020        default,
2021        skip_serializing_if = "Option::is_none"
2022    )]
2023    pub client_extensions: Option<ClientExtensions>,
2024}
2025
2026/// A GuaranteedStopLossOrderRequest specifies the parameters that may be set when creating a Guaranteed
2027/// Stop Loss Order. Only one of the price and distance fields may be specified.
2028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2029#[serde(rename_all = "camelCase")]
2030pub struct GuaranteedStopLossOrderRequest {
2031    /// The type of the Order to Create. Must be set to “GUARANTEED_STOP_LOSS” when creating a Guaranteed Stop
2032    /// Loss Order.
2033    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
2034    pub r#type: Option<OrderType>,
2035    /// The ID of the Trade to close when the price threshold is breached.
2036    #[serde(rename = "tradeID")]
2037    pub trade_id: TradeID,
2038    /// The client ID of the Trade to be closed when the price threshold is breached.
2039    #[serde(
2040        rename = "clientTradeID",
2041        default,
2042        skip_serializing_if = "Option::is_none"
2043    )]
2044    pub client_trade_id: Option<ClientID>,
2045    /// The price threshold specified for the Guaranteed Stop Loss Order. The associated Trade will be closed at
2046    /// this price.
2047    #[serde(rename = "price")]
2048    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
2049    pub price: Decimal,
2050    /// Specifies the distance (in price units) from the Account’s current price to use as the Guaranteed Stop
2051    /// Loss Order price. If the Trade is short the Instrument’s bid price is used, and for long Trades the ask
2052    /// is used.
2053    #[serde(rename = "distance", default, skip_serializing_if = "Option::is_none")]
2054    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2055    pub distance: Option<Decimal>,
2056    /// The time-in-force requested for the GuaranteedStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for
2057    /// GuaranteedStopLoss Orders.
2058    #[serde(rename = "timeInForce")]
2059    pub time_in_force: TimeInForce,
2060    /// The date/time when the GuaranteedStopLoss Order will be cancelled if its timeInForce is “GTD”.
2061    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
2062    pub gtd_time: Option<Timestamp>,
2063    /// Specification of which price component should be used when determining if an Order should be triggered
2064    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
2065    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
2066    /// filled using their default price component. This feature is only provided through the REST API. Clients
2067    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
2068    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
2069    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
2070    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
2071    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
2072    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
2073    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
2074    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
2075    #[serde(rename = "triggerCondition")]
2076    pub trigger_condition: OrderTriggerCondition,
2077    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
2078    /// account is associated with MT4.
2079    #[serde(
2080        rename = "clientExtensions",
2081        default,
2082        skip_serializing_if = "Option::is_none"
2083    )]
2084    pub client_extensions: Option<ClientExtensions>,
2085}
2086
2087/// A TrailingStopLossOrderRequest specifies the parameters that may be set when creating a Trailing Stop
2088/// Loss Order.
2089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2090#[serde(rename_all = "camelCase")]
2091pub struct TrailingStopLossOrderRequest {
2092    /// The type of the Order to Create. Must be set to “TRAILING_STOP_LOSS” when creating a Trailing Stop Loss
2093    /// Order.
2094    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
2095    pub r#type: Option<OrderType>,
2096    /// The ID of the Trade to close when the price threshold is breached.
2097    #[serde(rename = "tradeID")]
2098    pub trade_id: TradeID,
2099    /// The client ID of the Trade to be closed when the price threshold is breached.
2100    #[serde(
2101        rename = "clientTradeID",
2102        default,
2103        skip_serializing_if = "Option::is_none"
2104    )]
2105    pub client_trade_id: Option<ClientID>,
2106    /// The price distance (in price units) specified for the TrailingStopLoss Order.
2107    #[serde(rename = "distance")]
2108    #[serde(deserialize_with = "crate::decimal_wire::number_or_string")]
2109    pub distance: Decimal,
2110    /// The time-in-force requested for the TrailingStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for
2111    /// TrailingStopLoss Orders.
2112    #[serde(rename = "timeInForce")]
2113    pub time_in_force: TimeInForce,
2114    /// The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
2115    #[serde(rename = "gtdTime", default, skip_serializing_if = "Option::is_none")]
2116    pub gtd_time: Option<Timestamp>,
2117    /// Specification of which price component should be used when determining if an Order should be triggered
2118    /// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
2119    /// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
2120    /// filled using their default price component. This feature is only provided through the REST API. Clients
2121    /// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
2122    /// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
2123    /// platforms always assume that an Order’s trigger condition is set to the default value when indicating
2124    /// the distance from an Order’s trigger price, and will always provide the default trigger condition when
2125    /// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
2126    /// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
2127    /// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
2128    /// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
2129    #[serde(rename = "triggerCondition")]
2130    pub trigger_condition: OrderTriggerCondition,
2131    /// The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your
2132    /// account is associated with MT4.
2133    #[serde(
2134        rename = "clientExtensions",
2135        default,
2136        skip_serializing_if = "Option::is_none"
2137    )]
2138    pub client_extensions: Option<ClientExtensions>,
2139}
2140
2141/// The type of the Order.
2142#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2143#[non_exhaustive]
2144pub enum OrderType {
2145    /// A Market Order
2146    Market,
2147    /// A Limit Order
2148    Limit,
2149    /// A Stop Order
2150    Stop,
2151    /// A Market-if-touched Order
2152    MarketIfTouched,
2153    /// A Take Profit Order
2154    TakeProfit,
2155    /// A Stop Loss Order
2156    StopLoss,
2157    /// A Guaranteed Stop Loss Order
2158    GuaranteedStopLoss,
2159    /// A Trailing Stop Loss Order
2160    TrailingStopLoss,
2161    /// A Fixed Price Order
2162    FixedPrice,
2163    /// An unrecognized provider value, preserved for forward compatibility.
2164    Unknown(String),
2165}
2166
2167impl OrderType {
2168    /// Return the exact provider spelling.
2169    pub fn as_str(&self) -> &str {
2170        match self {
2171            Self::Market => "MARKET",
2172            Self::Limit => "LIMIT",
2173            Self::Stop => "STOP",
2174            Self::MarketIfTouched => "MARKET_IF_TOUCHED",
2175            Self::TakeProfit => "TAKE_PROFIT",
2176            Self::StopLoss => "STOP_LOSS",
2177            Self::GuaranteedStopLoss => "GUARANTEED_STOP_LOSS",
2178            Self::TrailingStopLoss => "TRAILING_STOP_LOSS",
2179            Self::FixedPrice => "FIXED_PRICE",
2180            Self::Unknown(value) => value,
2181        }
2182    }
2183}
2184
2185impl Serialize for OrderType {
2186    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2187        serializer.serialize_str(self.as_str())
2188    }
2189}
2190
2191impl<'de> Deserialize<'de> for OrderType {
2192    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2193        let value = String::deserialize(deserializer)?;
2194        Ok(match value.as_str() {
2195            "MARKET" => Self::Market,
2196            "LIMIT" => Self::Limit,
2197            "STOP" => Self::Stop,
2198            "MARKET_IF_TOUCHED" => Self::MarketIfTouched,
2199            "TAKE_PROFIT" => Self::TakeProfit,
2200            "STOP_LOSS" => Self::StopLoss,
2201            "GUARANTEED_STOP_LOSS" => Self::GuaranteedStopLoss,
2202            "TRAILING_STOP_LOSS" => Self::TrailingStopLoss,
2203            "FIXED_PRICE" => Self::FixedPrice,
2204            _ => Self::Unknown(value),
2205        })
2206    }
2207}
2208
2209/// The type of the Order.
2210#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2211#[non_exhaustive]
2212pub enum CancellableOrderType {
2213    /// A Limit Order
2214    Limit,
2215    /// A Stop Order
2216    Stop,
2217    /// A Market-if-touched Order
2218    MarketIfTouched,
2219    /// A Take Profit Order
2220    TakeProfit,
2221    /// A Stop Loss Order
2222    StopLoss,
2223    /// A Guaranteed Stop Loss Order
2224    GuaranteedStopLoss,
2225    /// A Trailing Stop Loss Order
2226    TrailingStopLoss,
2227    /// An unrecognized provider value, preserved for forward compatibility.
2228    Unknown(String),
2229}
2230
2231impl CancellableOrderType {
2232    /// Return the exact provider spelling.
2233    pub fn as_str(&self) -> &str {
2234        match self {
2235            Self::Limit => "LIMIT",
2236            Self::Stop => "STOP",
2237            Self::MarketIfTouched => "MARKET_IF_TOUCHED",
2238            Self::TakeProfit => "TAKE_PROFIT",
2239            Self::StopLoss => "STOP_LOSS",
2240            Self::GuaranteedStopLoss => "GUARANTEED_STOP_LOSS",
2241            Self::TrailingStopLoss => "TRAILING_STOP_LOSS",
2242            Self::Unknown(value) => value,
2243        }
2244    }
2245}
2246
2247impl Serialize for CancellableOrderType {
2248    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2249        serializer.serialize_str(self.as_str())
2250    }
2251}
2252
2253impl<'de> Deserialize<'de> for CancellableOrderType {
2254    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2255        let value = String::deserialize(deserializer)?;
2256        Ok(match value.as_str() {
2257            "LIMIT" => Self::Limit,
2258            "STOP" => Self::Stop,
2259            "MARKET_IF_TOUCHED" => Self::MarketIfTouched,
2260            "TAKE_PROFIT" => Self::TakeProfit,
2261            "STOP_LOSS" => Self::StopLoss,
2262            "GUARANTEED_STOP_LOSS" => Self::GuaranteedStopLoss,
2263            "TRAILING_STOP_LOSS" => Self::TrailingStopLoss,
2264            _ => Self::Unknown(value),
2265        })
2266    }
2267}
2268
2269/// The current state of the Order.
2270#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2271#[non_exhaustive]
2272pub enum OrderState {
2273    /// The Order is currently pending execution
2274    Pending,
2275    /// The Order has been filled
2276    Filled,
2277    /// The Order has been triggered
2278    Triggered,
2279    /// The Order has been cancelled
2280    Cancelled,
2281    /// An unrecognized provider value, preserved for forward compatibility.
2282    Unknown(String),
2283}
2284
2285impl OrderState {
2286    /// Return the exact provider spelling.
2287    pub fn as_str(&self) -> &str {
2288        match self {
2289            Self::Pending => "PENDING",
2290            Self::Filled => "FILLED",
2291            Self::Triggered => "TRIGGERED",
2292            Self::Cancelled => "CANCELLED",
2293            Self::Unknown(value) => value,
2294        }
2295    }
2296}
2297
2298impl Serialize for OrderState {
2299    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2300        serializer.serialize_str(self.as_str())
2301    }
2302}
2303
2304impl<'de> Deserialize<'de> for OrderState {
2305    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2306        let value = String::deserialize(deserializer)?;
2307        Ok(match value.as_str() {
2308            "PENDING" => Self::Pending,
2309            "FILLED" => Self::Filled,
2310            "TRIGGERED" => Self::Triggered,
2311            "CANCELLED" => Self::Cancelled,
2312            _ => Self::Unknown(value),
2313        })
2314    }
2315}
2316
2317/// The state to filter the requested Orders by.
2318#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2319#[non_exhaustive]
2320pub enum OrderStateFilter {
2321    /// The Orders that are currently pending execution
2322    Pending,
2323    /// The Orders that have been filled
2324    Filled,
2325    /// The Orders that have been triggered
2326    Triggered,
2327    /// The Orders that have been cancelled
2328    Cancelled,
2329    /// The Orders that are in any of the possible states listed above
2330    All,
2331    /// An unrecognized provider value, preserved for forward compatibility.
2332    Unknown(String),
2333}
2334
2335impl OrderStateFilter {
2336    /// Return the exact provider spelling.
2337    pub fn as_str(&self) -> &str {
2338        match self {
2339            Self::Pending => "PENDING",
2340            Self::Filled => "FILLED",
2341            Self::Triggered => "TRIGGERED",
2342            Self::Cancelled => "CANCELLED",
2343            Self::All => "ALL",
2344            Self::Unknown(value) => value,
2345        }
2346    }
2347}
2348
2349impl Serialize for OrderStateFilter {
2350    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2351        serializer.serialize_str(self.as_str())
2352    }
2353}
2354
2355impl<'de> Deserialize<'de> for OrderStateFilter {
2356    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2357        let value = String::deserialize(deserializer)?;
2358        Ok(match value.as_str() {
2359            "PENDING" => Self::Pending,
2360            "FILLED" => Self::Filled,
2361            "TRIGGERED" => Self::Triggered,
2362            "CANCELLED" => Self::Cancelled,
2363            "ALL" => Self::All,
2364            _ => Self::Unknown(value),
2365        })
2366    }
2367}
2368
2369/// An OrderIdentifier is used to refer to an Order, and contains both the OrderID and the ClientOrderID.
2370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2371#[serde(rename_all = "camelCase")]
2372pub struct OrderIdentifier {
2373    /// The OANDA-assigned Order ID
2374    #[serde(rename = "orderID", default, skip_serializing_if = "Option::is_none")]
2375    pub order_id: Option<OrderID>,
2376    /// The client-provided client Order ID
2377    #[serde(
2378        rename = "clientOrderID",
2379        default,
2380        skip_serializing_if = "Option::is_none"
2381    )]
2382    pub client_order_id: Option<ClientID>,
2383}
2384
2385/// The time-in-force of an Order. TimeInForce describes how long an Order should remain pending before
2386/// being automatically cancelled by the execution system.
2387#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2388#[non_exhaustive]
2389pub enum TimeInForce {
2390    /// The Order is “Good unTil Cancelled”
2391    Gtc,
2392    /// The Order is “Good unTil Date” and will be cancelled at the provided time
2393    Gtd,
2394    /// The Order is “Good For Day” and will be cancelled at 5pm New York time
2395    Gfd,
2396    /// The Order must be immediately “Filled Or Killed”
2397    Fok,
2398    /// The Order must be “Immediately partially filled Or Cancelled”
2399    Ioc,
2400    /// An unrecognized provider value, preserved for forward compatibility.
2401    Unknown(String),
2402}
2403
2404impl TimeInForce {
2405    /// Return the exact provider spelling.
2406    pub fn as_str(&self) -> &str {
2407        match self {
2408            Self::Gtc => "GTC",
2409            Self::Gtd => "GTD",
2410            Self::Gfd => "GFD",
2411            Self::Fok => "FOK",
2412            Self::Ioc => "IOC",
2413            Self::Unknown(value) => value,
2414        }
2415    }
2416}
2417
2418impl Serialize for TimeInForce {
2419    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2420        serializer.serialize_str(self.as_str())
2421    }
2422}
2423
2424impl<'de> Deserialize<'de> for TimeInForce {
2425    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2426        let value = String::deserialize(deserializer)?;
2427        Ok(match value.as_str() {
2428            "GTC" => Self::Gtc,
2429            "GTD" => Self::Gtd,
2430            "GFD" => Self::Gfd,
2431            "FOK" => Self::Fok,
2432            "IOC" => Self::Ioc,
2433            _ => Self::Unknown(value),
2434        })
2435    }
2436}
2437
2438/// Specification of how Positions in the Account are modified when the Order is filled.
2439#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2440#[non_exhaustive]
2441pub enum OrderPositionFill {
2442    /// When the Order is filled, only allow Positions to be opened or extended.
2443    OpenOnly,
2444    /// When the Order is filled, always fully reduce an existing Position before opening a new Position.
2445    ReduceFirst,
2446    /// When the Order is filled, only reduce an existing Position.
2447    ReduceOnly,
2448    /// When the Order is filled, use REDUCE_FIRST behaviour for non-client hedging Accounts, and OPEN_ONLY
2449    /// behaviour for client hedging Accounts.
2450    Default,
2451    /// An unrecognized provider value, preserved for forward compatibility.
2452    Unknown(String),
2453}
2454
2455impl OrderPositionFill {
2456    /// Return the exact provider spelling.
2457    pub fn as_str(&self) -> &str {
2458        match self {
2459            Self::OpenOnly => "OPEN_ONLY",
2460            Self::ReduceFirst => "REDUCE_FIRST",
2461            Self::ReduceOnly => "REDUCE_ONLY",
2462            Self::Default => "DEFAULT",
2463            Self::Unknown(value) => value,
2464        }
2465    }
2466}
2467
2468impl Serialize for OrderPositionFill {
2469    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2470        serializer.serialize_str(self.as_str())
2471    }
2472}
2473
2474impl<'de> Deserialize<'de> for OrderPositionFill {
2475    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2476        let value = String::deserialize(deserializer)?;
2477        Ok(match value.as_str() {
2478            "OPEN_ONLY" => Self::OpenOnly,
2479            "REDUCE_FIRST" => Self::ReduceFirst,
2480            "REDUCE_ONLY" => Self::ReduceOnly,
2481            "DEFAULT" => Self::Default,
2482            _ => Self::Unknown(value),
2483        })
2484    }
2485}
2486
2487/// Specification of which price component should be used when determining if an Order should be triggered
2488/// and filled. This allows Orders to be triggered based on the bid, ask, mid, default (ask for buy, bid for
2489/// sell) or inverse (ask for sell, bid for buy) price depending on the desired behaviour. Orders are always
2490/// filled using their default price component. This feature is only provided through the REST API. Clients
2491/// who choose to specify a non-default trigger condition will not see it reflected in any of OANDA’s
2492/// proprietary or partner trading platforms, their transaction history or their account statements. OANDA
2493/// platforms always assume that an Order’s trigger condition is set to the default value when indicating
2494/// the distance from an Order’s trigger price, and will always provide the default trigger condition when
2495/// creating or modifying an Order. A special restriction applies when creating a Guaranteed Stop Loss
2496/// Order. In this case the TriggerCondition value must either be “DEFAULT”, or the “natural” trigger side
2497/// “DEFAULT” results in. So for a Guaranteed Stop Loss Order for a long trade valid values are “DEFAULT”
2498/// and “BID”, and for short trades “DEFAULT” and “ASK” are valid.
2499#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2500#[non_exhaustive]
2501pub enum OrderTriggerCondition {
2502    /// Trigger an Order the “natural” way: compare its price to the ask for long Orders and bid for short
2503    /// Orders.
2504    Default,
2505    /// Trigger an Order the opposite of the “natural” way: compare its price the bid for long Orders and ask
2506    /// for short Orders.
2507    Inverse,
2508    /// Trigger an Order by comparing its price to the bid regardless of whether it is long or short.
2509    Bid,
2510    /// Trigger an Order by comparing its price to the ask regardless of whether it is long or short.
2511    Ask,
2512    /// Trigger an Order by comparing its price to the midpoint regardless of whether it is long or short.
2513    Mid,
2514    /// An unrecognized provider value, preserved for forward compatibility.
2515    Unknown(String),
2516}
2517
2518impl OrderTriggerCondition {
2519    /// Return the exact provider spelling.
2520    pub fn as_str(&self) -> &str {
2521        match self {
2522            Self::Default => "DEFAULT",
2523            Self::Inverse => "INVERSE",
2524            Self::Bid => "BID",
2525            Self::Ask => "ASK",
2526            Self::Mid => "MID",
2527            Self::Unknown(value) => value,
2528        }
2529    }
2530}
2531
2532impl Serialize for OrderTriggerCondition {
2533    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2534        serializer.serialize_str(self.as_str())
2535    }
2536}
2537
2538impl<'de> Deserialize<'de> for OrderTriggerCondition {
2539    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2540        let value = String::deserialize(deserializer)?;
2541        Ok(match value.as_str() {
2542            "DEFAULT" => Self::Default,
2543            "INVERSE" => Self::Inverse,
2544            "BID" => Self::Bid,
2545            "ASK" => Self::Ask,
2546            "MID" => Self::Mid,
2547            _ => Self::Unknown(value),
2548        })
2549    }
2550}
2551
2552/// The dynamic state of an Order. This is only relevant to TrailingStopLoss Orders, as no other Order type
2553/// has dynamic state.
2554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2555#[serde(rename_all = "camelCase")]
2556pub struct DynamicOrderState {
2557    /// The Order’s ID.
2558    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
2559    pub id: Option<OrderID>,
2560    /// The Order’s calculated trailing stop value.
2561    #[serde(
2562        rename = "trailingStopValue",
2563        default,
2564        skip_serializing_if = "Option::is_none"
2565    )]
2566    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2567    pub trailing_stop_value: Option<Decimal>,
2568    /// The distance between the Trailing Stop Loss Order’s trailingStopValue and the current Market Price. This
2569    /// represents the distance (in price units) of the Order from a triggering price. If the distance could not
2570    /// be determined, this value will not be set.
2571    #[serde(
2572        rename = "triggerDistance",
2573        default,
2574        skip_serializing_if = "Option::is_none"
2575    )]
2576    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2577    pub trigger_distance: Option<Decimal>,
2578    /// True if an exact trigger distance could be calculated. If false, it means the provided trigger distance
2579    /// is a best estimate. If the distance could not be determined, this value will not be set.
2580    #[serde(
2581        rename = "isTriggerDistanceExact",
2582        default,
2583        skip_serializing_if = "Option::is_none"
2584    )]
2585    pub is_trigger_distance_exact: Option<bool>,
2586}
2587
2588/// Representation of many units of an Instrument are available to be traded for both long and short Orders.
2589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2590#[serde(rename_all = "camelCase")]
2591pub struct UnitsAvailableDetails {
2592    /// The units available for long Orders.
2593    #[serde(rename = "long", default, skip_serializing_if = "Option::is_none")]
2594    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2595    pub long: Option<Decimal>,
2596    /// The units available for short Orders.
2597    #[serde(rename = "short", default, skip_serializing_if = "Option::is_none")]
2598    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2599    pub short: Option<Decimal>,
2600}
2601
2602/// Representation of how many units of an Instrument are available to be traded by an Order depending on
2603/// its positionFill option.
2604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2605#[serde(rename_all = "camelCase")]
2606pub struct UnitsAvailable {
2607    /// The number of units that are available to be traded using an Order with a positionFill option of
2608    /// “DEFAULT”. For an Account with hedging enabled, this value will be the same as the “OPEN_ONLY” value.
2609    /// For an Account without hedging enabled, this value will be the same as the “REDUCE_FIRST” value.
2610    #[serde(rename = "default", default, skip_serializing_if = "Option::is_none")]
2611    pub default: Option<UnitsAvailableDetails>,
2612    /// The number of units that may are available to be traded with an Order with a positionFill option of
2613    /// “REDUCE_FIRST”.
2614    #[serde(
2615        rename = "reduceFirst",
2616        default,
2617        skip_serializing_if = "Option::is_none"
2618    )]
2619    pub reduce_first: Option<UnitsAvailableDetails>,
2620    /// The number of units that may are available to be traded with an Order with a positionFill option of
2621    /// “REDUCE_ONLY”.
2622    #[serde(
2623        rename = "reduceOnly",
2624        default,
2625        skip_serializing_if = "Option::is_none"
2626    )]
2627    pub reduce_only: Option<UnitsAvailableDetails>,
2628    /// The number of units that may are available to be traded with an Order with a positionFill option of
2629    /// “OPEN_ONLY”.
2630    #[serde(rename = "openOnly", default, skip_serializing_if = "Option::is_none")]
2631    pub open_only: Option<UnitsAvailableDetails>,
2632}
2633
2634/// Details required by clients creating a Guaranteed Stop Loss Order
2635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2636#[serde(rename_all = "camelCase")]
2637pub struct GuaranteedStopLossOrderEntryData {
2638    /// The minimum distance allowed between the Trade’s fill price and the configured price for guaranteed Stop
2639    /// Loss Orders created for this instrument. Specified in price units.
2640    #[serde(
2641        rename = "minimumDistance",
2642        default,
2643        skip_serializing_if = "Option::is_none"
2644    )]
2645    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2646    pub minimum_distance: Option<Decimal>,
2647    /// The amount that is charged to the account if a guaranteed Stop Loss Order is triggered and filled. The
2648    /// value is in price units and is charged for each unit of the Trade.
2649    #[serde(rename = "premium", default, skip_serializing_if = "Option::is_none")]
2650    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
2651    pub premium: Option<Decimal>,
2652    /// The guaranteed Stop Loss Order level restriction for this instrument.
2653    #[serde(
2654        rename = "levelRestriction",
2655        default,
2656        skip_serializing_if = "Option::is_none"
2657    )]
2658    pub level_restriction: Option<GuaranteedStopLossOrderLevelRestriction>,
2659}