bybit/models/execution_data.rs
1use crate::prelude::*;
2
3/// Represents detailed data about a single trade execution.
4///
5/// This struct contains comprehensive information about a trade, including price, quantity, fees, and order details.
6///
7/// # Bybit API Reference
8/// Part of the execution WebSocket stream (https://bybit-exchange.github.io/docs/v5/websocket/private/execution).
9///
10/// # Perpetual Futures Context
11/// Execution data is critical for tracking trade performance and costs. Bots use this to update position sizes, calculate realized PnL, and monitor fees.
12#[derive(Serialize, Deserialize, Debug, Clone)]
13#[serde(rename_all = "camelCase")]
14pub struct ExecutionData {
15 /// The category of the execution (e.g., "linear").
16 ///
17 /// Specifies the contract type (e.g., USDT-margined futures). Bots must handle different categories due to varying margin and settlement rules.
18 pub category: String,
19
20 /// The trading pair symbol (e.g., "BTCUSDT").
21 ///
22 /// Identifies the market for the execution. Bots filter by symbol to process relevant trades.
23 pub symbol: String,
24
25 /// The fee charged for the execution.
26 ///
27 /// Represents the trading cost for the executed trade. Bots must include this in PnL calculations to ensure accurate profitability tracking.
28 #[serde(with = "string_to_float")]
29 pub exec_fee: f64,
30
31 /// The unique identifier for the execution.
32 ///
33 /// Used to track individual trades. Bots can use this to match executions with orders.
34 pub exec_id: String,
35
36 /// The price at which the trade was executed.
37 ///
38 /// The actual price of the filled order. Bots use this to update position entry prices and calculate PnL.
39 #[serde(with = "string_to_float")]
40 pub exec_price: f64,
41
42 /// The quantity executed in the trade.
43 ///
44 /// The volume of the trade (in contracts or base currency). Bots use this to update position sizes and track order fills.
45 #[serde(with = "string_to_float")]
46 pub exec_qty: f64,
47
48 /// The type of execution (e.g., "Trade", "Bust").
49 ///
50 /// Indicates the nature of the execution (e.g., normal trade or liquidation). Bots must handle different types appropriately.
51 pub exec_type: String,
52
53 /// The value of the executed trade (in quote currency).
54 ///
55 /// Calculated as `exec_price * exec_qty`. Bots use this to assess trade size and impact on margin.
56 #[serde(with = "string_to_float")]
57 pub exec_value: f64,
58
59 /// Whether the execution was a maker order.
60 ///
61 /// If `true`, the trade added liquidity and likely incurred a lower fee. Bots can use this to optimize order placement for cost efficiency.
62 pub is_maker: bool,
63
64 /// The fee rate applied to the execution.
65 ///
66 /// The percentage fee charged (e.g., 0.0006 for 0.06%). Bots use this to verify fee calculations and optimize trading costs.
67 #[serde(rename = "feeRate", with = "string_to_float")]
68 pub fee_rate: f64,
69
70 /// The implied volatility for the trade (as a string).
71 ///
72 /// Relevant for options trading. For futures bots, this may be less critical but can indicate market expectations of volatility.
73 #[serde(rename = "tradeIv")]
74 pub trade_iv: String,
75
76 /// The mark implied volatility (as a string).
77 ///
78 /// The implied volatility based on the mark price. Bots can use this for volatility-based strategies in options or futures.
79 #[serde(rename = "markIv")]
80 pub mark_iv: String,
81
82 /// The ID of the block trade (if applicable).
83 ///
84 /// Identifies large trades executed off the order book. Bots can monitor this for institutional activity that may impact prices.
85 #[serde(rename = "blockTradeId")]
86 pub block_trade_id: String,
87
88 /// The current mark price at the time of execution.
89 ///
90 /// Used for PnL and margin calculations. Bots use this to track unrealized PnL and liquidation risks.
91 #[serde(with = "string_to_float")]
92 pub mark_price: f64,
93
94 /// The index price at the time of execution.
95 ///
96 /// The reference price for the asset. Bots use this to calculate funding rates and fair value.
97 #[serde(with = "string_to_float")]
98 pub index_price: f64,
99
100 /// The underlying price at the time of execution.
101 ///
102 /// The price of the underlying asset (e.g., spot price). Bots use this for arbitrage or hedging strategies.
103 #[serde(with = "string_to_float")]
104 pub underlying_price: f64,
105
106 /// The remaining quantity to be filled for the order.
107 ///
108 /// Indicates how much of the order is still open. Bots use this to track partial fills and manage open orders.
109 #[serde(with = "string_to_float")]
110 pub leaves_qty: f64,
111
112 /// The ID of the order associated with the execution.
113 ///
114 /// Links the execution to the original order. Bots use this to track order status and fills.
115 pub order_id: String,
116
117 /// The user-defined ID for the order.
118 ///
119 /// Allows bots to assign custom identifiers to orders for internal tracking.
120 pub order_link_id: String,
121
122 /// The price specified in the order.
123 ///
124 /// The target price for the order (e.g., limit order price). Bots use this to verify execution prices against order prices.
125 #[serde(with = "string_to_float")]
126 pub order_price: f64,
127
128 /// The total quantity specified in the order.
129 ///
130 /// The full size of the order. Bots use this to calculate fill percentages and manage order execution.
131 #[serde(with = "string_to_float")]
132 pub order_qty: f64,
133
134 /// The type of order (e.g., "Limit", "Market").
135 ///
136 /// Specifies the order placement method. Bots use this to determine execution behavior and strategy alignment.
137 pub order_type: String,
138
139 /// The type of stop order (if applicable, e.g., "StopLoss").
140 ///
141 /// Indicates if the order was a conditional stop order. Bots use this to manage risk and automate exits.
142 #[serde(rename = "stopOrderType")]
143 pub stop_order_type: String,
144
145 /// The side of the order ("Buy" or "Sell").
146 ///
147 /// Indicates the direction of the trade. Bots use this to update position direction and exposure.
148 pub side: String,
149
150 /// The timestamp when the execution occurred (in milliseconds).
151 ///
152 /// Indicates the exact time of the trade. Bots use this for precise timing and correlation with market data.
153 #[serde(with = "string_to_u64")]
154 pub exec_time: u64,
155
156 /// Whether leverage was used (as a string, e.g., "1").
157 ///
158 /// Indicates if the trade used borrowed funds. Bots use this to adjust margin and risk calculations.
159 pub is_leverage: String,
160
161 /// The size of the position closed by the execution (as a string).
162 ///
163 /// Relevant for closing trades. Bots use this to update position sizes and track closures.
164 pub closed_size: String,
165
166 /// The sequence number for the execution.
167 ///
168 /// Used to ensure executions are processed in order. Bots validate sequence numbers to avoid missing updates.
169 pub seq: u64,
170}