deribit_base/model/
instrument.rs1use crate::model::currency::Currency;
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "lowercase")]
13pub enum InstrumentKind {
14 Future,
16 Option,
18 Spot,
20 #[serde(rename = "future_combo")]
22 FutureCombo,
23 #[serde(rename = "option_combo")]
25 OptionCombo,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30#[serde(rename_all = "lowercase")]
31pub enum OptionType {
32 Call,
34 Put,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(rename_all = "lowercase")]
41pub enum InstrumentType {
42 Linear,
44 Reversed,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct Instrument {
51 pub instrument_name: String,
53 pub kind: InstrumentKind,
55 pub currency: Currency,
57 pub is_active: bool,
59 pub expiration_timestamp: Option<i64>,
61 pub strike: Option<f64>,
63 pub option_type: Option<OptionType>,
65 pub tick_size: f64,
67 pub min_trade_amount: f64,
69 pub contract_size: f64,
71 pub settlement_period: Option<String>,
73 pub instrument_type: Option<InstrumentType>,
75 pub quote_currency: Option<Currency>,
77 pub settlement_currency: Option<Currency>,
79 pub creation_timestamp: Option<i64>,
81 pub max_leverage: Option<f64>,
83 pub maker_commission: Option<f64>,
85 pub taker_commission: Option<f64>,
87}
88
89impl Instrument {
90 pub fn is_perpetual(&self) -> bool {
92 self.expiration_timestamp.is_none() && self.kind == InstrumentKind::Future
93 }
94
95 pub fn is_option(&self) -> bool {
97 self.kind == InstrumentKind::Option
98 }
99
100 pub fn is_future(&self) -> bool {
102 matches!(
103 self.kind,
104 InstrumentKind::Future | InstrumentKind::FutureCombo
105 )
106 }
107
108 pub fn is_spot(&self) -> bool {
110 self.kind == InstrumentKind::Spot
111 }
112
113 pub fn currency_str(&self) -> &'static str {
115 self.currency.as_str()
116 }
117}