Skip to main content

oanda_rs/models/
account.rs

1//! Account-related models.
2
3use serde::{Deserialize, Serialize};
4
5use super::macros::string_enum;
6use super::transaction::Transaction;
7use super::{
8    AccountId, AccountUnits, CalculatedPositionState, CalculatedTradeState, Currency, DateTime,
9    DecimalNumber, DynamicOrderState, InstrumentName, Order, Position, TradeSummary, TransactionId,
10};
11
12/// Properties related to an Account.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14#[non_exhaustive]
15pub struct AccountProperties {
16    /// The Account's identifier
17    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
18    pub id: Option<AccountId>,
19
20    /// The Account's associated MT4 Account ID. This field will not be present
21    /// if the Account is not an MT4 account.
22    #[serde(rename = "mt4AccountID", skip_serializing_if = "Option::is_none")]
23    pub mt4_account_id: Option<i64>,
24
25    /// The Account's tags
26    #[serde(rename = "tags", default, skip_serializing_if = "Vec::is_empty")]
27    pub tags: Vec<String>,
28}
29
30/// A summary representation of a client's Account. The AccountSummary does not
31/// provide to full specification of pending Orders, open Trades and Positions.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33#[non_exhaustive]
34pub struct AccountSummary {
35    /// The Account's identifier
36    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
37    pub id: Option<AccountId>,
38
39    /// Client-assigned alias for the Account. Only provided if the Account has
40    /// an alias set
41    #[serde(rename = "alias", skip_serializing_if = "Option::is_none")]
42    pub alias: Option<String>,
43
44    /// The home currency of the Account
45    #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
46    pub currency: Option<Currency>,
47
48    /// The current balance of the Account.
49    #[serde(rename = "balance", skip_serializing_if = "Option::is_none")]
50    pub balance: Option<AccountUnits>,
51
52    /// ID of the user that created the Account.
53    #[serde(rename = "createdByUserID", skip_serializing_if = "Option::is_none")]
54    pub created_by_user_id: Option<i64>,
55
56    /// The date/time when the Account was created.
57    #[serde(rename = "createdTime", skip_serializing_if = "Option::is_none")]
58    pub created_time: Option<DateTime>,
59
60    /// The `guaranteedStopLossOrderMode` field.
61    #[serde(
62        rename = "guaranteedStopLossOrderMode",
63        skip_serializing_if = "Option::is_none"
64    )]
65    pub guaranteed_stop_loss_order_mode: Option<GuaranteedStopLossOrderMode>,
66
67    /// The total profit/loss realized over the lifetime of the Account.
68    #[serde(rename = "pl", skip_serializing_if = "Option::is_none")]
69    pub pl: Option<AccountUnits>,
70
71    /// The total realized profit/loss for the Account since it was last reset
72    /// by the client.
73    #[serde(rename = "resettablePL", skip_serializing_if = "Option::is_none")]
74    pub resettable_pl: Option<AccountUnits>,
75
76    /// The date/time that the Account's resettablePL was last reset.
77    #[serde(rename = "resettablePLTime", skip_serializing_if = "Option::is_none")]
78    pub resettable_pl_time: Option<DateTime>,
79
80    /// The total amount of financing paid/collected over the lifetime of the
81    /// Account.
82    #[serde(rename = "financing", skip_serializing_if = "Option::is_none")]
83    pub financing: Option<AccountUnits>,
84
85    /// The total amount of commission paid over the lifetime of the Account.
86    #[serde(rename = "commission", skip_serializing_if = "Option::is_none")]
87    pub commission: Option<AccountUnits>,
88
89    /// The total amount of fees charged over the lifetime of the Account for
90    /// the execution of guaranteed Stop Loss Orders.
91    #[serde(
92        rename = "guaranteedExecutionFees",
93        skip_serializing_if = "Option::is_none"
94    )]
95    pub guaranteed_execution_fees: Option<AccountUnits>,
96
97    /// Client-provided margin rate override for the Account. The effective
98    /// margin rate of the Account is the lesser of this value and the OANDA
99    /// margin rate for the Account's division. This value is only provided if a
100    /// margin rate override exists for the Account.
101    #[serde(rename = "marginRate", skip_serializing_if = "Option::is_none")]
102    pub margin_rate: Option<DecimalNumber>,
103
104    /// The date/time when the Account entered a margin call state. Only
105    /// provided if the Account is in a margin call.
106    #[serde(
107        rename = "marginCallEnterTime",
108        skip_serializing_if = "Option::is_none"
109    )]
110    pub margin_call_enter_time: Option<DateTime>,
111
112    /// The number of times that the Account's current margin call was extended.
113    #[serde(
114        rename = "marginCallExtensionCount",
115        skip_serializing_if = "Option::is_none"
116    )]
117    pub margin_call_extension_count: Option<i64>,
118
119    /// The date/time of the Account's last margin call extension.
120    #[serde(
121        rename = "lastMarginCallExtensionTime",
122        skip_serializing_if = "Option::is_none"
123    )]
124    pub last_margin_call_extension_time: Option<DateTime>,
125
126    /// The number of Trades currently open in the Account.
127    #[serde(rename = "openTradeCount", skip_serializing_if = "Option::is_none")]
128    pub open_trade_count: Option<i64>,
129
130    /// The number of Positions currently open in the Account.
131    #[serde(rename = "openPositionCount", skip_serializing_if = "Option::is_none")]
132    pub open_position_count: Option<i64>,
133
134    /// The number of Orders currently pending in the Account.
135    #[serde(rename = "pendingOrderCount", skip_serializing_if = "Option::is_none")]
136    pub pending_order_count: Option<i64>,
137
138    /// Flag indicating that the Account has hedging enabled.
139    #[serde(rename = "hedgingEnabled", skip_serializing_if = "Option::is_none")]
140    pub hedging_enabled: Option<bool>,
141
142    /// The date/time of the last order that was filled for this account.
143    #[serde(
144        rename = "lastOrderFillTimestamp",
145        skip_serializing_if = "Option::is_none"
146    )]
147    pub last_order_fill_timestamp: Option<DateTime>,
148
149    /// The total unrealized profit/loss for all Trades currently open in the
150    /// Account.
151    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
152    pub unrealized_pl: Option<AccountUnits>,
153
154    /// The net asset value of the Account. Equal to Account balance +
155    /// unrealizedPL.
156    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
157    pub nav: Option<AccountUnits>,
158
159    /// Margin currently used for the Account.
160    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
161    pub margin_used: Option<AccountUnits>,
162
163    /// Margin available for Account currency.
164    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
165    pub margin_available: Option<AccountUnits>,
166
167    /// The value of the Account's open positions represented in the Account's
168    /// home currency.
169    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
170    pub position_value: Option<AccountUnits>,
171
172    /// The Account's margin closeout unrealized PL.
173    #[serde(
174        rename = "marginCloseoutUnrealizedPL",
175        skip_serializing_if = "Option::is_none"
176    )]
177    pub margin_closeout_unrealized_pl: Option<AccountUnits>,
178
179    /// The Account's margin closeout NAV.
180    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
181    pub margin_closeout_nav: Option<AccountUnits>,
182
183    /// The Account's margin closeout margin used.
184    #[serde(
185        rename = "marginCloseoutMarginUsed",
186        skip_serializing_if = "Option::is_none"
187    )]
188    pub margin_closeout_margin_used: Option<AccountUnits>,
189
190    /// The Account's margin closeout percentage. When this value is 1.0 or
191    /// above the Account is in a margin closeout situation.
192    #[serde(
193        rename = "marginCloseoutPercent",
194        skip_serializing_if = "Option::is_none"
195    )]
196    pub margin_closeout_percent: Option<DecimalNumber>,
197
198    /// The value of the Account's open positions as used for margin closeout
199    /// calculations represented in the Account's home currency.
200    #[serde(
201        rename = "marginCloseoutPositionValue",
202        skip_serializing_if = "Option::is_none"
203    )]
204    pub margin_closeout_position_value: Option<DecimalNumber>,
205
206    /// The current WithdrawalLimit for the account which will be zero or a
207    /// positive value indicating how much can be withdrawn from the account.
208    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
209    pub withdrawal_limit: Option<AccountUnits>,
210
211    /// The Account's margin call margin used.
212    #[serde(
213        rename = "marginCallMarginUsed",
214        skip_serializing_if = "Option::is_none"
215    )]
216    pub margin_call_margin_used: Option<AccountUnits>,
217
218    /// The Account's margin call percentage. When this value is 1.0 or above
219    /// the Account is in a margin call situation.
220    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
221    pub margin_call_percent: Option<DecimalNumber>,
222
223    /// The ID of the last Transaction created for the Account.
224    #[serde(rename = "lastTransactionID", skip_serializing_if = "Option::is_none")]
225    pub last_transaction_id: Option<TransactionId>,
226
227    /// The total amount of dividend adjustment paid over the lifetime of the
228    /// Account in the Account's home currency.
229    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
230    pub dividend_adjustment: Option<DecimalNumber>,
231
232    /// The net asset value of the Account inclusive of unsettled amounts. This
233    /// field is returned by the live v20 API but is not present in OANDA's
234    /// official documentation.
235    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
236    pub true_nav: Option<DecimalNumber>,
237
238    /// The total unrealized profit/loss inclusive of unsettled amounts. This
239    /// field is returned by the live v20 API but is not present in OANDA's
240    /// official documentation.
241    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
242    pub true_unrealized_pl: Option<DecimalNumber>,
243
244    /// The date/time of the last dividend adjustment per instrument. This field
245    /// is returned by the live v20 API but is not present in OANDA's official
246    /// documentation.
247    #[serde(
248        rename = "lastDividendAdjustmentTimestamps",
249        default,
250        skip_serializing_if = "Vec::is_empty"
251    )]
252    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
253}
254
255string_enum! {
256    /// The overall behaviour of the Account regarding guaranteed Stop Loss
257    /// Orders.
258    pub enum GuaranteedStopLossOrderMode {
259        Disabled => "DISABLED",
260        Allowed => "ALLOWED",
261        Required => "REQUIRED",
262    }
263}
264
265string_enum! {
266    /// The financing mode of an Account
267    pub enum AccountFinancingMode {
268        NoFinancing => "NO_FINANCING",
269        SecondBySecond => "SECOND_BY_SECOND",
270        Daily => "DAILY",
271        DailyInstrument => "DAILY_INSTRUMENT",
272        SecondBySecondInstrument => "SECOND_BY_SECOND_INSTRUMENT",
273    }
274}
275
276/// The date/time of the last dividend adjustment for a single instrument
277/// (entry of `AccountSummary.lastDividendAdjustmentTimestamps`).
278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
279#[non_exhaustive]
280pub struct DividendAdjustmentTimestamp {
281    /// The instrument of the dividend adjustment.
282    #[serde(rename = "instrument", skip_serializing_if = "Option::is_none")]
283    pub instrument: Option<InstrumentName>,
284
285    /// The date/time of the dividend adjustment.
286    #[serde(rename = "timestamp", skip_serializing_if = "Option::is_none")]
287    pub timestamp: Option<DateTime>,
288}
289
290/// The full details of a client's Account. This includes full open Trade, open
291/// Position and pending Order representation.
292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
293#[non_exhaustive]
294pub struct Account {
295    /// The Account's identifier
296    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
297    pub id: Option<AccountId>,
298
299    /// Client-assigned alias for the Account. Only provided if the Account has
300    /// an alias set
301    #[serde(rename = "alias", skip_serializing_if = "Option::is_none")]
302    pub alias: Option<String>,
303
304    /// The home currency of the Account
305    #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
306    pub currency: Option<Currency>,
307
308    /// The current balance of the Account.
309    #[serde(rename = "balance", skip_serializing_if = "Option::is_none")]
310    pub balance: Option<AccountUnits>,
311
312    /// ID of the user that created the Account.
313    #[serde(rename = "createdByUserID", skip_serializing_if = "Option::is_none")]
314    pub created_by_user_id: Option<i64>,
315
316    /// The date/time when the Account was created.
317    #[serde(rename = "createdTime", skip_serializing_if = "Option::is_none")]
318    pub created_time: Option<DateTime>,
319
320    /// The `guaranteedStopLossOrderMode` field.
321    #[serde(
322        rename = "guaranteedStopLossOrderMode",
323        skip_serializing_if = "Option::is_none"
324    )]
325    pub guaranteed_stop_loss_order_mode: Option<GuaranteedStopLossOrderMode>,
326
327    /// The total profit/loss realized over the lifetime of the Account.
328    #[serde(rename = "pl", skip_serializing_if = "Option::is_none")]
329    pub pl: Option<AccountUnits>,
330
331    /// The total realized profit/loss for the Account since it was last reset
332    /// by the client.
333    #[serde(rename = "resettablePL", skip_serializing_if = "Option::is_none")]
334    pub resettable_pl: Option<AccountUnits>,
335
336    /// The date/time that the Account's resettablePL was last reset.
337    #[serde(rename = "resettablePLTime", skip_serializing_if = "Option::is_none")]
338    pub resettable_pl_time: Option<DateTime>,
339
340    /// The total amount of financing paid/collected over the lifetime of the
341    /// Account.
342    #[serde(rename = "financing", skip_serializing_if = "Option::is_none")]
343    pub financing: Option<AccountUnits>,
344
345    /// The total amount of commission paid over the lifetime of the Account.
346    #[serde(rename = "commission", skip_serializing_if = "Option::is_none")]
347    pub commission: Option<AccountUnits>,
348
349    /// The total amount of fees charged over the lifetime of the Account for
350    /// the execution of guaranteed Stop Loss Orders.
351    #[serde(
352        rename = "guaranteedExecutionFees",
353        skip_serializing_if = "Option::is_none"
354    )]
355    pub guaranteed_execution_fees: Option<AccountUnits>,
356
357    /// Client-provided margin rate override for the Account. The effective
358    /// margin rate of the Account is the lesser of this value and the OANDA
359    /// margin rate for the Account's division. This value is only provided if a
360    /// margin rate override exists for the Account.
361    #[serde(rename = "marginRate", skip_serializing_if = "Option::is_none")]
362    pub margin_rate: Option<DecimalNumber>,
363
364    /// The date/time when the Account entered a margin call state. Only
365    /// provided if the Account is in a margin call.
366    #[serde(
367        rename = "marginCallEnterTime",
368        skip_serializing_if = "Option::is_none"
369    )]
370    pub margin_call_enter_time: Option<DateTime>,
371
372    /// The number of times that the Account's current margin call was extended.
373    #[serde(
374        rename = "marginCallExtensionCount",
375        skip_serializing_if = "Option::is_none"
376    )]
377    pub margin_call_extension_count: Option<i64>,
378
379    /// The date/time of the Account's last margin call extension.
380    #[serde(
381        rename = "lastMarginCallExtensionTime",
382        skip_serializing_if = "Option::is_none"
383    )]
384    pub last_margin_call_extension_time: Option<DateTime>,
385
386    /// The number of Trades currently open in the Account.
387    #[serde(rename = "openTradeCount", skip_serializing_if = "Option::is_none")]
388    pub open_trade_count: Option<i64>,
389
390    /// The number of Positions currently open in the Account.
391    #[serde(rename = "openPositionCount", skip_serializing_if = "Option::is_none")]
392    pub open_position_count: Option<i64>,
393
394    /// The number of Orders currently pending in the Account.
395    #[serde(rename = "pendingOrderCount", skip_serializing_if = "Option::is_none")]
396    pub pending_order_count: Option<i64>,
397
398    /// Flag indicating that the Account has hedging enabled.
399    #[serde(rename = "hedgingEnabled", skip_serializing_if = "Option::is_none")]
400    pub hedging_enabled: Option<bool>,
401
402    /// The date/time of the last order that was filled for this account.
403    #[serde(
404        rename = "lastOrderFillTimestamp",
405        skip_serializing_if = "Option::is_none"
406    )]
407    pub last_order_fill_timestamp: Option<DateTime>,
408
409    /// The total unrealized profit/loss for all Trades currently open in the
410    /// Account.
411    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
412    pub unrealized_pl: Option<AccountUnits>,
413
414    /// The net asset value of the Account. Equal to Account balance +
415    /// unrealizedPL.
416    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
417    pub nav: Option<AccountUnits>,
418
419    /// Margin currently used for the Account.
420    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
421    pub margin_used: Option<AccountUnits>,
422
423    /// Margin available for Account currency.
424    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
425    pub margin_available: Option<AccountUnits>,
426
427    /// The value of the Account's open positions represented in the Account's
428    /// home currency.
429    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
430    pub position_value: Option<AccountUnits>,
431
432    /// The Account's margin closeout unrealized PL.
433    #[serde(
434        rename = "marginCloseoutUnrealizedPL",
435        skip_serializing_if = "Option::is_none"
436    )]
437    pub margin_closeout_unrealized_pl: Option<AccountUnits>,
438
439    /// The Account's margin closeout NAV.
440    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
441    pub margin_closeout_nav: Option<AccountUnits>,
442
443    /// The Account's margin closeout margin used.
444    #[serde(
445        rename = "marginCloseoutMarginUsed",
446        skip_serializing_if = "Option::is_none"
447    )]
448    pub margin_closeout_margin_used: Option<AccountUnits>,
449
450    /// The Account's margin closeout percentage. When this value is 1.0 or
451    /// above the Account is in a margin closeout situation.
452    #[serde(
453        rename = "marginCloseoutPercent",
454        skip_serializing_if = "Option::is_none"
455    )]
456    pub margin_closeout_percent: Option<DecimalNumber>,
457
458    /// The value of the Account's open positions as used for margin closeout
459    /// calculations represented in the Account's home currency.
460    #[serde(
461        rename = "marginCloseoutPositionValue",
462        skip_serializing_if = "Option::is_none"
463    )]
464    pub margin_closeout_position_value: Option<DecimalNumber>,
465
466    /// The current WithdrawalLimit for the account which will be zero or a
467    /// positive value indicating how much can be withdrawn from the account.
468    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
469    pub withdrawal_limit: Option<AccountUnits>,
470
471    /// The Account's margin call margin used.
472    #[serde(
473        rename = "marginCallMarginUsed",
474        skip_serializing_if = "Option::is_none"
475    )]
476    pub margin_call_margin_used: Option<AccountUnits>,
477
478    /// The Account's margin call percentage. When this value is 1.0 or above
479    /// the Account is in a margin call situation.
480    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
481    pub margin_call_percent: Option<DecimalNumber>,
482
483    /// The ID of the last Transaction created for the Account.
484    #[serde(rename = "lastTransactionID", skip_serializing_if = "Option::is_none")]
485    pub last_transaction_id: Option<TransactionId>,
486
487    /// The details of the Trades currently open in the Account.
488    #[serde(rename = "trades", default, skip_serializing_if = "Vec::is_empty")]
489    pub trades: Vec<TradeSummary>,
490
491    /// The details all Account Positions.
492    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
493    pub positions: Vec<Position>,
494
495    /// The details of the Orders currently pending in the Account.
496    #[serde(rename = "orders", default, skip_serializing_if = "Vec::is_empty")]
497    pub orders: Vec<Order>,
498
499    /// The total amount of dividend adjustment paid over the lifetime of the
500    /// Account in the Account's home currency.
501    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
502    pub dividend_adjustment: Option<DecimalNumber>,
503
504    /// The net asset value of the Account inclusive of unsettled amounts. This
505    /// field is returned by the live v20 API but is not present in OANDA's
506    /// official documentation.
507    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
508    pub true_nav: Option<DecimalNumber>,
509
510    /// The total unrealized profit/loss inclusive of unsettled amounts. This
511    /// field is returned by the live v20 API but is not present in OANDA's
512    /// official documentation.
513    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
514    pub true_unrealized_pl: Option<DecimalNumber>,
515
516    /// The date/time of the last dividend adjustment per instrument. This field
517    /// is returned by the live v20 API but is not present in OANDA's official
518    /// documentation.
519    #[serde(
520        rename = "lastDividendAdjustmentTimestamps",
521        default,
522        skip_serializing_if = "Vec::is_empty"
523    )]
524    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
525}
526
527/// An AccountChanges Object is used to represent the changes to an Account's
528/// Orders, Trades and Positions since a specified Account TransactionID in the
529/// past.
530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
531#[non_exhaustive]
532pub struct AccountChanges {
533    /// The Orders created. These Orders may have been filled, cancelled or
534    /// triggered in the same period.
535    #[serde(
536        rename = "ordersCreated",
537        default,
538        skip_serializing_if = "Vec::is_empty"
539    )]
540    pub orders_created: Vec<Order>,
541
542    /// The Orders cancelled.
543    #[serde(
544        rename = "ordersCancelled",
545        default,
546        skip_serializing_if = "Vec::is_empty"
547    )]
548    pub orders_cancelled: Vec<Order>,
549
550    /// The Orders filled.
551    #[serde(
552        rename = "ordersFilled",
553        default,
554        skip_serializing_if = "Vec::is_empty"
555    )]
556    pub orders_filled: Vec<Order>,
557
558    /// The Orders triggered.
559    #[serde(
560        rename = "ordersTriggered",
561        default,
562        skip_serializing_if = "Vec::is_empty"
563    )]
564    pub orders_triggered: Vec<Order>,
565
566    /// The Trades opened.
567    #[serde(
568        rename = "tradesOpened",
569        default,
570        skip_serializing_if = "Vec::is_empty"
571    )]
572    pub trades_opened: Vec<TradeSummary>,
573
574    /// The Trades reduced.
575    #[serde(
576        rename = "tradesReduced",
577        default,
578        skip_serializing_if = "Vec::is_empty"
579    )]
580    pub trades_reduced: Vec<TradeSummary>,
581
582    /// The Trades closed.
583    #[serde(
584        rename = "tradesClosed",
585        default,
586        skip_serializing_if = "Vec::is_empty"
587    )]
588    pub trades_closed: Vec<TradeSummary>,
589
590    /// The Positions changed.
591    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
592    pub positions: Vec<Position>,
593
594    /// The Transactions that have been generated.
595    #[serde(
596        rename = "transactions",
597        default,
598        skip_serializing_if = "Vec::is_empty"
599    )]
600    pub transactions: Vec<Transaction>,
601}
602
603/// An AccountState Object is used to represent an Account's current price-
604/// dependent state. Price-dependent Account state is dependent on OANDA's
605/// current Prices, and includes things like unrealized PL, NAV and Trailing
606/// Stop Loss Order state.
607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
608#[non_exhaustive]
609pub struct AccountChangesState {
610    /// The total unrealized profit/loss for all Trades currently open in the
611    /// Account.
612    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
613    pub unrealized_pl: Option<AccountUnits>,
614
615    /// The net asset value of the Account. Equal to Account balance +
616    /// unrealizedPL.
617    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
618    pub nav: Option<AccountUnits>,
619
620    /// Margin currently used for the Account.
621    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
622    pub margin_used: Option<AccountUnits>,
623
624    /// Margin available for Account currency.
625    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
626    pub margin_available: Option<AccountUnits>,
627
628    /// The value of the Account's open positions represented in the Account's
629    /// home currency.
630    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
631    pub position_value: Option<AccountUnits>,
632
633    /// The Account's margin closeout unrealized PL.
634    #[serde(
635        rename = "marginCloseoutUnrealizedPL",
636        skip_serializing_if = "Option::is_none"
637    )]
638    pub margin_closeout_unrealized_pl: Option<AccountUnits>,
639
640    /// The Account's margin closeout NAV.
641    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
642    pub margin_closeout_nav: Option<AccountUnits>,
643
644    /// The Account's margin closeout margin used.
645    #[serde(
646        rename = "marginCloseoutMarginUsed",
647        skip_serializing_if = "Option::is_none"
648    )]
649    pub margin_closeout_margin_used: Option<AccountUnits>,
650
651    /// The Account's margin closeout percentage. When this value is 1.0 or
652    /// above the Account is in a margin closeout situation.
653    #[serde(
654        rename = "marginCloseoutPercent",
655        skip_serializing_if = "Option::is_none"
656    )]
657    pub margin_closeout_percent: Option<DecimalNumber>,
658
659    /// The value of the Account's open positions as used for margin closeout
660    /// calculations represented in the Account's home currency.
661    #[serde(
662        rename = "marginCloseoutPositionValue",
663        skip_serializing_if = "Option::is_none"
664    )]
665    pub margin_closeout_position_value: Option<DecimalNumber>,
666
667    /// The current WithdrawalLimit for the account which will be zero or a
668    /// positive value indicating how much can be withdrawn from the account.
669    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
670    pub withdrawal_limit: Option<AccountUnits>,
671
672    /// The Account's margin call margin used.
673    #[serde(
674        rename = "marginCallMarginUsed",
675        skip_serializing_if = "Option::is_none"
676    )]
677    pub margin_call_margin_used: Option<AccountUnits>,
678
679    /// The Account's margin call percentage. When this value is 1.0 or above
680    /// the Account is in a margin call situation.
681    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
682    pub margin_call_percent: Option<DecimalNumber>,
683
684    /// The price-dependent state of each pending Order in the Account.
685    #[serde(rename = "orders", default, skip_serializing_if = "Vec::is_empty")]
686    pub orders: Vec<DynamicOrderState>,
687
688    /// The price-dependent state for each open Trade in the Account.
689    #[serde(rename = "trades", default, skip_serializing_if = "Vec::is_empty")]
690    pub trades: Vec<CalculatedTradeState>,
691
692    /// The price-dependent state for each open Position in the Account.
693    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
694    pub positions: Vec<CalculatedPositionState>,
695
696    /// The net asset value of the Account inclusive of unsettled amounts. This
697    /// field is returned by the live v20 API but is not present in OANDA's
698    /// official documentation.
699    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
700    pub true_nav: Option<DecimalNumber>,
701
702    /// The total unrealized profit/loss inclusive of unsettled amounts. This
703    /// field is returned by the live v20 API but is not present in OANDA's
704    /// official documentation.
705    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
706    pub true_unrealized_pl: Option<DecimalNumber>,
707}
708
709/// The dynamically calculated state of a client's Account.
710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
711#[non_exhaustive]
712pub struct CalculatedAccountState {
713    /// The total unrealized profit/loss for all Trades currently open in the
714    /// Account.
715    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
716    pub unrealized_pl: Option<AccountUnits>,
717
718    /// The net asset value of the Account. Equal to Account balance +
719    /// unrealizedPL.
720    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
721    pub nav: Option<AccountUnits>,
722
723    /// Margin currently used for the Account.
724    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
725    pub margin_used: Option<AccountUnits>,
726
727    /// Margin available for Account currency.
728    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
729    pub margin_available: Option<AccountUnits>,
730
731    /// The value of the Account's open positions represented in the Account's
732    /// home currency.
733    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
734    pub position_value: Option<AccountUnits>,
735
736    /// The Account's margin closeout unrealized PL.
737    #[serde(
738        rename = "marginCloseoutUnrealizedPL",
739        skip_serializing_if = "Option::is_none"
740    )]
741    pub margin_closeout_unrealized_pl: Option<AccountUnits>,
742
743    /// The Account's margin closeout NAV.
744    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
745    pub margin_closeout_nav: Option<AccountUnits>,
746
747    /// The Account's margin closeout margin used.
748    #[serde(
749        rename = "marginCloseoutMarginUsed",
750        skip_serializing_if = "Option::is_none"
751    )]
752    pub margin_closeout_margin_used: Option<AccountUnits>,
753
754    /// The Account's margin closeout percentage. When this value is 1.0 or
755    /// above the Account is in a margin closeout situation.
756    #[serde(
757        rename = "marginCloseoutPercent",
758        skip_serializing_if = "Option::is_none"
759    )]
760    pub margin_closeout_percent: Option<DecimalNumber>,
761
762    /// The value of the Account's open positions as used for margin closeout
763    /// calculations represented in the Account's home currency.
764    #[serde(
765        rename = "marginCloseoutPositionValue",
766        skip_serializing_if = "Option::is_none"
767    )]
768    pub margin_closeout_position_value: Option<DecimalNumber>,
769
770    /// The current WithdrawalLimit for the account which will be zero or a
771    /// positive value indicating how much can be withdrawn from the account.
772    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
773    pub withdrawal_limit: Option<AccountUnits>,
774
775    /// The Account's margin call margin used.
776    #[serde(
777        rename = "marginCallMarginUsed",
778        skip_serializing_if = "Option::is_none"
779    )]
780    pub margin_call_margin_used: Option<AccountUnits>,
781
782    /// The Account's margin call percentage. When this value is 1.0 or above
783    /// the Account is in a margin call situation.
784    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
785    pub margin_call_percent: Option<DecimalNumber>,
786
787    /// The total amount of dividend adjustment paid over the lifetime of the
788    /// Account in the Account's home currency.
789    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
790    pub dividend_adjustment: Option<DecimalNumber>,
791
792    /// The net asset value of the Account inclusive of unsettled amounts. This
793    /// field is returned by the live v20 API but is not present in OANDA's
794    /// official documentation.
795    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
796    pub true_nav: Option<DecimalNumber>,
797
798    /// The total unrealized profit/loss inclusive of unsettled amounts. This
799    /// field is returned by the live v20 API but is not present in OANDA's
800    /// official documentation.
801    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
802    pub true_unrealized_pl: Option<DecimalNumber>,
803
804    /// The date/time of the last dividend adjustment per instrument. This field
805    /// is returned by the live v20 API but is not present in OANDA's official
806    /// documentation.
807    #[serde(
808        rename = "lastDividendAdjustmentTimestamps",
809        default,
810        skip_serializing_if = "Vec::is_empty"
811    )]
812    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
813}