Skip to main content

oanda_client/models/
position.rs

1//! OANDA v20 position 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/// The specification of a Position within an Account.
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Position {
18    /// The Position’s Instrument.
19    #[serde(
20        rename = "instrument",
21        default,
22        skip_serializing_if = "Option::is_none"
23    )]
24    pub instrument: Option<InstrumentName>,
25    /// Profit/loss realized by the Position over the lifetime of the Account.
26    #[serde(rename = "pl", default, skip_serializing_if = "Option::is_none")]
27    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
28    pub pl: Option<Decimal>,
29    /// The unrealized profit/loss of all open Trades that contribute to this Position.
30    #[serde(
31        rename = "unrealizedPL",
32        default,
33        skip_serializing_if = "Option::is_none"
34    )]
35    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
36    pub unrealized_pl: Option<Decimal>,
37    /// Margin currently used by the Position.
38    #[serde(
39        rename = "marginUsed",
40        default,
41        skip_serializing_if = "Option::is_none"
42    )]
43    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
44    pub margin_used: Option<Decimal>,
45    /// Profit/loss realized by the Position since the Account’s resettablePL was last reset by the client.
46    #[serde(
47        rename = "resettablePL",
48        default,
49        skip_serializing_if = "Option::is_none"
50    )]
51    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
52    pub resettable_pl: Option<Decimal>,
53    /// The total amount of financing paid/collected for this instrument over the lifetime of the Account.
54    #[serde(rename = "financing", default, skip_serializing_if = "Option::is_none")]
55    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
56    pub financing: Option<Decimal>,
57    /// The total amount of commission paid for this instrument over the lifetime of the Account.
58    #[serde(
59        rename = "commission",
60        default,
61        skip_serializing_if = "Option::is_none"
62    )]
63    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
64    pub commission: Option<Decimal>,
65    /// The total amount of dividend adjustment paid for this instrument over the lifetime of the Account.
66    #[serde(
67        rename = "dividendAdjustment",
68        default,
69        skip_serializing_if = "Option::is_none"
70    )]
71    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
72    pub dividend_adjustment: Option<Decimal>,
73    /// The total amount of fees charged over the lifetime of the Account for the execution of guaranteed Stop
74    /// Loss Orders for this instrument.
75    #[serde(
76        rename = "guaranteedExecutionFees",
77        default,
78        skip_serializing_if = "Option::is_none"
79    )]
80    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
81    pub guaranteed_execution_fees: Option<Decimal>,
82    /// The details of the long side of the Position.
83    #[serde(rename = "long", default, skip_serializing_if = "Option::is_none")]
84    pub long: Option<PositionSide>,
85    /// The details of the short side of the Position.
86    #[serde(rename = "short", default, skip_serializing_if = "Option::is_none")]
87    pub short: Option<PositionSide>,
88}
89
90/// The representation of a Position for a single direction (long or short).
91#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
92#[serde(rename_all = "camelCase")]
93pub struct PositionSide {
94    /// Number of units in the position (negative value indicates short position, positive indicates long
95    /// position).
96    #[serde(rename = "units", default, skip_serializing_if = "Option::is_none")]
97    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
98    pub units: Option<Decimal>,
99    /// Volume-weighted average of the underlying Trade open prices for the Position.
100    #[serde(
101        rename = "averagePrice",
102        default,
103        skip_serializing_if = "Option::is_none"
104    )]
105    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
106    pub average_price: Option<Decimal>,
107    /// List of the open Trade IDs which contribute to the open Position.
108    #[serde(rename = "tradeIDs", default, skip_serializing_if = "Option::is_none")]
109    pub trade_ids: Option<Vec<TradeID>>,
110    /// Profit/loss realized by the PositionSide over the lifetime of the Account.
111    #[serde(rename = "pl", default, skip_serializing_if = "Option::is_none")]
112    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
113    pub pl: Option<Decimal>,
114    /// The unrealized profit/loss of all open Trades that contribute to this PositionSide.
115    #[serde(
116        rename = "unrealizedPL",
117        default,
118        skip_serializing_if = "Option::is_none"
119    )]
120    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
121    pub unrealized_pl: Option<Decimal>,
122    /// Profit/loss realized by the PositionSide since the Account’s resettablePL was last reset by the client.
123    #[serde(
124        rename = "resettablePL",
125        default,
126        skip_serializing_if = "Option::is_none"
127    )]
128    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
129    pub resettable_pl: Option<Decimal>,
130    /// The total amount of financing paid/collected for this PositionSide over the lifetime of the Account.
131    #[serde(rename = "financing", default, skip_serializing_if = "Option::is_none")]
132    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
133    pub financing: Option<Decimal>,
134    /// The total amount of dividend adjustment paid for the PositionSide over the lifetime of the Account.
135    #[serde(
136        rename = "dividendAdjustment",
137        default,
138        skip_serializing_if = "Option::is_none"
139    )]
140    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
141    pub dividend_adjustment: Option<Decimal>,
142    /// The total amount of fees charged over the lifetime of the Account for the execution of guaranteed Stop
143    /// Loss Orders attached to Trades for this PositionSide.
144    #[serde(
145        rename = "guaranteedExecutionFees",
146        default,
147        skip_serializing_if = "Option::is_none"
148    )]
149    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
150    pub guaranteed_execution_fees: Option<Decimal>,
151}
152
153/// The dynamic (calculated) state of a Position
154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
155#[serde(rename_all = "camelCase")]
156pub struct CalculatedPositionState {
157    /// The Position’s Instrument.
158    #[serde(
159        rename = "instrument",
160        default,
161        skip_serializing_if = "Option::is_none"
162    )]
163    pub instrument: Option<InstrumentName>,
164    /// The Position’s net unrealized profit/loss
165    #[serde(
166        rename = "netUnrealizedPL",
167        default,
168        skip_serializing_if = "Option::is_none"
169    )]
170    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
171    pub net_unrealized_pl: Option<Decimal>,
172    /// The unrealized profit/loss of the Position’s long open Trades
173    #[serde(
174        rename = "longUnrealizedPL",
175        default,
176        skip_serializing_if = "Option::is_none"
177    )]
178    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
179    pub long_unrealized_pl: Option<Decimal>,
180    /// The unrealized profit/loss of the Position’s short open Trades
181    #[serde(
182        rename = "shortUnrealizedPL",
183        default,
184        skip_serializing_if = "Option::is_none"
185    )]
186    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
187    pub short_unrealized_pl: Option<Decimal>,
188    /// Margin currently used by the Position.
189    #[serde(
190        rename = "marginUsed",
191        default,
192        skip_serializing_if = "Option::is_none"
193    )]
194    #[serde(deserialize_with = "crate::decimal_wire::optional_number_or_string")]
195    pub margin_used: Option<Decimal>,
196}