Skip to main content

bybit_api/models/
position.rs

1//! Position models.
2
3use crate::models::common::*;
4use serde::{Deserialize, Serialize};
5
6/// Position list response.
7#[derive(Debug, Clone, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct PositionList {
10    /// Category
11    pub category: String,
12    /// List of positions
13    pub list: Vec<Position>,
14    /// Next page cursor
15    #[serde(default)]
16    pub next_page_cursor: String,
17}
18
19/// Position info.
20#[derive(Debug, Clone, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct Position {
23    /// Position index
24    pub position_idx: i32,
25    /// Risk ID
26    #[serde(default)]
27    pub risk_id: i32,
28    /// Risk limit value
29    #[serde(default)]
30    pub risk_limit_value: String,
31    /// Symbol
32    pub symbol: String,
33    /// Side
34    pub side: String,
35    /// Size
36    pub size: String,
37    /// Average entry price
38    #[serde(default)]
39    pub avg_price: String,
40    /// Position value
41    #[serde(default)]
42    pub position_value: String,
43    /// Trade mode (0=cross, 1=isolated)
44    #[serde(default)]
45    pub trade_mode: i32,
46    /// Position status
47    #[serde(default)]
48    pub position_status: String,
49    /// Leverage
50    #[serde(default)]
51    pub leverage: String,
52    /// Mark price
53    #[serde(default)]
54    pub mark_price: String,
55    /// Liquidation price
56    #[serde(default)]
57    pub liq_price: String,
58    /// Bust price
59    #[serde(default)]
60    pub bust_price: String,
61    /// Position margin
62    #[serde(default)]
63    pub position_mm: String,
64    /// Position initial margin
65    #[serde(default)]
66    pub position_im: String,
67    /// Take profit price
68    #[serde(default)]
69    pub take_profit: String,
70    /// Stop loss price
71    #[serde(default)]
72    pub stop_loss: String,
73    /// Trailing stop
74    #[serde(default)]
75    pub trailing_stop: String,
76    /// Unrealised PnL
77    #[serde(default)]
78    pub unrealised_pnl: String,
79    /// Cumulative realised PnL
80    #[serde(default)]
81    pub cum_realised_pnl: String,
82    /// Created time
83    #[serde(default)]
84    pub created_time: String,
85    /// Updated time
86    #[serde(default)]
87    pub updated_time: String,
88}
89
90/// Set leverage request.
91#[derive(Debug, Clone, Serialize)]
92#[serde(rename_all = "camelCase")]
93pub struct SetLeverageParams {
94    /// Category
95    pub category: Category,
96    /// Symbol
97    pub symbol: String,
98    /// Buy leverage
99    pub buy_leverage: String,
100    /// Sell leverage
101    pub sell_leverage: String,
102}
103
104/// Trading stop request.
105#[derive(Debug, Clone, Serialize)]
106#[serde(rename_all = "camelCase")]
107pub struct TradingStopParams {
108    /// Category
109    pub category: Category,
110    /// Symbol
111    pub symbol: String,
112    /// Take profit price
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub take_profit: Option<String>,
115    /// Stop loss price
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub stop_loss: Option<String>,
118    /// Trailing stop
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub trailing_stop: Option<String>,
121    /// Take profit trigger
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub tp_trigger_by: Option<TriggerBy>,
124    /// Stop loss trigger
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub sl_trigger_by: Option<TriggerBy>,
127    /// Position index
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub position_idx: Option<i32>,
130}
131
132/// Switch position mode request.
133#[derive(Debug, Clone, Serialize)]
134#[serde(rename_all = "camelCase")]
135pub struct SwitchPositionModeParams {
136    /// Category
137    pub category: Category,
138    /// Symbol (optional)
139    #[serde(skip_serializing_if = "Option::is_none")]
140    pub symbol: Option<String>,
141    /// Coin (optional)
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub coin: Option<String>,
144    /// Mode (0=merged, 3=both sides)
145    pub mode: i32,
146}
147
148/// Set risk limit request.
149#[derive(Debug, Clone, Serialize)]
150#[serde(rename_all = "camelCase")]
151pub struct SetRiskLimitParams {
152    /// Category
153    pub category: Category,
154    /// Symbol
155    pub symbol: String,
156    /// Risk ID
157    pub risk_id: i32,
158    /// Position index
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub position_idx: Option<i32>,
161}
162
163/// Add margin request.
164#[derive(Debug, Clone, Serialize)]
165#[serde(rename_all = "camelCase")]
166pub struct AddMarginParams {
167    /// Category
168    pub category: Category,
169    /// Symbol
170    pub symbol: String,
171    /// Margin amount
172    pub margin: String,
173    /// Position index
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub position_idx: Option<i32>,
176}
177
178/// Closed PnL response.
179#[derive(Debug, Clone, Deserialize)]
180#[serde(rename_all = "camelCase")]
181pub struct ClosedPnlList {
182    /// Category
183    pub category: String,
184    /// List of closed PnL records
185    pub list: Vec<ClosedPnl>,
186    /// Next page cursor
187    #[serde(default)]
188    pub next_page_cursor: String,
189}
190
191/// Closed PnL record.
192#[derive(Debug, Clone, Deserialize)]
193#[serde(rename_all = "camelCase")]
194pub struct ClosedPnl {
195    /// Symbol
196    pub symbol: String,
197    /// Order ID
198    pub order_id: String,
199    /// Side
200    pub side: String,
201    /// Qty
202    pub qty: String,
203    /// Order price
204    pub order_price: String,
205    /// Order type
206    pub order_type: String,
207    /// Exec type
208    pub exec_type: String,
209    /// Closed size
210    pub closed_size: String,
211    /// Cumulative entry value
212    pub cum_entry_value: String,
213    /// Average entry price
214    pub avg_entry_price: String,
215    /// Cumulative exit value
216    pub cum_exit_value: String,
217    /// Average exit price
218    pub avg_exit_price: String,
219    /// Closed PnL
220    pub closed_pnl: String,
221    /// Fill count
222    pub fill_count: String,
223    /// Leverage
224    pub leverage: String,
225    /// Created time
226    pub created_time: String,
227    /// Updated time
228    pub updated_time: String,
229}
230
231/// Execution list response.
232#[derive(Debug, Clone, Deserialize)]
233#[serde(rename_all = "camelCase")]
234pub struct ExecutionList {
235    /// Category
236    pub category: String,
237    /// List of executions
238    pub list: Vec<Execution>,
239    /// Next page cursor
240    #[serde(default)]
241    pub next_page_cursor: String,
242}
243
244/// Execution record.
245#[derive(Debug, Clone, Deserialize)]
246#[serde(rename_all = "camelCase")]
247pub struct Execution {
248    /// Symbol
249    pub symbol: String,
250    /// Order ID
251    pub order_id: String,
252    /// Order link ID
253    #[serde(default)]
254    pub order_link_id: String,
255    /// Side
256    pub side: String,
257    /// Order price
258    pub order_price: String,
259    /// Order qty
260    pub order_qty: String,
261    /// Order type
262    pub order_type: String,
263    /// Exec ID
264    pub exec_id: String,
265    /// Exec price
266    pub exec_price: String,
267    /// Exec qty
268    pub exec_qty: String,
269    /// Exec fee
270    pub exec_fee: String,
271    /// Exec type
272    pub exec_type: String,
273    /// Exec value
274    pub exec_value: String,
275    /// Fee rate
276    #[serde(default)]
277    pub fee_rate: String,
278    /// Exec time
279    pub exec_time: String,
280}