oanda-rs 0.1.0

Async Rust SDK for the OANDA v20 REST and streaming API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
//! Account-related models.

use serde::{Deserialize, Serialize};

use super::macros::string_enum;
use super::transaction::Transaction;
use super::{
    AccountId, AccountUnits, CalculatedPositionState, CalculatedTradeState, Currency, DateTime,
    DecimalNumber, DynamicOrderState, InstrumentName, Order, Position, TradeSummary, TransactionId,
};

/// Properties related to an Account.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AccountProperties {
    /// The Account's identifier
    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
    pub id: Option<AccountId>,

    /// The Account's associated MT4 Account ID. This field will not be present
    /// if the Account is not an MT4 account.
    #[serde(rename = "mt4AccountID", skip_serializing_if = "Option::is_none")]
    pub mt4_account_id: Option<i64>,

    /// The Account's tags
    #[serde(rename = "tags", default, skip_serializing_if = "Vec::is_empty")]
    pub tags: Vec<String>,
}

/// A summary representation of a client's Account. The AccountSummary does not
/// provide to full specification of pending Orders, open Trades and Positions.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AccountSummary {
    /// The Account's identifier
    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
    pub id: Option<AccountId>,

    /// Client-assigned alias for the Account. Only provided if the Account has
    /// an alias set
    #[serde(rename = "alias", skip_serializing_if = "Option::is_none")]
    pub alias: Option<String>,

    /// The home currency of the Account
    #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
    pub currency: Option<Currency>,

    /// The current balance of the Account.
    #[serde(rename = "balance", skip_serializing_if = "Option::is_none")]
    pub balance: Option<AccountUnits>,

    /// ID of the user that created the Account.
    #[serde(rename = "createdByUserID", skip_serializing_if = "Option::is_none")]
    pub created_by_user_id: Option<i64>,

    /// The date/time when the Account was created.
    #[serde(rename = "createdTime", skip_serializing_if = "Option::is_none")]
    pub created_time: Option<DateTime>,

    /// The `guaranteedStopLossOrderMode` field.
    #[serde(
        rename = "guaranteedStopLossOrderMode",
        skip_serializing_if = "Option::is_none"
    )]
    pub guaranteed_stop_loss_order_mode: Option<GuaranteedStopLossOrderMode>,

    /// The total profit/loss realized over the lifetime of the Account.
    #[serde(rename = "pl", skip_serializing_if = "Option::is_none")]
    pub pl: Option<AccountUnits>,

    /// The total realized profit/loss for the Account since it was last reset
    /// by the client.
    #[serde(rename = "resettablePL", skip_serializing_if = "Option::is_none")]
    pub resettable_pl: Option<AccountUnits>,

    /// The date/time that the Account's resettablePL was last reset.
    #[serde(rename = "resettablePLTime", skip_serializing_if = "Option::is_none")]
    pub resettable_pl_time: Option<DateTime>,

    /// The total amount of financing paid/collected over the lifetime of the
    /// Account.
    #[serde(rename = "financing", skip_serializing_if = "Option::is_none")]
    pub financing: Option<AccountUnits>,

    /// The total amount of commission paid over the lifetime of the Account.
    #[serde(rename = "commission", skip_serializing_if = "Option::is_none")]
    pub commission: Option<AccountUnits>,

    /// The total amount of fees charged over the lifetime of the Account for
    /// the execution of guaranteed Stop Loss Orders.
    #[serde(
        rename = "guaranteedExecutionFees",
        skip_serializing_if = "Option::is_none"
    )]
    pub guaranteed_execution_fees: Option<AccountUnits>,

    /// Client-provided margin rate override for the Account. The effective
    /// margin rate of the Account is the lesser of this value and the OANDA
    /// margin rate for the Account's division. This value is only provided if a
    /// margin rate override exists for the Account.
    #[serde(rename = "marginRate", skip_serializing_if = "Option::is_none")]
    pub margin_rate: Option<DecimalNumber>,

    /// The date/time when the Account entered a margin call state. Only
    /// provided if the Account is in a margin call.
    #[serde(
        rename = "marginCallEnterTime",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_enter_time: Option<DateTime>,

    /// The number of times that the Account's current margin call was extended.
    #[serde(
        rename = "marginCallExtensionCount",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_extension_count: Option<i64>,

    /// The date/time of the Account's last margin call extension.
    #[serde(
        rename = "lastMarginCallExtensionTime",
        skip_serializing_if = "Option::is_none"
    )]
    pub last_margin_call_extension_time: Option<DateTime>,

    /// The number of Trades currently open in the Account.
    #[serde(rename = "openTradeCount", skip_serializing_if = "Option::is_none")]
    pub open_trade_count: Option<i64>,

    /// The number of Positions currently open in the Account.
    #[serde(rename = "openPositionCount", skip_serializing_if = "Option::is_none")]
    pub open_position_count: Option<i64>,

    /// The number of Orders currently pending in the Account.
    #[serde(rename = "pendingOrderCount", skip_serializing_if = "Option::is_none")]
    pub pending_order_count: Option<i64>,

    /// Flag indicating that the Account has hedging enabled.
    #[serde(rename = "hedgingEnabled", skip_serializing_if = "Option::is_none")]
    pub hedging_enabled: Option<bool>,

    /// The date/time of the last order that was filled for this account.
    #[serde(
        rename = "lastOrderFillTimestamp",
        skip_serializing_if = "Option::is_none"
    )]
    pub last_order_fill_timestamp: Option<DateTime>,

    /// The total unrealized profit/loss for all Trades currently open in the
    /// Account.
    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
    pub unrealized_pl: Option<AccountUnits>,

    /// The net asset value of the Account. Equal to Account balance +
    /// unrealizedPL.
    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
    pub nav: Option<AccountUnits>,

    /// Margin currently used for the Account.
    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
    pub margin_used: Option<AccountUnits>,

    /// Margin available for Account currency.
    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
    pub margin_available: Option<AccountUnits>,

    /// The value of the Account's open positions represented in the Account's
    /// home currency.
    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
    pub position_value: Option<AccountUnits>,

    /// The Account's margin closeout unrealized PL.
    #[serde(
        rename = "marginCloseoutUnrealizedPL",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_unrealized_pl: Option<AccountUnits>,

    /// The Account's margin closeout NAV.
    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
    pub margin_closeout_nav: Option<AccountUnits>,

    /// The Account's margin closeout margin used.
    #[serde(
        rename = "marginCloseoutMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_margin_used: Option<AccountUnits>,

    /// The Account's margin closeout percentage. When this value is 1.0 or
    /// above the Account is in a margin closeout situation.
    #[serde(
        rename = "marginCloseoutPercent",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_percent: Option<DecimalNumber>,

    /// The value of the Account's open positions as used for margin closeout
    /// calculations represented in the Account's home currency.
    #[serde(
        rename = "marginCloseoutPositionValue",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_position_value: Option<DecimalNumber>,

    /// The current WithdrawalLimit for the account which will be zero or a
    /// positive value indicating how much can be withdrawn from the account.
    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
    pub withdrawal_limit: Option<AccountUnits>,

    /// The Account's margin call margin used.
    #[serde(
        rename = "marginCallMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_margin_used: Option<AccountUnits>,

    /// The Account's margin call percentage. When this value is 1.0 or above
    /// the Account is in a margin call situation.
    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
    pub margin_call_percent: Option<DecimalNumber>,

    /// The ID of the last Transaction created for the Account.
    #[serde(rename = "lastTransactionID", skip_serializing_if = "Option::is_none")]
    pub last_transaction_id: Option<TransactionId>,

    /// The total amount of dividend adjustment paid over the lifetime of the
    /// Account in the Account's home currency.
    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
    pub dividend_adjustment: Option<DecimalNumber>,

    /// The net asset value of the Account inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
    pub true_nav: Option<DecimalNumber>,

    /// The total unrealized profit/loss inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
    pub true_unrealized_pl: Option<DecimalNumber>,

    /// The date/time of the last dividend adjustment per instrument. This field
    /// is returned by the live v20 API but is not present in OANDA's official
    /// documentation.
    #[serde(
        rename = "lastDividendAdjustmentTimestamps",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
}

string_enum! {
    /// The overall behaviour of the Account regarding guaranteed Stop Loss
    /// Orders.
    pub enum GuaranteedStopLossOrderMode {
        Disabled => "DISABLED",
        Allowed => "ALLOWED",
        Required => "REQUIRED",
    }
}

string_enum! {
    /// The financing mode of an Account
    pub enum AccountFinancingMode {
        NoFinancing => "NO_FINANCING",
        SecondBySecond => "SECOND_BY_SECOND",
        Daily => "DAILY",
        DailyInstrument => "DAILY_INSTRUMENT",
        SecondBySecondInstrument => "SECOND_BY_SECOND_INSTRUMENT",
    }
}

/// The date/time of the last dividend adjustment for a single instrument
/// (entry of `AccountSummary.lastDividendAdjustmentTimestamps`).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DividendAdjustmentTimestamp {
    /// The instrument of the dividend adjustment.
    #[serde(rename = "instrument", skip_serializing_if = "Option::is_none")]
    pub instrument: Option<InstrumentName>,

    /// The date/time of the dividend adjustment.
    #[serde(rename = "timestamp", skip_serializing_if = "Option::is_none")]
    pub timestamp: Option<DateTime>,
}

/// The full details of a client's Account. This includes full open Trade, open
/// Position and pending Order representation.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Account {
    /// The Account's identifier
    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
    pub id: Option<AccountId>,

    /// Client-assigned alias for the Account. Only provided if the Account has
    /// an alias set
    #[serde(rename = "alias", skip_serializing_if = "Option::is_none")]
    pub alias: Option<String>,

    /// The home currency of the Account
    #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
    pub currency: Option<Currency>,

    /// The current balance of the Account.
    #[serde(rename = "balance", skip_serializing_if = "Option::is_none")]
    pub balance: Option<AccountUnits>,

    /// ID of the user that created the Account.
    #[serde(rename = "createdByUserID", skip_serializing_if = "Option::is_none")]
    pub created_by_user_id: Option<i64>,

    /// The date/time when the Account was created.
    #[serde(rename = "createdTime", skip_serializing_if = "Option::is_none")]
    pub created_time: Option<DateTime>,

    /// The `guaranteedStopLossOrderMode` field.
    #[serde(
        rename = "guaranteedStopLossOrderMode",
        skip_serializing_if = "Option::is_none"
    )]
    pub guaranteed_stop_loss_order_mode: Option<GuaranteedStopLossOrderMode>,

    /// The total profit/loss realized over the lifetime of the Account.
    #[serde(rename = "pl", skip_serializing_if = "Option::is_none")]
    pub pl: Option<AccountUnits>,

    /// The total realized profit/loss for the Account since it was last reset
    /// by the client.
    #[serde(rename = "resettablePL", skip_serializing_if = "Option::is_none")]
    pub resettable_pl: Option<AccountUnits>,

    /// The date/time that the Account's resettablePL was last reset.
    #[serde(rename = "resettablePLTime", skip_serializing_if = "Option::is_none")]
    pub resettable_pl_time: Option<DateTime>,

    /// The total amount of financing paid/collected over the lifetime of the
    /// Account.
    #[serde(rename = "financing", skip_serializing_if = "Option::is_none")]
    pub financing: Option<AccountUnits>,

    /// The total amount of commission paid over the lifetime of the Account.
    #[serde(rename = "commission", skip_serializing_if = "Option::is_none")]
    pub commission: Option<AccountUnits>,

    /// The total amount of fees charged over the lifetime of the Account for
    /// the execution of guaranteed Stop Loss Orders.
    #[serde(
        rename = "guaranteedExecutionFees",
        skip_serializing_if = "Option::is_none"
    )]
    pub guaranteed_execution_fees: Option<AccountUnits>,

    /// Client-provided margin rate override for the Account. The effective
    /// margin rate of the Account is the lesser of this value and the OANDA
    /// margin rate for the Account's division. This value is only provided if a
    /// margin rate override exists for the Account.
    #[serde(rename = "marginRate", skip_serializing_if = "Option::is_none")]
    pub margin_rate: Option<DecimalNumber>,

    /// The date/time when the Account entered a margin call state. Only
    /// provided if the Account is in a margin call.
    #[serde(
        rename = "marginCallEnterTime",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_enter_time: Option<DateTime>,

    /// The number of times that the Account's current margin call was extended.
    #[serde(
        rename = "marginCallExtensionCount",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_extension_count: Option<i64>,

    /// The date/time of the Account's last margin call extension.
    #[serde(
        rename = "lastMarginCallExtensionTime",
        skip_serializing_if = "Option::is_none"
    )]
    pub last_margin_call_extension_time: Option<DateTime>,

    /// The number of Trades currently open in the Account.
    #[serde(rename = "openTradeCount", skip_serializing_if = "Option::is_none")]
    pub open_trade_count: Option<i64>,

    /// The number of Positions currently open in the Account.
    #[serde(rename = "openPositionCount", skip_serializing_if = "Option::is_none")]
    pub open_position_count: Option<i64>,

    /// The number of Orders currently pending in the Account.
    #[serde(rename = "pendingOrderCount", skip_serializing_if = "Option::is_none")]
    pub pending_order_count: Option<i64>,

    /// Flag indicating that the Account has hedging enabled.
    #[serde(rename = "hedgingEnabled", skip_serializing_if = "Option::is_none")]
    pub hedging_enabled: Option<bool>,

    /// The date/time of the last order that was filled for this account.
    #[serde(
        rename = "lastOrderFillTimestamp",
        skip_serializing_if = "Option::is_none"
    )]
    pub last_order_fill_timestamp: Option<DateTime>,

    /// The total unrealized profit/loss for all Trades currently open in the
    /// Account.
    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
    pub unrealized_pl: Option<AccountUnits>,

    /// The net asset value of the Account. Equal to Account balance +
    /// unrealizedPL.
    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
    pub nav: Option<AccountUnits>,

    /// Margin currently used for the Account.
    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
    pub margin_used: Option<AccountUnits>,

    /// Margin available for Account currency.
    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
    pub margin_available: Option<AccountUnits>,

    /// The value of the Account's open positions represented in the Account's
    /// home currency.
    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
    pub position_value: Option<AccountUnits>,

    /// The Account's margin closeout unrealized PL.
    #[serde(
        rename = "marginCloseoutUnrealizedPL",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_unrealized_pl: Option<AccountUnits>,

    /// The Account's margin closeout NAV.
    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
    pub margin_closeout_nav: Option<AccountUnits>,

    /// The Account's margin closeout margin used.
    #[serde(
        rename = "marginCloseoutMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_margin_used: Option<AccountUnits>,

    /// The Account's margin closeout percentage. When this value is 1.0 or
    /// above the Account is in a margin closeout situation.
    #[serde(
        rename = "marginCloseoutPercent",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_percent: Option<DecimalNumber>,

    /// The value of the Account's open positions as used for margin closeout
    /// calculations represented in the Account's home currency.
    #[serde(
        rename = "marginCloseoutPositionValue",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_position_value: Option<DecimalNumber>,

    /// The current WithdrawalLimit for the account which will be zero or a
    /// positive value indicating how much can be withdrawn from the account.
    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
    pub withdrawal_limit: Option<AccountUnits>,

    /// The Account's margin call margin used.
    #[serde(
        rename = "marginCallMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_margin_used: Option<AccountUnits>,

    /// The Account's margin call percentage. When this value is 1.0 or above
    /// the Account is in a margin call situation.
    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
    pub margin_call_percent: Option<DecimalNumber>,

    /// The ID of the last Transaction created for the Account.
    #[serde(rename = "lastTransactionID", skip_serializing_if = "Option::is_none")]
    pub last_transaction_id: Option<TransactionId>,

    /// The details of the Trades currently open in the Account.
    #[serde(rename = "trades", default, skip_serializing_if = "Vec::is_empty")]
    pub trades: Vec<TradeSummary>,

    /// The details all Account Positions.
    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
    pub positions: Vec<Position>,

    /// The details of the Orders currently pending in the Account.
    #[serde(rename = "orders", default, skip_serializing_if = "Vec::is_empty")]
    pub orders: Vec<Order>,

    /// The total amount of dividend adjustment paid over the lifetime of the
    /// Account in the Account's home currency.
    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
    pub dividend_adjustment: Option<DecimalNumber>,

    /// The net asset value of the Account inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
    pub true_nav: Option<DecimalNumber>,

    /// The total unrealized profit/loss inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
    pub true_unrealized_pl: Option<DecimalNumber>,

    /// The date/time of the last dividend adjustment per instrument. This field
    /// is returned by the live v20 API but is not present in OANDA's official
    /// documentation.
    #[serde(
        rename = "lastDividendAdjustmentTimestamps",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
}

/// An AccountChanges Object is used to represent the changes to an Account's
/// Orders, Trades and Positions since a specified Account TransactionID in the
/// past.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AccountChanges {
    /// The Orders created. These Orders may have been filled, cancelled or
    /// triggered in the same period.
    #[serde(
        rename = "ordersCreated",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub orders_created: Vec<Order>,

    /// The Orders cancelled.
    #[serde(
        rename = "ordersCancelled",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub orders_cancelled: Vec<Order>,

    /// The Orders filled.
    #[serde(
        rename = "ordersFilled",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub orders_filled: Vec<Order>,

    /// The Orders triggered.
    #[serde(
        rename = "ordersTriggered",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub orders_triggered: Vec<Order>,

    /// The Trades opened.
    #[serde(
        rename = "tradesOpened",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub trades_opened: Vec<TradeSummary>,

    /// The Trades reduced.
    #[serde(
        rename = "tradesReduced",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub trades_reduced: Vec<TradeSummary>,

    /// The Trades closed.
    #[serde(
        rename = "tradesClosed",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub trades_closed: Vec<TradeSummary>,

    /// The Positions changed.
    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
    pub positions: Vec<Position>,

    /// The Transactions that have been generated.
    #[serde(
        rename = "transactions",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub transactions: Vec<Transaction>,
}

/// An AccountState Object is used to represent an Account's current price-
/// dependent state. Price-dependent Account state is dependent on OANDA's
/// current Prices, and includes things like unrealized PL, NAV and Trailing
/// Stop Loss Order state.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AccountChangesState {
    /// The total unrealized profit/loss for all Trades currently open in the
    /// Account.
    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
    pub unrealized_pl: Option<AccountUnits>,

    /// The net asset value of the Account. Equal to Account balance +
    /// unrealizedPL.
    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
    pub nav: Option<AccountUnits>,

    /// Margin currently used for the Account.
    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
    pub margin_used: Option<AccountUnits>,

    /// Margin available for Account currency.
    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
    pub margin_available: Option<AccountUnits>,

    /// The value of the Account's open positions represented in the Account's
    /// home currency.
    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
    pub position_value: Option<AccountUnits>,

    /// The Account's margin closeout unrealized PL.
    #[serde(
        rename = "marginCloseoutUnrealizedPL",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_unrealized_pl: Option<AccountUnits>,

    /// The Account's margin closeout NAV.
    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
    pub margin_closeout_nav: Option<AccountUnits>,

    /// The Account's margin closeout margin used.
    #[serde(
        rename = "marginCloseoutMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_margin_used: Option<AccountUnits>,

    /// The Account's margin closeout percentage. When this value is 1.0 or
    /// above the Account is in a margin closeout situation.
    #[serde(
        rename = "marginCloseoutPercent",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_percent: Option<DecimalNumber>,

    /// The value of the Account's open positions as used for margin closeout
    /// calculations represented in the Account's home currency.
    #[serde(
        rename = "marginCloseoutPositionValue",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_position_value: Option<DecimalNumber>,

    /// The current WithdrawalLimit for the account which will be zero or a
    /// positive value indicating how much can be withdrawn from the account.
    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
    pub withdrawal_limit: Option<AccountUnits>,

    /// The Account's margin call margin used.
    #[serde(
        rename = "marginCallMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_margin_used: Option<AccountUnits>,

    /// The Account's margin call percentage. When this value is 1.0 or above
    /// the Account is in a margin call situation.
    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
    pub margin_call_percent: Option<DecimalNumber>,

    /// The price-dependent state of each pending Order in the Account.
    #[serde(rename = "orders", default, skip_serializing_if = "Vec::is_empty")]
    pub orders: Vec<DynamicOrderState>,

    /// The price-dependent state for each open Trade in the Account.
    #[serde(rename = "trades", default, skip_serializing_if = "Vec::is_empty")]
    pub trades: Vec<CalculatedTradeState>,

    /// The price-dependent state for each open Position in the Account.
    #[serde(rename = "positions", default, skip_serializing_if = "Vec::is_empty")]
    pub positions: Vec<CalculatedPositionState>,

    /// The net asset value of the Account inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
    pub true_nav: Option<DecimalNumber>,

    /// The total unrealized profit/loss inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
    pub true_unrealized_pl: Option<DecimalNumber>,
}

/// The dynamically calculated state of a client's Account.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CalculatedAccountState {
    /// The total unrealized profit/loss for all Trades currently open in the
    /// Account.
    #[serde(rename = "unrealizedPL", skip_serializing_if = "Option::is_none")]
    pub unrealized_pl: Option<AccountUnits>,

    /// The net asset value of the Account. Equal to Account balance +
    /// unrealizedPL.
    #[serde(rename = "NAV", skip_serializing_if = "Option::is_none")]
    pub nav: Option<AccountUnits>,

    /// Margin currently used for the Account.
    #[serde(rename = "marginUsed", skip_serializing_if = "Option::is_none")]
    pub margin_used: Option<AccountUnits>,

    /// Margin available for Account currency.
    #[serde(rename = "marginAvailable", skip_serializing_if = "Option::is_none")]
    pub margin_available: Option<AccountUnits>,

    /// The value of the Account's open positions represented in the Account's
    /// home currency.
    #[serde(rename = "positionValue", skip_serializing_if = "Option::is_none")]
    pub position_value: Option<AccountUnits>,

    /// The Account's margin closeout unrealized PL.
    #[serde(
        rename = "marginCloseoutUnrealizedPL",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_unrealized_pl: Option<AccountUnits>,

    /// The Account's margin closeout NAV.
    #[serde(rename = "marginCloseoutNAV", skip_serializing_if = "Option::is_none")]
    pub margin_closeout_nav: Option<AccountUnits>,

    /// The Account's margin closeout margin used.
    #[serde(
        rename = "marginCloseoutMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_margin_used: Option<AccountUnits>,

    /// The Account's margin closeout percentage. When this value is 1.0 or
    /// above the Account is in a margin closeout situation.
    #[serde(
        rename = "marginCloseoutPercent",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_percent: Option<DecimalNumber>,

    /// The value of the Account's open positions as used for margin closeout
    /// calculations represented in the Account's home currency.
    #[serde(
        rename = "marginCloseoutPositionValue",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_closeout_position_value: Option<DecimalNumber>,

    /// The current WithdrawalLimit for the account which will be zero or a
    /// positive value indicating how much can be withdrawn from the account.
    #[serde(rename = "withdrawalLimit", skip_serializing_if = "Option::is_none")]
    pub withdrawal_limit: Option<AccountUnits>,

    /// The Account's margin call margin used.
    #[serde(
        rename = "marginCallMarginUsed",
        skip_serializing_if = "Option::is_none"
    )]
    pub margin_call_margin_used: Option<AccountUnits>,

    /// The Account's margin call percentage. When this value is 1.0 or above
    /// the Account is in a margin call situation.
    #[serde(rename = "marginCallPercent", skip_serializing_if = "Option::is_none")]
    pub margin_call_percent: Option<DecimalNumber>,

    /// The total amount of dividend adjustment paid over the lifetime of the
    /// Account in the Account's home currency.
    #[serde(rename = "dividendAdjustment", skip_serializing_if = "Option::is_none")]
    pub dividend_adjustment: Option<DecimalNumber>,

    /// The net asset value of the Account inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueNAV", skip_serializing_if = "Option::is_none")]
    pub true_nav: Option<DecimalNumber>,

    /// The total unrealized profit/loss inclusive of unsettled amounts. This
    /// field is returned by the live v20 API but is not present in OANDA's
    /// official documentation.
    #[serde(rename = "trueUnrealizedPL", skip_serializing_if = "Option::is_none")]
    pub true_unrealized_pl: Option<DecimalNumber>,

    /// The date/time of the last dividend adjustment per instrument. This field
    /// is returned by the live v20 API but is not present in OANDA's official
    /// documentation.
    #[serde(
        rename = "lastDividendAdjustmentTimestamps",
        default,
        skip_serializing_if = "Vec::is_empty"
    )]
    pub last_dividend_adjustment_timestamps: Vec<DividendAdjustmentTimestamp>,
}