nautilus_deribit/python/
enums.rs1use std::str::FromStr;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyTypeInfo, prelude::*, types::PyType};
22use strum::IntoEnumIterator;
23
24use crate::{
25 http::models::{DeribitCurrency, DeribitInstrumentKind, DeribitOptionType},
26 websocket::enums::{DeribitUpdateInterval, DeribitWsChannel},
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 DeribitInstrumentKind {
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!(DeribitInstrumentKind),
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 DeribitOptionType {
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!(DeribitOptionType),
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 = "CALL")]
243 fn py_call() -> Self {
244 Self::Call
245 }
246
247 #[classattr]
248 #[pyo3(name = "PUT")]
249 fn py_put() -> Self {
250 Self::Put
251 }
252}
253
254#[pymethods]
255impl DeribitUpdateInterval {
256 #[new]
257 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
258 let t = Self::type_object(py);
259 Self::py_from_str(&t, value)
260 }
261
262 fn __hash__(&self) -> isize {
263 *self as isize
264 }
265
266 fn __repr__(&self) -> String {
267 format!(
268 "<{}.{}: '{}'>",
269 stringify!(DeribitUpdateInterval),
270 self.name(),
271 self.value(),
272 )
273 }
274
275 fn __str__(&self) -> String {
276 self.to_string()
277 }
278
279 #[getter]
280 #[must_use]
281 pub fn name(&self) -> &str {
282 self.as_ref()
283 }
284
285 #[getter]
286 #[must_use]
287 pub fn value(&self) -> u8 {
288 *self as u8
289 }
290
291 #[staticmethod]
292 #[must_use]
293 fn variants() -> Vec<String> {
294 Self::iter().map(|x| x.to_string()).collect()
295 }
296
297 #[classmethod]
298 #[pyo3(name = "from_str")]
299 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
300 let data_str: String = data.str()?.extract()?;
301 Self::from_str(&data_str).map_err(to_pyvalue_err)
302 }
303
304 #[classattr]
305 #[pyo3(name = "RAW")]
306 fn py_raw() -> Self {
307 Self::Raw
308 }
309
310 #[classattr]
311 #[pyo3(name = "MS100")]
312 fn py_ms100() -> Self {
313 Self::Ms100
314 }
315
316 #[classattr]
317 #[pyo3(name = "AGG2")]
318 fn py_agg2() -> Self {
319 Self::Agg2
320 }
321}
322
323#[pymethods]
324impl DeribitWsChannel {
325 #[new]
326 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
327 let t = Self::type_object(py);
328 Self::py_from_str(&t, value)
329 }
330
331 fn __hash__(&self) -> isize {
332 *self as isize
333 }
334
335 fn __repr__(&self) -> String {
336 format!(
337 "<{}.{}: '{}'>",
338 stringify!(DeribitWsChannel),
339 self.name(),
340 self.value(),
341 )
342 }
343
344 fn __str__(&self) -> String {
345 self.to_string()
346 }
347
348 #[getter]
349 #[must_use]
350 pub fn name(&self) -> &str {
351 self.as_ref()
352 }
353
354 #[getter]
355 #[must_use]
356 pub fn value(&self) -> u8 {
357 *self as u8
358 }
359
360 #[staticmethod]
361 #[must_use]
362 fn variants() -> Vec<String> {
363 Self::iter().map(|x| x.to_string()).collect()
364 }
365
366 #[classmethod]
367 #[pyo3(name = "from_str")]
368 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
369 let data_str: String = data.str()?.extract()?;
370 Self::from_str(&data_str).map_err(to_pyvalue_err)
371 }
372
373 #[classattr]
374 #[pyo3(name = "TRADES")]
375 fn py_trades() -> Self {
376 Self::Trades
377 }
378
379 #[classattr]
380 #[pyo3(name = "BOOK")]
381 fn py_book() -> Self {
382 Self::Book
383 }
384
385 #[classattr]
386 #[pyo3(name = "TICKER")]
387 fn py_ticker() -> Self {
388 Self::Ticker
389 }
390
391 #[classattr]
392 #[pyo3(name = "QUOTE")]
393 fn py_quote() -> Self {
394 Self::Quote
395 }
396
397 #[classattr]
398 #[pyo3(name = "PRICE_INDEX")]
399 fn py_price_index() -> Self {
400 Self::PriceIndex
401 }
402
403 #[classattr]
404 #[pyo3(name = "PRICE_RANKING")]
405 fn py_price_ranking() -> Self {
406 Self::PriceRanking
407 }
408
409 #[classattr]
410 #[pyo3(name = "VOLATILITY_INDEX")]
411 fn py_volatility_index() -> Self {
412 Self::VolatilityIndex
413 }
414
415 #[classattr]
416 #[pyo3(name = "ESTIMATED_EXPIRATION_PRICE")]
417 fn py_estimated_expiration_price() -> Self {
418 Self::EstimatedExpirationPrice
419 }
420
421 #[classattr]
422 #[pyo3(name = "PERPETUAL")]
423 fn py_perpetual() -> Self {
424 Self::Perpetual
425 }
426
427 #[classattr]
428 #[pyo3(name = "MARK_PRICE_OPTIONS")]
429 fn py_mark_price_options() -> Self {
430 Self::MarkPriceOptions
431 }
432
433 #[classattr]
434 #[pyo3(name = "PLATFORM_STATE")]
435 fn py_platform_state() -> Self {
436 Self::PlatformState
437 }
438
439 #[classattr]
440 #[pyo3(name = "ANNOUNCEMENTS")]
441 fn py_announcements() -> Self {
442 Self::Announcements
443 }
444
445 #[classattr]
446 #[pyo3(name = "CHART_TRADES")]
447 fn py_chart_trades() -> Self {
448 Self::ChartTrades
449 }
450
451 #[classattr]
452 #[pyo3(name = "USER_ORDERS")]
453 fn py_user_orders() -> Self {
454 Self::UserOrders
455 }
456
457 #[classattr]
458 #[pyo3(name = "USER_TRADES")]
459 fn py_user_trades() -> Self {
460 Self::UserTrades
461 }
462
463 #[classattr]
464 #[pyo3(name = "USER_PORTFOLIO")]
465 fn py_user_portfolio() -> Self {
466 Self::UserPortfolio
467 }
468
469 #[classattr]
470 #[pyo3(name = "USER_CHANGES")]
471 fn py_user_changes() -> Self {
472 Self::UserChanges
473 }
474
475 #[classattr]
476 #[pyo3(name = "USER_ACCESS_LOG")]
477 fn py_user_access_log() -> Self {
478 Self::UserAccessLog
479 }
480}