Skip to main content

oanda_client/models/
mod.rs

1//! Provider-native OANDA v20 models.
2//!
3//! Required fields follow the provider definitions; optional fields preserve absence,
4//! including documented provider defaults and partial account-change snapshots.
5//! Scalar enums retain unrecognized spellings in `Unknown` for forward compatibility.
6//! Financial values use exact decimals, accepting documented strings and numeric
7//! liquidity without a floating-point conversion. Typed endpoint admission validates
8//! outbound instructions separately, so decoding retains provider evidence.
9
10// Each spelling is declared once, alongside its public variant documentation.
11macro_rules! provider_enum {
12    (
13        $(#[$meta:meta])* $visibility:vis enum $name:ident {
14            $($(#[$variant_meta:meta])* $variant:ident => $wire:literal,)*
15            ;
16            $(#[$unknown_meta:meta])* Unknown(String),
17        }
18    ) => {
19        $(#[$meta])*
20        $visibility enum $name {
21            $($(#[$variant_meta])* $variant,)*
22            $(#[$unknown_meta])* Unknown(String),
23        }
24
25        impl $name {
26            /// Return the exact provider spelling.
27            #[must_use]
28            pub fn as_str(&self) -> &str {
29                match self {
30                    $(Self::$variant => $wire,)*
31                    Self::Unknown(value) => value,
32                }
33            }
34        }
35
36        impl serde::Serialize for $name {
37            fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
38                serializer.serialize_str(self.as_str())
39            }
40        }
41
42        impl<'de> serde::Deserialize<'de> for $name {
43            fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
44                let value = <String as serde::Deserialize>::deserialize(deserializer)?;
45                Ok(match value.as_str() {
46                    $($wire => Self::$variant,)*
47                    _ => Self::Unknown(value),
48                })
49            }
50        }
51    };
52}
53pub use crate::ids::*;
54pub use crate::timestamp::Timestamp as DateTime;
55/// Exact OANDA decimal number.
56pub type DecimalNumber = rust_decimal::Decimal;
57/// Exact account-currency units.
58pub type AccountUnits = rust_decimal::Decimal;
59/// Exact provider price.
60pub type PriceValue = rust_decimal::Decimal;
61mod variants;
62pub use variants::*;
63
64mod account;
65pub use account::*;
66mod instrument;
67pub use instrument::*;
68mod order;
69pub use order::*;
70mod trade;
71pub use trade::*;
72mod position;
73pub use position::*;
74mod transaction;
75pub use transaction::*;
76mod pricing;
77pub use pricing::*;
78mod pricing_common;
79pub use pricing_common::*;
80mod primitives;
81pub use primitives::*;