Skip to main content

nautilus_deribit/python/
enums.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//! Deribit enumerations Python bindings.
17
18use std::str::FromStr;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyTypeInfo, prelude::*, types::PyType};
22use strum::IntoEnumIterator;
23
24use crate::{
25    common::enums::{DeribitCurrency, DeribitProductType},
26    websocket::enums::DeribitUpdateInterval,
27};
28
29#[pymethods]
30impl DeribitCurrency {
31    #[new]
32    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
33        let t = Self::type_object(py);
34        Self::py_from_str(&t, value)
35    }
36
37    fn __hash__(&self) -> isize {
38        *self as isize
39    }
40
41    fn __repr__(&self) -> String {
42        format!(
43            "<{}.{}: '{}'>",
44            stringify!(DeribitCurrency),
45            self.name(),
46            self.value(),
47        )
48    }
49
50    fn __str__(&self) -> String {
51        self.to_string()
52    }
53
54    #[getter]
55    #[must_use]
56    pub fn name(&self) -> &str {
57        self.as_ref()
58    }
59
60    #[getter]
61    #[must_use]
62    pub fn value(&self) -> u8 {
63        *self as u8
64    }
65
66    #[staticmethod]
67    #[must_use]
68    fn variants() -> Vec<String> {
69        Self::iter().map(|x| x.to_string()).collect()
70    }
71
72    #[classmethod]
73    #[pyo3(name = "from_str")]
74    fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
75        let data_str: String = data.str()?.extract()?;
76        Self::from_str(&data_str).map_err(to_pyvalue_err)
77    }
78
79    #[classattr]
80    #[pyo3(name = "BTC")]
81    fn py_btc() -> Self {
82        Self::BTC
83    }
84
85    #[classattr]
86    #[pyo3(name = "ETH")]
87    fn py_eth() -> Self {
88        Self::ETH
89    }
90
91    #[classattr]
92    #[pyo3(name = "USDC")]
93    fn py_usdc() -> Self {
94        Self::USDC
95    }
96
97    #[classattr]
98    #[pyo3(name = "USDT")]
99    fn py_usdt() -> Self {
100        Self::USDT
101    }
102
103    #[classattr]
104    #[pyo3(name = "EURR")]
105    fn py_eurr() -> Self {
106        Self::EURR
107    }
108}
109
110#[pymethods]
111impl DeribitProductType {
112    #[new]
113    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
114        let t = Self::type_object(py);
115        Self::py_from_str(&t, value)
116    }
117
118    fn __hash__(&self) -> isize {
119        *self as isize
120    }
121
122    fn __repr__(&self) -> String {
123        format!(
124            "<{}.{}: '{}'>",
125            stringify!(DeribitProductType),
126            self.name(),
127            self.value(),
128        )
129    }
130
131    fn __str__(&self) -> String {
132        self.to_string()
133    }
134
135    #[getter]
136    #[must_use]
137    pub fn name(&self) -> &str {
138        self.as_ref()
139    }
140
141    #[getter]
142    #[must_use]
143    pub fn value(&self) -> u8 {
144        *self as u8
145    }
146
147    #[staticmethod]
148    #[must_use]
149    fn variants() -> Vec<String> {
150        Self::iter().map(|x| x.to_string()).collect()
151    }
152
153    #[classmethod]
154    #[pyo3(name = "from_str")]
155    fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
156        let data_str: String = data.str()?.extract()?;
157        Self::from_str(&data_str).map_err(to_pyvalue_err)
158    }
159
160    #[classattr]
161    #[pyo3(name = "FUTURE")]
162    fn py_future() -> Self {
163        Self::Future
164    }
165
166    #[classattr]
167    #[pyo3(name = "OPTION")]
168    fn py_option() -> Self {
169        Self::Option
170    }
171
172    #[classattr]
173    #[pyo3(name = "SPOT")]
174    fn py_spot() -> Self {
175        Self::Spot
176    }
177
178    #[classattr]
179    #[pyo3(name = "FUTURE_COMBO")]
180    fn py_future_combo() -> Self {
181        Self::FutureCombo
182    }
183
184    #[classattr]
185    #[pyo3(name = "OPTION_COMBO")]
186    fn py_option_combo() -> Self {
187        Self::OptionCombo
188    }
189}
190
191#[pymethods]
192impl DeribitUpdateInterval {
193    #[new]
194    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
195        let t = Self::type_object(py);
196        Self::py_from_str(&t, value)
197    }
198
199    fn __hash__(&self) -> isize {
200        *self as isize
201    }
202
203    fn __repr__(&self) -> String {
204        format!(
205            "<{}.{}: '{}'>",
206            stringify!(DeribitUpdateInterval),
207            self.name(),
208            self.value(),
209        )
210    }
211
212    fn __str__(&self) -> String {
213        self.to_string()
214    }
215
216    #[getter]
217    #[must_use]
218    pub fn name(&self) -> &str {
219        self.as_ref()
220    }
221
222    #[getter]
223    #[must_use]
224    pub fn value(&self) -> u8 {
225        *self as u8
226    }
227
228    #[staticmethod]
229    #[must_use]
230    fn variants() -> Vec<String> {
231        Self::iter().map(|x| x.to_string()).collect()
232    }
233
234    #[classmethod]
235    #[pyo3(name = "from_str")]
236    fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
237        let data_str: String = data.str()?.extract()?;
238        Self::from_str(&data_str).map_err(to_pyvalue_err)
239    }
240
241    #[classattr]
242    #[pyo3(name = "RAW")]
243    fn py_raw() -> Self {
244        Self::Raw
245    }
246
247    #[classattr]
248    #[pyo3(name = "MS100")]
249    fn py_ms100() -> Self {
250        Self::Ms100
251    }
252
253    #[classattr]
254    #[pyo3(name = "AGG2")]
255    fn py_agg2() -> Self {
256        Self::Agg2
257    }
258}