Skip to main content

bybit/models/
wallet_data.rs

1use crate::prelude::*;
2
3/// Represents wallet data, including balances and margin metrics, for a Bybit account.
4///
5/// This struct provides a snapshot of the account’s financial state, used for monitoring margin, equity, and risk in perpetual futures trading (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
6/// For trading bots, wallet data is critical for ensuring sufficient margin, avoiding liquidations, and optimizing capital allocation.
7#[derive(Serialize, Deserialize, Debug, Clone)]
8#[serde(rename_all = "camelCase")]
9pub struct WalletData {
10    /// Initial margin rate for the account, as a string (e.g., "0.1" for 10%).
11    ///
12    /// This represents the ratio of initial margin to total equity, a key risk metric in perpetual futures. A higher rate indicates greater leverage and risk (https://bybit-exchange.github.io/docs/v5/account/risk-limit).
13    /// **Bot Implication**: Bots monitor `account_im_rate` to ensure compliance with Bybit’s margin requirements, adjusting positions to avoid margin calls.
14    #[serde(rename = "accountIMRate", with = "string_to_float_optional")]
15    pub account_im_rate: Option<f64>,
16
17    /// Maintenance margin rate for the account, as a string (e.g., "0.05" for 5%).
18    ///
19    /// This is the minimum margin ratio required to maintain open positions. Falling below this triggers a margin call or liquidation (https://bybit-exchange.github.io/docs/v5/account/risk-limit).
20    /// **Bot Implication**: Bots prioritize `account_mm_rate` to prevent forced liquidations, especially in volatile markets where margin requirements can spike.
21    #[serde(rename = "accountMMRate", with = "string_to_float_optional")]
22    pub account_mm_rate: Option<f64>,
23
24    /// Total equity in the account, in USDT or the base currency.
25    ///
26    /// This represents the account’s net worth, including wallet balance and unrealized PNL (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
27    /// **Bot Implication**: Bots use `total_equity` to assess overall account health and allocate capital across positions, ensuring sufficient buffer for market swings.
28    #[serde(with = "string_to_float")]
29    pub total_equity: f64,
30
31    /// Total wallet balance, excluding unrealized PNL.
32    ///
33    /// This is the actual cash balance in the account, available for trading or withdrawal (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
34    /// **Bot Implication**: Bots track `total_wallet_balance` to ensure liquidity for new trades and margin requirements, avoiding funding shortages.
35    #[serde(with = "string_to_float")]
36    pub total_wallet_balance: f64,
37
38    /// Total margin balance, including wallet balance and unrealized PNL.
39    ///
40    /// This reflects the account’s total margin capacity, used to support open positions (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
41    /// **Bot Implication**: Bots use `total_margin_balance` to calculate leverage limits and ensure positions are adequately margined.
42    #[serde(with = "string_to_float_optional")]
43    pub total_margin_balance: Option<f64>,
44
45    /// Total available balance for new trades or withdrawals.
46    ///
47    /// This is the portion of the wallet balance not tied up in margin or open positions (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
48    /// **Bot Implication**: Bots rely on `total_available_balance` to determine capacity for new trades, ensuring no over-allocation of funds.
49    #[serde(with = "string_to_float_optional")]
50    pub total_available_balance: Option<f64>,
51
52    /// Total unrealized profit and loss for perpetual futures positions.
53    ///
54    /// This reflects the paper gains or losses on open positions, impacting equity and margin calculations (https://bybit-exchange.github.io/docs/v5/account/position).
55    /// **Bot Implication**: Bots monitor `total_perp_upl` to assess position performance and adjust risk controls, as large unrealized losses can trigger liquidations.
56    #[serde(rename = "totalPerpUPL", with = "string_to_float")]
57    pub total_perp_upl: f64,
58
59    /// Total initial margin required for open positions and orders.
60    ///
61    /// This is the collateral required to open and maintain positions, based on Bybit’s risk limits (https://bybit-exchange.github.io/docs/v5/account/risk-limit).
62    /// **Bot Implication**: Bots track `total_initial_margin` to ensure sufficient margin allocation, preventing rejections or forced closures.
63    #[serde(with = "string_to_float_optional")]
64    pub total_initial_margin: Option<f64>,
65
66    /// Total maintenance margin required to keep positions open.
67    ///
68    /// This is the minimum collateral needed to avoid liquidation, typically lower than initial margin (https://bybit-exchange.github.io/docs/v5/account/risk-limit).
69    /// **Bot Implication**: Bots prioritize `total_maintenance_margin` to maintain account stability, as falling below this triggers risk management actions.
70    #[serde(with = "string_to_float_optional")]
71    pub total_maintenance_margin: Option<f64>,
72
73    /// List of coin-specific balance data for the account.
74    ///
75    /// This breaks down the wallet by currency, providing granular balance and margin details (https://bybit-exchange.github.io/docs/v5/account/wallet-balance).
76    /// **Bot Implication**: Bots use `coin` to manage multi-currency accounts, ensuring proper funding and collateral allocation per currency.
77    pub coin: Vec<CoinData>,
78
79    /// Loan-to-value ratio for the account, as a string (e.g., "0.2" for 20%).
80    ///
81    /// This measures borrowed funds relative to total equity, a leverage risk indicator in Bybit’s unified margin account (https://bybit-exchange.github.io/docs/v5/account/risk-limit).
82    /// **Bot Implication**: Bots monitor `account_ltv` to control leverage risk, as high LTV increases liquidation probability in adverse markets.
83    #[serde(rename = "accountLTV", with = "string_to_float_optional")]
84    pub account_ltv: Option<f64>,
85
86    /// Type of account, e.g., "UNIFIED", if specified.
87    ///
88    /// This indicates the account’s margin mode, such as unified (cross-margin) or isolated (per-position margin) (https://bybit-exchange.github.io/docs/v5/account/margin-mode).
89    /// **Bot Implication**: Bots must align strategies with `account_type`, as margin modes affect risk calculations and liquidation mechanics.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub account_type: Option<String>,
92}