bybit/models/
position_item.rs

1use crate::prelude::*;
2
3/// Represents a single position to be moved between accounts.
4///
5/// Part of the `MovePositionRequest`, this struct details the position to transfer, including its category, symbol, and trade parameters. Bots use this to specify which positions to move and at what price.
6#[derive(Clone, Default, Serialize)]
7pub struct PositionItem<'a> {
8    /// The product category (e.g., Linear, Inverse).
9    ///
10    /// Specifies the instrument type of the position. Bots must set this to match the position’s contract type.
11    pub category: Category,
12
13    /// The trading pair symbol (e.g., "BTCUSDT").
14    ///
15    /// Identifies the perpetual futures contract for the position. Bots must specify a valid symbol.
16    pub symbol: Cow<'a, str>,
17
18    /// The transfer price.
19    ///
20    /// The price at which the position is transferred, used for valuation between accounts. Bots should set this based on the current mark price or a mutually agreed value to ensure fair transfer.
21    pub price: f64,
22
23    /// The position side (Buy or Sell).
24    ///
25    /// Indicates whether the position is long (Buy) or short (Sell). Bots use this to ensure the correct position direction is transferred.
26    pub side: Side,
27
28    /// The quantity of the position to move.
29    ///
30    /// The amount of the base asset to transfer. Bots should ensure this does not exceed the available position size in the source account.
31    pub qty: f64,
32}
33
34impl<'a> PositionItem<'a> {
35    /// Constructs a new PositionItem with specified parameters.
36    ///
37    /// Allows customization of the position to move. Bots should use this to specify the category, symbol, price, side, and quantity of the position.
38    pub fn new(category: Category, symbol: &'a str, price: f64, side: Side, qty: f64) -> Self {
39        Self {
40            category,
41            symbol: Cow::Borrowed(symbol),
42            price,
43            side,
44            qty,
45        }
46    }
47    /// Creates a default PositionItem.
48    ///
49    /// Returns a position item with `category` set to `Linear`, `symbol` set to `"BTCUSDT"`, `price` and `qty` set to `0.0`, and `side` set to `Buy`. Suitable for testing but should be customized for production.
50    pub fn default() -> PositionItem<'a> {
51        PositionItem::new(Category::Linear, "BTCUSDT", 0.0, Side::Buy, 0.0)
52    }
53}