Skip to main content

bybit/models/
position_request.rs

1use crate::prelude::*;
2
3/// Parameters for requesting position information.
4///
5/// Used to construct a request to the `/v5/position/list` endpoint to retrieve current position details. Bots use this to monitor open positions, calculate unrealized P&L, and manage risk in perpetual futures.
6#[derive(Clone, Default)]
7pub struct PositionRequest<'a> {
8    /// The product category (e.g., Linear, Inverse).
9    ///
10    /// Specifies the instrument type. Bots must set this to fetch positions for the correct contract type.
11    pub category: Category,
12
13    /// The trading pair symbol (e.g., "BTCUSDT").
14    ///
15    /// Optionally filters positions by symbol. If unset, all positions in the category are returned. Bots should specify this for targeted position monitoring.
16    pub symbol: Option<Cow<'a, str>>,
17
18    /// The base coin (e.g., "BTC").
19    ///
20    /// Optionally filters positions by the base asset. Useful for bots managing multiple pairs of the same asset.
21    pub base_coin: Option<Cow<'a, str>>,
22
23    /// The settlement coin (e.g., "USDT").
24    ///
25    /// Optionally filters positions by the settlement currency. For `Linear` perpetuals, this is typically "USDT". Bots can use this to focus on specific margin types.
26    pub settle_coin: Option<Cow<'a, str>>,
27
28    /// The maximum number of position records to return.
29    ///
30    /// Controls the number of position records returned. Bots should set a reasonable limit to balance data completeness with performance.
31    pub limit: Option<usize>,
32}
33
34impl<'a> PositionRequest<'a> {
35    /// Creates a default Position request.
36    ///
37    /// Returns a request with `category` set to `Linear` and all other fields unset. Suitable for broad queries but should be customized for specific position monitoring needs.
38    pub fn default() -> Self {
39        Self::new(Category::Linear, None, None, None, None)
40    }
41    /// Constructs a new Position request with specified parameters.
42    ///
43    /// Allows full customization. Bots should use this to specify the exact symbol, category, and filters to align with their position management requirements.
44    pub fn new(
45        category: Category,
46        symbol: Option<&'a str>,
47        base_coin: Option<&'a str>,
48        settle_coin: Option<&'a str>,
49        limit: Option<usize>,
50    ) -> Self {
51        Self {
52            category,
53            symbol: symbol.map(Cow::Borrowed),
54            base_coin: base_coin.map(Cow::Borrowed),
55            settle_coin: settle_coin.map(Cow::Borrowed),
56            limit,
57        }
58    }
59}
60
61impl<'a> MovePositionRequest<'a> {
62    /// Constructs a new MovePosition request with specified parameters.
63    ///
64    /// Allows customization of the position transfer request. Bots should use this to specify the source and destination UIDs and the list of positions to move.
65    pub fn new(from_uid: u64, to_uid: u64, list: Vec<PositionItem<'a>>) -> Self {
66        Self {
67            from_uid,
68            to_uid,
69            list,
70        }
71    }
72    /// Creates a default MovePosition request.
73    ///
74    /// Returns a request with `from_uid` and `to_uid` set to `0` and an empty position list. Suitable for testing but should be customized with valid UIDs and positions for production.
75    pub fn default() -> MovePositionRequest<'a> {
76        MovePositionRequest::new(0, 0, vec![])
77    }
78}