bybit/models/position_info.rs
1use crate::prelude::*;
2
3/// Represents detailed information about a single position.
4///
5/// Returned as part of the `InfoResponse`, this struct provides comprehensive position data, including size, entry price, leverage, and P&L. Bots use this to monitor and manage open positions in perpetual futures.
6#[derive(Debug, Serialize, Deserialize, Clone)]
7#[serde(rename_all = "camelCase")]
8pub struct PositionInfo {
9 /// The position index (e.g., 0 for one-way mode, 1 or 2 for hedge mode).
10 ///
11 /// Indicates the position type in Bybit’s position management system. Bots use this to distinguish between long and short positions in hedge mode for perpetual futures.
12 pub position_idx: i32,
13
14 /// The risk ID associated with the position.
15 ///
16 /// Identifies the risk limit tier applied to the position. Bots use this to verify compliance with risk management settings.
17 pub risk_id: i32,
18
19 /// The risk limit value for the position.
20 ///
21 /// The maximum exposure allowed for the position, in the settlement currency. Bots use this to ensure positions stay within risk limits.
22 #[serde(with = "string_to_float")]
23 pub risk_limit_value: f64,
24
25 /// The trading pair symbol (e.g., "BTCUSDT").
26 ///
27 /// Identifies the perpetual futures contract for the position. Bots should verify this matches the expected symbol.
28 pub symbol: String,
29
30 /// The position side (Buy, Sell, or None).
31 ///
32 /// Indicates whether the position is long (Buy), short (Sell), or closed (None). Bots use this to track position direction and calculate net exposure.
33 #[serde(deserialize_with = "empty_string_as_none")]
34 pub side: Option<Side>,
35
36 /// The position size (in base asset).
37 ///
38 /// The quantity of the base asset held in the position (e.g., BTC in `BTCUSDT`). Bots use this to calculate position value and risk exposure.
39 #[serde(with = "string_to_float")]
40 pub size: f64,
41
42 /// The average entry price of the position (optional).
43 ///
44 /// The average price at which the position was opened. Bots use this to calculate unrealized P&L and assess position profitability.
45 #[serde(with = "string_to_float_optional")]
46 pub avg_price: Option<f64>,
47
48 /// The position value (optional).
49 ///
50 /// The monetary value of the position (`size` * `avg_price`). Bots use this to calculate margin requirements and exposure in the settlement currency.
51 #[serde(with = "string_to_float_optional")]
52 pub position_value: Option<f64>,
53
54 /// The trade mode (0 for cross margin, 1 for isolated margin).
55 ///
56 /// Indicates whether the position uses cross margin (shared across positions) or isolated margin (specific to this position). Bots use this to manage margin allocation strategies.
57 pub trade_mode: i32,
58
59 /// The position status (e.g., "Normal", "Liq").
60 ///
61 /// Indicates the current state of the position, such as active or in liquidation. Bots use this to trigger risk management actions if the position is at risk.
62 pub position_status: String,
63
64 /// Auto-margin addition status (0 or 1).
65 ///
66 /// Indicates whether auto-margin addition is enabled (`1`) or disabled (`0`). Bots use this to monitor margin settings and prevent unexpected margin calls.
67 pub auto_add_margin: i32,
68
69 /// The Auto-Deleveraging (ADL) rank indicator.
70 ///
71 /// Indicates the position’s priority for auto-deleveraging in case of market stress. Higher ranks (e.g., 4) are deleveraged first. Bots use this to assess liquidation risk.
72 pub adl_rank_indicator: i32,
73
74 /// The leverage applied to the position (optional).
75 ///
76 /// The leverage multiplier (e.g., `10` for 10x). Bots use this to calculate margin requirements and assess risk exposure.
77 #[serde(with = "string_to_float_optional")]
78 pub leverage: Option<f64>,
79
80 /// The position’s margin balance.
81 ///
82 /// The amount of margin allocated to the position. Bots use this to monitor margin health and prevent liquidation.
83 #[serde(with = "string_to_float")]
84 pub position_balance: f64,
85
86 /// The mark price of the position.
87 ///
88 /// The current mark price used for P&L calculations in perpetual futures. Bots use this to calculate unrealized P&L and assess position health.
89 #[serde(with = "string_to_float")]
90 pub mark_price: f64,
91
92 /// The liquidation price (optional).
93 ///
94 /// The price at which the position will be liquidated. Bots use this to set stop-loss orders or trigger risk management actions.
95 #[serde(with = "string_to_float_optional")]
96 pub liq_price: Option<f64>,
97
98 /// The bankruptcy price (optional).
99 ///
100 /// The price at which the position would result in account bankruptcy. Bots use this as a critical risk threshold for position management.
101 #[serde(with = "string_to_float_optional")]
102 pub bust_price: Option<f64>,
103
104 /// The maintenance margin for the position (optional).
105 ///
106 /// The minimum margin required to maintain the position. Bots use this to calculate margin ratios and avoid liquidation.
107 #[serde(rename = "positionMM", with = "string_to_float_optional")]
108 pub position_mm: Option<f64>,
109
110 /// The initial margin for the position (optional).
111 ///
112 /// The initial margin required to open the position. Bots use this to calculate leverage and margin utilization.
113 #[serde(rename = "positionIM", with = "string_to_float_optional")]
114 pub position_im: Option<f64>,
115
116 /// The take-profit/stop-loss mode (e.g., "Full", "Partial").
117 ///
118 /// Indicates whether take-profit and stop-loss orders are applied to the entire position (`Full`) or partially. Bots use this to manage exit strategies.
119 pub tpsl_mode: String,
120
121 /// The take-profit price (optional).
122 ///
123 /// The price at which the position will automatically close for a profit. Bots use this to implement automated exit strategies.
124 #[serde(with = "string_to_float_optional")]
125 pub take_profit: Option<f64>,
126
127 /// The stop-loss price (optional).
128 ///
129 /// The price at which the position will automatically close to limit losses. Bots use this to manage downside risk.
130 #[serde(with = "string_to_float_optional")]
131 pub stop_loss: Option<f64>,
132
133 /// The trailing stop value.
134 ///
135 /// The trailing stop offset, if enabled. Bots use this to implement dynamic stop-loss strategies that follow market movements.
136 pub trailing_stop: String,
137
138 /// The unrealized profit and loss (optional).
139 ///
140 /// The current unrealized P&L for the position, based on the mark price. Bots use this to monitor position profitability in real time.
141 #[serde(with = "string_to_float_optional")]
142 pub unrealised_pnl: Option<f64>,
143
144 /// The cumulative realized profit and loss (optional).
145 ///
146 /// The total realized P&L for the position from all executions. Bots use this to track historical performance.
147 #[serde(with = "string_to_float_optional")]
148 pub cum_realised_pnl: Option<f64>,
149
150 /// The sequence number of the position update.
151 ///
152 /// A unique sequence ID for ordering position updates. Bots use this to ensure proper chronological processing of position data.
153 pub seq: i64,
154
155 /// Indicates if the position is reduce-only.
156 ///
157 /// `true` if the position can only be reduced (e.g., closing trades only). Bots use this to enforce position management rules.
158 pub is_reduce_only: bool,
159
160 /// The timestamp of the last margin maintenance update (optional).
161 ///
162 /// Indicates when the margin maintenance requirements were last updated. Bots use this to monitor margin health over time.
163 #[serde(with = "string_to_u64_optional")]
164 pub mmr_sys_updated_time: Option<u64>,
165
166 /// The timestamp of the last leverage update (optional).
167 ///
168 /// Indicates when the leverage settings were last updated. Bots use this to track changes in risk exposure.
169 #[serde(with = "string_to_u64_optional")]
170 pub leverage_sys_updated_time: Option<u64>,
171
172 /// The timestamp when the position was created.
173 ///
174 /// Indicates when the position was opened. Bots use this to calculate position duration and align with other time-series data.
175 #[serde(with = "string_to_u64")]
176 pub created_time: u64,
177
178 /// The timestamp of the last position update.
179 ///
180 /// Indicates when the position was last modified (e.g., size or margin changes). Bots use this to track position changes in real time.
181 #[serde(with = "string_to_u64")]
182 pub updated_time: u64,
183}