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
/******************************************************************************
Author: Joaquín Béjar García
Email: jb@taunais.com
Date: 21/7/25
******************************************************************************/
use crate::model::response::other::AccountSummariesResponse;
use pretty_simple_display::{DebugPretty, DisplaySimple};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
/// Subaccount information
#[skip_serializing_none]
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct Subaccount {
/// Subaccount email
pub email: String,
/// Subaccount ID
pub id: u64,
/// Whether login is enabled
pub login_enabled: bool,
/// Portfolio information (optional)
pub portfolio: Option<std::collections::HashMap<String, CurrencyPortfolio>>,
/// Whether to receive notifications
pub receive_notifications: bool,
/// System name
pub system_name: String,
/// Time in force (optional)
pub tif: Option<String>,
/// Subaccount type
#[serde(rename = "type")]
pub subaccount_type: String,
/// Username
pub username: String,
/// Margin model
pub margin_model: Option<String>,
/// Available funds
pub available_funds: Option<f64>,
/// Disabled trading products
pub disabled_trading_products: Option<Vec<String>>,
/// Is password
pub is_password: Option<bool>,
/// Proof ID
pub proof_id: Option<String>,
/// Proof ID signature
pub proof_id_signature: Option<String>,
/// Security keys assignments
pub security_keys_assignments: Option<Vec<serde_json::Value>>,
/// Security keys enabled
pub security_keys_enabled: Option<bool>,
/// Trading products details
pub trading_products_details: Option<Vec<TradingProductDetail>>,
/// Referrals count
pub referrals_count: Option<u64>,
}
/// Currency portfolio information
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct CurrencyPortfolio {
/// Available funds
pub available_funds: f64,
/// Available withdrawal funds
pub available_withdrawal_funds: f64,
/// Balance
pub balance: f64,
/// Currency
pub currency: String,
/// Equity
pub equity: f64,
/// Initial margin
pub initial_margin: f64,
/// Locked balance
pub locked_balance: f64,
/// Maintenance margin
pub maintenance_margin: f64,
/// Margin balance
pub margin_balance: f64,
/// Spot reserve
pub spot_reserve: f64,
/// Additional reserve
pub additional_reserve: f64,
}
/// Trading product detail
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct TradingProductDetail {
/// Whether enabled
pub enabled: bool,
/// Product name
pub product: String,
/// Whether overwriteable
pub overwriteable: bool,
}
/// Portfolio information (legacy)
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct PortfolioInfo {
/// Available funds
pub available_funds: f64,
/// Available withdrawal funds
pub available_withdrawal_funds: f64,
/// Balance
pub balance: f64,
/// Currency
pub currency: String,
/// Delta total
pub delta_total: f64,
/// Equity
pub equity: f64,
/// Initial margin
pub initial_margin: f64,
/// Maintenance margin
pub maintenance_margin: f64,
/// Margin balance
pub margin_balance: f64,
/// Session realized P&L
pub session_rpl: f64,
/// Session unrealized P&L
pub session_upl: f64,
/// Total P&L
pub total_pl: f64,
}
/// Portfolio information
#[skip_serializing_none]
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct Portfolio {
/// Currency of the portfolio
pub currency: String,
/// Account summaries for different currencies
pub accounts: Vec<AccountSummariesResponse>,
/// Total portfolio value in USD
pub total_usd_value: Option<f64>,
/// Cross-currency margin enabled
pub cross_margin_enabled: bool,
}
impl Portfolio {
/// Create a new empty portfolio
pub fn new(currency: String) -> Self {
Self {
currency,
accounts: Vec::new(),
total_usd_value: None,
cross_margin_enabled: false,
}
}
/// Add an account summary to the portfolio
pub fn add_account(&mut self, account: AccountSummariesResponse) {
self.accounts.push(account);
}
}