bybit/models/add_reduce_margin_result.rs
1use crate::prelude::*;
2
3/// Details the result of a margin adjustment for a position.
4///
5/// Part of the `AddReduceMarginResponse`, this struct provides updated position metrics after adding or reducing margin. Bots use this to confirm the new position state and update risk management calculations.
6#[derive(Serialize, Deserialize, Clone, Debug)]
7#[serde(rename_all = "camelCase")]
8pub struct AddReduceMarginResult {
9 /// The product category (e.g., Linear).
10 ///
11 /// Indicates the instrument type of the position. Bots should verify this matches the requested `category`.
12 pub category: Category,
13
14 /// The trading pair symbol (e.g., "BTCUSDT").
15 ///
16 /// Identifies the perpetual futures contract. Bots should confirm this matches the requested symbol.
17 pub symbol: String,
18
19 /// The position index (e.g., 0 for one-way mode, 1 or 2 for hedge mode).
20 ///
21 /// Indicates the position type. Bots use this to distinguish between long and short positions in hedge mode.
22 pub position_idx: i32,
23
24 /// The risk ID associated with the position.
25 ///
26 /// Identifies the risk limit tier applied to the position. Bots use this to verify compliance with risk management settings.
27 pub risk_id: i32,
28
29 /// The risk limit value for the position.
30 ///
31 /// The maximum exposure allowed for the position, in the settlement currency. Bots use this to ensure positions stay within risk limits.
32 #[serde(with = "string_to_float")]
33 pub risk_limit_value: f64,
34
35 /// The position size (in base asset).
36 ///
37 /// The quantity of the base asset held in the position. Bots use this to calculate position value and risk exposure.
38 #[serde(with = "string_to_float")]
39 pub size: f64,
40
41 /// The position value.
42 ///
43 /// The monetary value of the position (`size` * `avg_price`). Bots use this to calculate margin requirements and exposure.
44 #[serde(with = "string_to_float")]
45 pub position_value: f64,
46
47 /// The average entry price of the position.
48 ///
49 /// The average price at which the position was opened. Bots use this to calculate unrealized P&L and assess profitability.
50 #[serde(with = "string_to_float")]
51 pub avg_price: f64,
52
53 /// The liquidation price.
54 ///
55 /// The price at which the position will be liquidated. Bots use this to set stop-loss orders or trigger risk management actions.
56 #[serde(with = "string_to_float")]
57 pub liq_price: f64,
58
59 /// The bankruptcy price.
60 ///
61 /// The price at which the position would result in account bankruptcy. Bots use this as a critical risk threshold.
62 #[serde(with = "string_to_float")]
63 pub bust_price: f64,
64
65 /// The mark price of the position.
66 ///
67 /// The current mark price used for P&L calculations in perpetual futures. Bots use this to calculate unrealized P&L and assess position health.
68 #[serde(with = "string_to_float")]
69 pub mark_price: f64,
70
71 /// The leverage applied to the position.
72 ///
73 /// The leverage multiplier (e.g., "10" for 10x). Bots use this to calculate margin requirements and assess risk exposure.
74 pub leverage: String,
75
76 /// Auto-margin addition status (0 or 1).
77 ///
78 /// Indicates whether auto-margin addition is enabled (`1`) or disabled (`0`). Bots use this to monitor margin settings.
79 pub auto_add_margin: i32,
80
81 /// The position status (e.g., "Normal", "Liq").
82 ///
83 /// Indicates the current state of the position, such as active or in liquidation. Bots use this to trigger risk management actions if needed.
84 pub position_status: String,
85
86 /// The initial margin for the position.
87 ///
88 /// The initial margin required to maintain the position. Bots use this to calculate leverage and margin utilization.
89 #[serde(rename = "positionIM")]
90 pub position_im: String,
91
92 /// The maintenance margin for the position.
93 ///
94 /// The minimum margin required to avoid liquidation. Bots use this to calculate margin ratios and manage risk.
95 #[serde(rename = "positionMM")]
96 pub position_mm: String,
97
98 /// The unrealized profit and loss.
99 ///
100 /// The current unrealized P&L for the position, based on the mark price. Bots use this to monitor position profitability in real time.
101 pub unrealised_pnl: String,
102
103 /// The cumulative realized profit and loss.
104 ///
105 /// The total realized P&L for the position from all executions. Bots use this to track historical performance.
106 pub cum_realised_pnl: String,
107
108 /// The stop-loss price (optional).
109 ///
110 /// The price at which the position will automatically close to limit losses. Bots use this to verify stop-loss settings.
111 #[serde(with = "string_to_float_optional")]
112 pub stop_loss: Option<f64>,
113
114 /// The take-profit price (optional).
115 ///
116 /// The price at which the position will automatically close for a profit. Bots use this to verify take-profit settings.
117 #[serde(with = "string_to_float_optional")]
118 pub take_profit: Option<f64>,
119
120 /// The trailing stop value.
121 ///
122 /// The trailing stop offset, if enabled. Bots use this to verify dynamic stop-loss settings that follow market movements.
123 pub trailing_stop: String,
124
125 /// The timestamp when the position was created.
126 ///
127 /// Indicates when the position was opened. Bots use this to calculate position duration and align with other time-series data.
128 #[serde(with = "string_to_u64")]
129 pub created_time: u64,
130
131 /// The timestamp of the last position update.
132 ///
133 /// Indicates when the position was last modified (e.g., margin or size changes). Bots use this to track position changes in real time.
134 #[serde(with = "string_to_u64")]
135 pub updated_time: u64,
136}