nautilus_bitmex/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::common::enums::BitmexSymbolStatus;
25
26#[pymethods]
27impl BitmexSymbolStatus {
28 #[new]
29 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
30 let t = Self::type_object(py);
31 Self::py_from_str(&t, value)
32 }
33
34 const fn __hash__(&self) -> isize {
35 *self as isize
36 }
37
38 fn __repr__(&self) -> String {
39 format!(
40 "<{}.{}: '{}'>",
41 stringify!(BitmexSymbolStatus),
42 self.name(),
43 self.value(),
44 )
45 }
46
47 fn __str__(&self) -> String {
48 self.to_string()
49 }
50
51 #[getter]
52 #[must_use]
53 pub fn name(&self) -> &str {
54 self.as_ref()
55 }
56
57 #[getter]
58 #[must_use]
59 pub const fn value(&self) -> u8 {
60 *self as u8
61 }
62
63 #[staticmethod]
64 #[must_use]
65 fn variants() -> Vec<String> {
66 Self::iter().map(|x| x.to_string()).collect()
67 }
68
69 #[classmethod]
70 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
71 let data_str: String = data.str()?.extract()?;
72 Self::from_str(&data_str).map_err(to_pyvalue_err)
73 }
74
75 #[classattr]
76 #[pyo3(name = "OPEN")]
77 const fn py_open() -> Self {
78 Self::Open
79 }
80
81 #[classattr]
82 #[pyo3(name = "CLOSED")]
83 const fn py_closed() -> Self {
84 Self::Closed
85 }
86
87 #[classattr]
88 #[pyo3(name = "UNLISTED")]
89 const fn py_unlisted() -> Self {
90 Self::Unlisted
91 }
92}