nautilus_databento/python/
enums.rs1use std::str::FromStr;
17
18use nautilus_core::python::to_pyvalue_err;
19use pyo3::{PyTypeInfo, prelude::*, types::PyType};
20
21use crate::enums::{DatabentoStatisticType, DatabentoStatisticUpdateAction};
22
23#[pymethods]
24impl DatabentoStatisticType {
25 #[new]
26 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
27 let t = Self::type_object(py);
28 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
29 }
30
31 const fn __hash__(&self) -> isize {
32 *self as isize
33 }
34
35 fn __repr__(&self) -> String {
36 format!(
37 "<{}.{}: '{}'>",
38 stringify!(DatabentoStatisticType),
39 self.name(),
40 self.value(),
41 )
42 }
43
44 fn __str__(&self) -> String {
45 self.to_string()
46 }
47
48 #[getter]
49 #[must_use]
50 pub fn name(&self) -> String {
51 self.to_string()
52 }
53
54 #[getter]
55 #[must_use]
56 pub const fn value(&self) -> u8 {
57 *self as u8
58 }
59
60 #[classmethod]
66 #[pyo3(name = "from_str")]
67 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
68 let data_str: &str = data.extract()?;
69 let tokenized = data_str.to_uppercase();
70 Self::from_str(&tokenized).map_err(to_pyvalue_err)
71 }
72 #[classattr]
73 #[pyo3(name = "OPENING_PRICE")]
74 const fn py_opening_price() -> Self {
75 Self::OpeningPrice
76 }
77
78 #[classattr]
79 #[pyo3(name = "INDICATIVE_OPENING_PRICE")]
80 const fn py_indicative_opening_price() -> Self {
81 Self::IndicativeOpeningPrice
82 }
83
84 #[classattr]
85 #[pyo3(name = "SETTLEMENT_PRICE")]
86 const fn py_settlement_price() -> Self {
87 Self::SettlementPrice
88 }
89
90 #[classattr]
91 #[pyo3(name = "TRADING_SESSION_LOW_PRICE")]
92 const fn py_trading_session_low_price() -> Self {
93 Self::TradingSessionLowPrice
94 }
95
96 #[classattr]
97 #[pyo3(name = "TRADING_SESSION_HIGH_PRICE")]
98 const fn py_trading_session_high_price() -> Self {
99 Self::TradingSessionHighPrice
100 }
101
102 #[classattr]
103 #[pyo3(name = "CLEARED_VOLUME")]
104 const fn py_cleared_volume() -> Self {
105 Self::ClearedVolume
106 }
107
108 #[classattr]
109 #[pyo3(name = "LOWEST_OFFER")]
110 const fn py_lowest_offer() -> Self {
111 Self::LowestOffer
112 }
113
114 #[classattr]
115 #[pyo3(name = "HIGHEST_BID")]
116 const fn py_highest_bid() -> Self {
117 Self::HighestBid
118 }
119
120 #[classattr]
121 #[pyo3(name = "OPEN_INTEREST")]
122 const fn py_open_interest() -> Self {
123 Self::OpenInterest
124 }
125
126 #[classattr]
127 #[pyo3(name = "FIXING_PRICE")]
128 const fn py_fixing_price() -> Self {
129 Self::FixingPrice
130 }
131
132 #[classattr]
133 #[pyo3(name = "CLOSE_PRICE")]
134 const fn py_close_price() -> Self {
135 Self::ClosePrice
136 }
137
138 #[classattr]
139 #[pyo3(name = "NET_CHANGE")]
140 const fn py_net_change() -> Self {
141 Self::NetChange
142 }
143
144 #[classattr]
145 #[pyo3(name = "VWAP")]
146 const fn py_vwap() -> Self {
147 Self::Vwap
148 }
149}
150
151#[pymethods]
152impl DatabentoStatisticUpdateAction {
153 #[new]
154 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
155 let t = Self::type_object(py);
156 Self::py_from_str(&t, value).map_err(to_pyvalue_err)
157 }
158
159 const fn __hash__(&self) -> isize {
160 *self as isize
161 }
162
163 fn __repr__(&self) -> String {
164 format!(
165 "<{}.{}: '{}'>",
166 stringify!(DatabentoStatisticUpdateAction),
167 self.name(),
168 self.value(),
169 )
170 }
171
172 fn __str__(&self) -> String {
173 self.to_string()
174 }
175
176 #[getter]
177 #[must_use]
178 pub fn name(&self) -> String {
179 self.to_string()
180 }
181
182 #[getter]
183 #[must_use]
184 pub const fn value(&self) -> u8 {
185 *self as u8
186 }
187
188 #[classmethod]
194 #[pyo3(name = "from_str")]
195 fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
196 let data_str: &str = data.extract()?;
197 let tokenized = data_str.to_uppercase();
198 Self::from_str(&tokenized).map_err(to_pyvalue_err)
199 }
200 #[classattr]
201 #[pyo3(name = "ADDED")]
202 const fn py_added() -> Self {
203 Self::Added
204 }
205
206 #[classattr]
207 #[pyo3(name = "DELETED")]
208 const fn py_deleted() -> Self {
209 Self::Deleted
210 }
211}