deribit_http/model/response/
trade.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 15/9/25
5******************************************************************************/
6use crate::model::TradeAllocation;
7use pretty_simple_display::{DebugPretty, DisplaySimple};
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11/// User trade response structure for order-specific trade queries
12#[skip_serializing_none]
13#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
14pub struct UserTradeResponseByOrder {
15    /// Unique identifier for the trade
16    pub trade_id: String,
17    /// Trade amount. For perpetual and inverse futures the amount is in USD units.
18    /// For options and linear futures it is the underlying base currency coin.
19    pub amount: f64,
20
21    /// Advanced type of user order: "usd" or "implv" (only for options; omitted if not applicable)
22    pub advanced: Option<String>,
23
24    /// true if user order was created with API
25    pub api: bool,
26
27    /// ID of the Block RFQ - when trade was part of the Block RFQ
28    pub block_rfq_id: Option<u64>,
29
30    /// ID of the Block RFQ quote - when trade was part of the Block RFQ
31    pub block_rfq_quote_id: Option<u64>,
32
33    /// Block trade id - when trade was part of a block trade
34    pub block_trade_id: Option<String>,
35
36    /// Optional field containing combo instrument name if the trade is a combo trade
37    pub combo_id: Option<String>,
38
39    /// Optional field containing combo trade identifier if the trade is a combo trade
40    pub combo_trade_id: Option<f64>,
41
42    /// Trade size in contract units (optional, may be absent in historical trades)
43    pub contracts: Option<f64>,
44
45    /// Direction: buy, or sell
46    pub direction: String,
47
48    /// User's fee in units of the specified fee_currency
49    pub fee: f64,
50
51    /// Currency, i.e "BTC", "ETH", "USDC"
52    pub fee_currency: String,
53
54    /// Index Price at the moment of trade
55    pub index_price: f64,
56
57    /// Unique instrument identifier
58    pub instrument_name: String,
59
60    /// Option implied volatility for the price (Option only)
61    pub iv: Option<f64>,
62
63    /// User defined label (presented only when previously set for order by user)
64    pub label: Option<String>,
65
66    /// Optional field containing leg trades if trade is a combo trade
67    pub legs: Option<Vec<serde_json::Value>>,
68
69    /// Optional field (only for trades caused by liquidation):
70    /// "M" when maker side was under liquidation, "T" when taker side was under liquidation,
71    /// "MT" when both sides were under liquidation
72    pub liquidation: Option<String>,
73
74    /// Describes what was role of users order: "M" when it was maker order, "T" when it was taker order
75    pub liquidity: String,
76
77    /// Mark Price at the moment of trade
78    pub mark_price: f64,
79
80    /// Always null according to docs
81    pub matching_id: Option<String>,
82
83    /// true if user order is MMP
84    pub mmp: bool,
85
86    /// Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade
87    pub order_id: String,
88
89    /// Order type: "limit", "market", or "liquidation"
90    pub order_type: String,
91
92    /// true if user order is post-only
93    pub post_only: Option<String>,
94
95    /// Price in base currency
96    pub price: f64,
97
98    /// Profit and loss in base currency
99    pub profit_loss: f64,
100
101    /// QuoteID of the user order (optional, present only for orders placed with private/mass_quote)
102    pub quote_id: Option<String>,
103
104    /// QuoteSet of the user order (optional, present only for orders placed with private/mass_quote)
105    pub quote_set_id: Option<String>,
106
107    /// true if user order is reduce-only
108    pub reduce_only: Option<String>,
109
110    /// true if user order is marked by the platform as a risk reducing order
111    /// (can apply only to orders placed by PM users)
112    pub risk_reducing: bool,
113
114    /// Order state: "open", "filled", "rejected", "cancelled", "untriggered" or "archive"
115    pub state: String,
116
117    /// Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick)
118    pub tick_direction: i32,
119
120    /// The timestamp of the trade (milliseconds since the UNIX epoch)
121    pub timestamp: u64,
122
123    /// List of allocations for Block RFQ pre-allocation
124    pub trade_allocations: Option<Vec<TradeAllocation>>,
125
126    /// The sequence number of the trade within instrument
127    pub trade_seq: u64,
128
129    /// Underlying price for implied volatility calculations (Options only)
130    pub underlying_price: Option<f64>,
131}