nautilus_deribit/common/models.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Models shared between Deribit HTTP and WebSocket layers.
17
18use nautilus_core::serialization::{deserialize_decimal, deserialize_optional_decimal};
19use rust_decimal::Decimal;
20use serde::{Deserialize, Serialize};
21
22/// A single leg entry of a Deribit combo trade.
23///
24/// Appears in the `legs` array of a combo's public trade message
25/// (`/public/get_last_trades_by_currency` with `kind=option_combo|future_combo`,
26/// and the `trades.{combo}.{interval}` subscription channel). Each leg is also
27/// published independently on the leg instrument's own `trades.{instrument}.*`
28/// stream, carrying `combo_id` and `combo_trade_id` to link back to the parent.
29#[derive(Clone, Debug, Serialize, Deserialize)]
30pub struct DeribitTradeLeg {
31 /// Trade timestamp in milliseconds.
32 pub timestamp: i64,
33 /// Trade price.
34 #[serde(deserialize_with = "deserialize_decimal")]
35 pub price: Decimal,
36 /// Trade amount.
37 #[serde(deserialize_with = "deserialize_decimal")]
38 pub amount: Decimal,
39 /// Trade direction: `buy` or `sell`.
40 pub direction: String,
41 /// Underlying index price at trade time (may be empty on older historical trades,
42 /// matching the optionality on the parent [`crate::http::models::DeribitPublicTrade`]).
43 #[serde(default, deserialize_with = "deserialize_optional_decimal")]
44 pub index_price: Option<Decimal>,
45 /// Leg instrument name (e.g., `BTC-PERPETUAL`).
46 pub instrument_name: String,
47 /// Per-instrument trade sequence number.
48 pub trade_seq: i64,
49 /// Mark price at trade time (may be empty on older historical trades,
50 /// matching the optionality on the parent [`crate::http::models::DeribitPublicTrade`]).
51 #[serde(default, deserialize_with = "deserialize_optional_decimal")]
52 pub mark_price: Option<Decimal>,
53 /// Tick direction: 0 = Plus, 1 = Zero-Plus, 2 = Minus, 3 = Zero-Minus.
54 pub tick_direction: i32,
55 /// The combo instrument that produced this leg.
56 pub combo_id: String,
57 /// Trade size in contract units (may be absent on historical combo trades,
58 /// matching the optionality on the parent [`crate::http::models::DeribitPublicTrade`]).
59 #[serde(default, deserialize_with = "deserialize_optional_decimal")]
60 pub contracts: Option<Decimal>,
61 /// Unique (per currency) trade identifier for the leg.
62 pub trade_id: String,
63 /// Trade identifier of the parent combo trade.
64 pub combo_trade_id: String,
65 /// Implied volatility (option legs only).
66 #[serde(default, deserialize_with = "deserialize_optional_decimal")]
67 pub iv: Option<Decimal>,
68}