crypto_com_exchange/model/
user.rs

1use serde::{Serialize, Deserialize};
2use serde_aux::prelude::deserialize_number_from_string;
3
4
5// Main container of the user balance
6#[derive(Serialize, Deserialize, Debug)]
7pub struct BalanceResult {
8    /// Subscription name used to subscribe this event
9    pub subscription: String,
10
11    /// The actual ticker data
12    pub data: Vec<Balance>
13}
14
15/// Balance element received from subscription
16#[derive(Serialize, Deserialize, Debug)]
17pub struct Balance {
18    /// Currency name
19    pub currency: String,
20
21    /// Total balance
22    pub balance: f32,
23
24    /// Total available
25    pub available: f32,
26
27    /// Total in any order
28    pub order: f32,
29
30    /// Total staked
31    pub stake: f32
32
33}
34
35
36#[derive(Serialize, Deserialize, Debug)]
37pub struct BalanceResult2 {
38    /// Subscription name used to subscribe this event
39    pub subscription: String,
40
41    /// The actual ticker data
42    pub data: Vec<Balance>
43}
44
45/// Balance element received from subscription
46#[derive(Serialize, Deserialize, Debug)]
47pub struct Balance2 {
48    /// Balance that user can open new order (Margin Balance - Initial Margin)
49    #[serde(deserialize_with = "deserialize_number_from_string")]
50    pub total_available_balance: f64,
51
52    /// Balance for the margin calculation (Wallet Balance + Unrealized PnL)
53    #[serde(deserialize_with = "deserialize_number_from_string")]
54    pub total_margin_balance: f64,
55
56    /// Total initial margin requirement for all positions and all open orders
57    #[serde(deserialize_with = "deserialize_number_from_string")]
58    pub total_initial_margin: f64,
59
60    /// Total maintenance margin requirement for all positions
61    #[serde(deserialize_with = "deserialize_number_from_string")]
62    pub total_maintenance_margin: f64,
63
64    /// Position value in USD
65    #[serde(deserialize_with = "deserialize_number_from_string")]
66    pub total_position_cost: f64,
67
68    /// Wallet Balance (Deposits - Withdrawals + Realized PnL - Fees)
69    #[serde(deserialize_with = "deserialize_number_from_string")]
70    pub total_cash_balance: f64,
71
72    /// Collateral Value
73    #[serde(deserialize_with = "deserialize_number_from_string")]
74    pub total_collateral_value: f64,
75
76    /// Current unrealized profit and loss from all open positions (calculated with Mark Price and Avg Price)
77    #[serde(deserialize_with = "deserialize_number_from_string")]
78    pub total_session_unrealized_pnl: f64,
79
80    /// Current realized profit and loss from all open positions (calculated with Mark Price and Avg Price)
81    pub instrument_name: String,
82
83    /// Describes whether the account is under liquidation
84    #[serde(deserialize_with = "deserialize_number_from_string")]
85    pub total_session_realized_pnl: f64,
86
87    /// Describes whether the account is under liquidation
88    pub is_liquidating: bool,
89
90    /// The actual leverage used (all open positions combined), i.e. position size / margin balance
91    #[serde(deserialize_with = "deserialize_number_from_string")]
92    pub total_effective_leverage: f64,
93
94    /// Maximum position size allowed (for all open positions combined)
95    #[serde(deserialize_with = "deserialize_number_from_string")]
96    pub position_limit: f64,
97
98    /// Combined position size of all open positions + order exposure on all instruments
99    #[serde(deserialize_with = "deserialize_number_from_string")]
100    pub used_position_limit: f64,
101
102    /// Collateral balances
103    pub position_balances: Vec<PositionBalance>
104    
105}
106
107/// Position balance
108#[derive(Serialize, Deserialize, Debug)]
109pub struct PositionBalance {
110
111    /// Instrument name of the collateral e.g. USD, CRO, USDT, or DAI
112    pub instrument_name: String,
113
114    /// Quantity of the collateral
115    #[serde(deserialize_with = "deserialize_number_from_string")]
116    pub quantity: f64,
117
118    /// Market value of the collateral
119    #[serde(deserialize_with = "deserialize_number_from_string")]
120    pub market_value: f64,
121
122    /// Collateral amount derived by market_value times collateral_weight
123    #[serde(deserialize_with = "deserialize_number_from_string")]
124    pub collateral_amount: f64,
125
126    /// Collateral weight
127    #[serde(deserialize_with = "deserialize_number_from_string")]
128    pub collateral_weight: f64,
129
130     /// Max withdrawal balance of the collateral
131     #[serde(deserialize_with = "deserialize_number_from_string")]
132     pub max_withdrawal_balance: f64,
133}
134 
135pub fn balance() -> String {
136    ("user.balance").to_string()
137  }