bybit/models/position_event.rs
1use crate::prelude::*;
2
3/// Represents a position event in Bybit's perpetual futures market.
4///
5/// This struct is used in WebSocket streams to provide updates about a user's open positions, including size, leverage, and profit/loss.
6///
7/// # Bybit API Reference
8/// The Bybit API (https://bybit-exchange.github.io/docs/v5/websocket/private/position) provides position data via WebSocket.
9///
10/// # Perpetual Futures Context
11/// Positions in perpetual futures represent a trader's exposure to a market. Bots monitor position updates to manage risk, adjust leverage, or trigger stop-loss/take-profit orders.
12#[derive(Serialize, Deserialize, Debug, Clone)]
13#[serde(rename_all = "camelCase")]
14pub struct PositionEvent {
15 /// The unique identifier for the position event.
16 ///
17 /// Used to track specific position updates. Bots can use this to correlate events with internal state.
18 pub id: String,
19
20 /// The WebSocket topic (e.g., "position").
21 ///
22 /// Identifies the position data stream. Bots use this to filter relevant messages.
23 pub topic: String,
24
25 /// The timestamp when the event was created (in milliseconds).
26 ///
27 /// Indicates when the position update occurred. Bots use this for time-based analysis.
28 pub creation_time: u64,
29
30 /// The position data for the event.
31 ///
32 /// Contains details about the user's positions. Bots process this to manage open trades.
33 pub data: Vec<PositionData>,
34}