Skip to main content

PositionData

Struct PositionData 

Source
pub struct PositionData {
Show 32 fields pub position_idx: u8, pub trade_mode: u8, pub risk_id: u8, pub risk_limit_value: String, pub symbol: String, pub side: Side, pub size: f64, pub entry_price: f64, pub leverage: String, pub position_value: f64, pub position_balance: f64, pub mark_price: f64, pub position_im: String, pub position_mm: String, pub take_profit: f64, pub stop_loss: f64, pub trailing_stop: Option<f64>, pub unrealised_pnl: String, pub cum_realised_pnl: String, pub created_time: u64, pub updated_time: u64, pub tpsl_mode: String, pub liq_price: f64, pub bust_price: Option<f64>, pub category: String, pub position_status: String, pub adl_rank_indicator: u8, pub auto_add_margin: u8, pub mmr_sys_updated_time: Option<u64>, pub leverage_sys_updated_time: Option<u64>, pub seq: u64, pub is_reduce_only: bool,
}
Expand description

Represents detailed data about a single position in Bybit’s perpetual futures market.

This struct contains comprehensive information about a position, including size, leverage, profit/loss, and risk parameters.

§Bybit API Reference

Part of the position WebSocket stream (https://bybit-exchange.github.io/docs/v5/websocket/private/position).

§Perpetual Futures Context

Position data is critical for risk management in futures trading. Bots use this to monitor margin requirements, unrealized PnL, and liquidation risks.

Fields§

§position_idx: u8

The position index (0 for one-way mode, 1 for buy-side hedge, 2 for sell-side hedge).

Indicates the position mode. Bots must handle different indices for hedged vs. one-way positions to manage risk accurately.

§trade_mode: u8

The trading mode (0 for regular, 1 for isolated margin).

Specifies whether the position uses cross or isolated margin. Bots need to adjust margin calculations based on this mode.

§risk_id: u8

The risk ID for the position’s risk limit.

Corresponds to Bybit’s risk limit tiers, which define margin requirements. Bots should monitor this to ensure compliance with risk limits.

§risk_limit_value: String

The risk limit value (as a string, e.g., “1000000”).

Represents the maximum exposure allowed for the risk tier. Bots use this to cap position sizes and avoid margin violations.

§symbol: String

The trading pair symbol (e.g., “BTCUSDT”).

Identifies the market for the position. Bots filter by symbol to manage specific markets.

§side: Side

The side of the position (“Buy” for long, “Sell” for short).

Indicates the direction of the position. Bots use this to calculate exposure and hedge positions.

§size: f64

The size of the position (in contracts or base currency).

Represents the volume of the position. Bots monitor this to manage exposure and ensure it aligns with strategy limits.

§entry_price: f64

The average entry price of the position.

The price at which the position was opened. Bots use this to calculate unrealized PnL and set stop-loss/take-profit levels.

§leverage: String

The leverage used for the position (as a string, e.g., “10”).

Indicates the leverage multiplier (e.g., 10x). Higher leverage increases potential returns but also liquidation risk. Bots must adjust position sizes based on leverage to manage risk.

§position_value: f64

The total value of the position (in quote currency).

Calculated as size * entry price. Bots use this to assess exposure and margin requirements.

§position_balance: f64

The margin allocated to the position.

Represents the funds reserved for the position. Bots monitor this to ensure sufficient margin and avoid liquidation.

§mark_price: f64

The current mark price of the position.

The fair value of the asset, used for PnL and margin calculations. Bots use this to track unrealized PnL and liquidation risks.

§position_im: String

The initial margin requirement (as a string, e.g., “1000”).

The minimum margin needed to open the position. Bots use this to calculate capital requirements and optimize margin usage.

§position_mm: String

The maintenance margin requirement (as a string, e.g., “500”).

The minimum margin needed to maintain the position. Falling below this triggers liquidation. Bots must monitor this closely to avoid forced closures.

§take_profit: f64

The take-profit price for the position.

The price at which the position will automatically close for a profit. Bots can set this to lock in gains and automate exits.

§stop_loss: f64

The stop-loss price for the position.

The price at which the position will automatically close to limit losses. Bots use this to manage downside risk.

§trailing_stop: Option<f64>

The trailing stop price (optional).

A dynamic stop-loss that follows the market price. Bots can use this for trend-following strategies to lock in profits while allowing upside potential.

§unrealised_pnl: String

The unrealized profit and loss (as a string, e.g., “100.50”).

The current profit or loss based on the mark price. Bots use this to monitor performance and make real-time adjustments.

§cum_realised_pnl: String

The cumulative realized profit and loss (as a string, e.g., “500.75”).

The total profit or loss from closed portions of the position. Bots use this to track overall performance.

§created_time: u64

The timestamp when the position was created (in milliseconds).

Indicates when the position was opened. Bots use this for position aging and strategy timing.

§updated_time: u64

The timestamp when the position was last updated (in milliseconds).

Indicates the most recent change to the position. Bots use this to track updates and ensure data freshness.

§tpsl_mode: String

The take-profit/stop-loss mode (e.g., “Full” or “Partial”).

Specifies how TP/SL orders are applied. Bots must handle different modes to execute correct exit strategies.

§liq_price: f64

The liquidation price for the position.

The price at which the position will be forcibly closed due to insufficient margin. Bots must monitor this to avoid unexpected liquidations, especially in volatile markets.

§bust_price: Option<f64>

The bankruptcy price for the position (optional).

The price at which the position’s margin is completely depleted, leading to a total loss. This is critical for bots to monitor, as it represents the worst-case scenario. Bots should use this to set conservative stop-losses and avoid catastrophic losses.

§category: String

The category of the position (e.g., “linear” for USDT-margined futures).

Specifies the contract type. Bots must handle different categories (e.g., linear vs. inverse) due to differences in margin and settlement.

§position_status: String

The status of the position (e.g., “Normal”).

Indicates whether the position is active or in a special state (e.g., liquidation). Bots use this to filter active positions for management.

§adl_rank_indicator: u8

The auto-deleveraging (ADL) rank indicator (0-4).

Indicates the likelihood of the position being auto-deleveraged in extreme market conditions. Higher ranks mean higher risk. Bots should monitor this to reduce exposure in volatile markets.

§auto_add_margin: u8

Whether auto-margin addition is enabled (0 for disabled, 1 for enabled).

If enabled, Bybit automatically adds margin to prevent liquidation. Bots should account for this in margin management to avoid unexpected changes.

§mmr_sys_updated_time: Option<u64>

The timestamp when the maintenance margin rate was last updated (optional, in milliseconds).

Indicates when margin requirements changed. Bots can use this to track margin updates and adjust strategies.

§leverage_sys_updated_time: Option<u64>

The timestamp when the leverage was last updated (optional, in milliseconds).

Indicates when leverage settings changed. Bots should monitor this to ensure leverage aligns with risk parameters.

§seq: u64

The sequence number for the position update.

Used to ensure updates are processed in order. Bots should validate sequence numbers to avoid missing or duplicate updates.

§is_reduce_only: bool

Whether the position is reduce-only.

If true, the position can only reduce size (e.g., close trades). Bots must respect this to avoid placing invalid orders.

Trait Implementations§

Source§

impl Clone for PositionData

Source§

fn clone(&self) -> PositionData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PositionData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PositionData

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PositionData

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,