nautilus_okx/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::{
25 OKXContractType, OKXInstrumentType, OKXMarginMode, OKXOrderStatus, OKXPositionMode,
26 OKXTradeMode, OKXVipLevel,
27};
28
29#[pymethods]
30impl OKXInstrumentType {
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!(OKXInstrumentType),
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 = "ANY")]
81 fn py_any() -> Self {
82 Self::Any
83 }
84
85 #[classattr]
86 #[pyo3(name = "SPOT")]
87 fn py_spot() -> Self {
88 Self::Spot
89 }
90
91 #[classattr]
92 #[pyo3(name = "MARGIN")]
93 fn py_margin() -> Self {
94 Self::Margin
95 }
96
97 #[classattr]
98 #[pyo3(name = "SWAP")]
99 fn py_swap() -> Self {
100 Self::Swap
101 }
102
103 #[classattr]
104 #[pyo3(name = "FUTURES")]
105 fn futures() -> Self {
106 Self::Futures
107 }
108
109 #[classattr]
110 #[pyo3(name = "OPTION")]
111 fn option() -> Self {
112 Self::Option
113 }
114}
115
116#[pymethods]
117impl OKXContractType {
118 #[new]
119 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
120 let t = Self::type_object(py);
121 Self::py_from_str(&t, value)
122 }
123
124 fn __hash__(&self) -> isize {
125 *self as isize
126 }
127
128 fn __repr__(&self) -> String {
129 format!(
130 "<{}.{}: '{}'>",
131 stringify!(OKXContractType),
132 self.name(),
133 self.value(),
134 )
135 }
136
137 fn __str__(&self) -> String {
138 self.to_string()
139 }
140
141 #[getter]
142 #[must_use]
143 pub fn name(&self) -> &str {
144 self.as_ref()
145 }
146
147 #[getter]
148 #[must_use]
149 pub fn value(&self) -> u8 {
150 *self as u8
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 #[staticmethod]
161 #[must_use]
162 fn variants() -> Vec<String> {
163 Self::iter().map(|x| x.to_string()).collect()
164 }
165
166 #[classattr]
167 #[pyo3(name = "NONE")]
168 fn py_none() -> Self {
169 Self::None
170 }
171
172 #[classattr]
173 #[pyo3(name = "LINEAR")]
174 fn py_linear() -> Self {
175 Self::Linear
176 }
177
178 #[classattr]
179 #[pyo3(name = "INVERSE")]
180 fn py_inverse() -> Self {
181 Self::Inverse
182 }
183}
184
185#[pymethods]
186impl OKXMarginMode {
187 #[new]
188 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
189 let t = Self::type_object(py);
190 Self::py_from_str(&t, value)
191 }
192
193 fn __hash__(&self) -> isize {
194 *self as isize
195 }
196
197 fn __repr__(&self) -> String {
198 format!(
199 "<{}.{}: '{}'>",
200 stringify!(OKXMarginMode),
201 self.name(),
202 self.value(),
203 )
204 }
205
206 fn __str__(&self) -> String {
207 self.to_string()
208 }
209
210 #[getter]
211 #[must_use]
212 pub fn name(&self) -> &str {
213 self.as_ref()
214 }
215
216 #[getter]
217 #[must_use]
218 pub fn value(&self) -> u8 {
219 *self as u8
220 }
221
222 #[staticmethod]
223 #[must_use]
224 fn variants() -> Vec<String> {
225 Self::iter().map(|x| x.to_string()).collect()
226 }
227
228 #[classmethod]
229 #[pyo3(name = "from_str")]
230 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
231 let data_str: String = data.str()?.extract()?;
232 Self::from_str(&data_str).map_err(to_pyvalue_err)
233 }
234
235 #[classattr]
236 #[pyo3(name = "NONE")]
237 fn py_none() -> Self {
238 Self::None
239 }
240
241 #[classattr]
242 #[pyo3(name = "ISOLATED")]
243 fn py_isolated() -> Self {
244 Self::Isolated
245 }
246
247 #[classattr]
248 #[pyo3(name = "CROSS")]
249 fn py_cross() -> Self {
250 Self::Cross
251 }
252}
253
254#[pymethods]
255impl OKXTradeMode {
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!(OKXTradeMode),
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 = "CASH")]
306 fn py_cash() -> Self {
307 Self::Cash
308 }
309
310 #[classattr]
311 #[pyo3(name = "ISOLATED")]
312 fn py_isolated() -> Self {
313 Self::Isolated
314 }
315
316 #[classattr]
317 #[pyo3(name = "CROSS")]
318 fn py_cross() -> Self {
319 Self::Cross
320 }
321
322 #[classattr]
323 #[pyo3(name = "SPOT_ISOLATED")]
324 fn py_spot_isolated() -> Self {
325 Self::SpotIsolated
326 }
327}
328
329#[pymethods]
330impl OKXPositionMode {
331 #[new]
332 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
333 let t = Self::type_object(py);
334 Self::py_from_str(&t, value)
335 }
336
337 fn __hash__(&self) -> isize {
338 *self as isize
339 }
340
341 fn __repr__(&self) -> String {
342 format!(
343 "<{}.{}: '{}'>",
344 stringify!(OKXPositionMode),
345 self.name(),
346 self.value(),
347 )
348 }
349
350 fn __str__(&self) -> String {
351 self.to_string()
352 }
353
354 #[getter]
355 #[must_use]
356 pub fn name(&self) -> &str {
357 self.as_ref()
358 }
359
360 #[getter]
361 #[must_use]
362 pub fn value(&self) -> u8 {
363 *self as u8
364 }
365
366 #[staticmethod]
367 #[must_use]
368 fn variants() -> Vec<String> {
369 Self::iter().map(|x| x.to_string()).collect()
370 }
371
372 #[classmethod]
373 #[pyo3(name = "from_str")]
374 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
375 let data_str: String = data.str()?.extract()?;
376 Self::from_str(&data_str).map_err(to_pyvalue_err)
377 }
378
379 #[classattr]
380 #[pyo3(name = "NET_MODE")]
381 fn py_net_mode() -> Self {
382 Self::NetMode
383 }
384
385 #[classattr]
386 #[pyo3(name = "LONG_SHORT_MODE")]
387 fn py_long_short_mode() -> Self {
388 Self::LongShortMode
389 }
390}
391
392#[pymethods]
393impl OKXOrderStatus {
394 #[new]
395 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
396 let t = Self::type_object(py);
397 Self::py_from_str(&t, value)
398 }
399
400 fn __hash__(&self) -> isize {
401 *self as isize
402 }
403
404 fn __repr__(&self) -> String {
405 format!(
406 "<{}.{}: '{}'>",
407 stringify!(OKXOrderStatus),
408 self.name(),
409 self.value(),
410 )
411 }
412
413 fn __str__(&self) -> String {
414 self.to_string()
415 }
416
417 #[getter]
418 #[must_use]
419 pub fn name(&self) -> &str {
420 self.as_ref()
421 }
422
423 #[getter]
424 #[must_use]
425 pub fn value(&self) -> u8 {
426 *self as u8
427 }
428
429 #[staticmethod]
430 #[must_use]
431 fn variants() -> Vec<String> {
432 Self::iter().map(|x| x.to_string()).collect()
433 }
434
435 #[classmethod]
436 #[pyo3(name = "from_str")]
437 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
438 let data_str: String = data.str()?.extract()?;
439 Self::from_str(&data_str).map_err(to_pyvalue_err)
440 }
441
442 #[classattr]
443 #[pyo3(name = "CANCELED")]
444 fn py_canceled() -> Self {
445 Self::Canceled
446 }
447
448 #[classattr]
449 #[pyo3(name = "LIVE")]
450 fn py_live() -> Self {
451 Self::Live
452 }
453
454 #[classattr]
455 #[pyo3(name = "EFFECTIVE")]
456 fn py_effective() -> Self {
457 Self::Effective
458 }
459
460 #[classattr]
461 #[pyo3(name = "PARTIALLY_FILLED")]
462 fn py_partially_filled() -> Self {
463 Self::PartiallyFilled
464 }
465
466 #[classattr]
467 #[pyo3(name = "FILLED")]
468 fn py_filled() -> Self {
469 Self::Filled
470 }
471
472 #[classattr]
473 #[pyo3(name = "MMP_CANCELED")]
474 fn py_mmp_canceled() -> Self {
475 Self::MmpCanceled
476 }
477
478 #[classattr]
479 #[pyo3(name = "ORDER_PLACED")]
480 fn py_order_placed() -> Self {
481 Self::OrderPlaced
482 }
483}
484
485#[pymethods]
486impl OKXVipLevel {
487 #[new]
488 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
489 let t = Self::type_object(py);
490 Self::py_from_str(&t, value)
491 }
492
493 fn __hash__(&self) -> isize {
494 *self as isize
495 }
496
497 fn __repr__(&self) -> String {
498 format!(
499 "<{}.{}: '{}'>",
500 stringify!(OKXVipLevel),
501 self.name(),
502 self.value(),
503 )
504 }
505
506 fn __str__(&self) -> String {
507 self.to_string()
508 }
509
510 #[getter]
511 #[must_use]
512 pub fn name(&self) -> &str {
513 self.as_ref()
514 }
515
516 #[getter]
517 #[must_use]
518 pub fn value(&self) -> u8 {
519 *self as u8
520 }
521
522 #[staticmethod]
523 #[must_use]
524 fn variants() -> Vec<String> {
525 Self::iter().map(|x| x.to_string()).collect()
526 }
527
528 #[classmethod]
529 #[pyo3(name = "from_str")]
530 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
531 let data_str: String = data.str()?.extract()?;
532 Self::from_str(&data_str).map_err(to_pyvalue_err)
533 }
534
535 #[classattr]
536 #[pyo3(name = "VIP0")]
537 fn py_vip0() -> Self {
538 Self::Vip0
539 }
540
541 #[classattr]
542 #[pyo3(name = "VIP1")]
543 fn py_vip1() -> Self {
544 Self::Vip1
545 }
546
547 #[classattr]
548 #[pyo3(name = "VIP2")]
549 fn py_vip2() -> Self {
550 Self::Vip2
551 }
552
553 #[classattr]
554 #[pyo3(name = "VIP3")]
555 fn py_vip3() -> Self {
556 Self::Vip3
557 }
558
559 #[classattr]
560 #[pyo3(name = "VIP4")]
561 fn py_vip4() -> Self {
562 Self::Vip4
563 }
564
565 #[classattr]
566 #[pyo3(name = "VIP5")]
567 fn py_vip5() -> Self {
568 Self::Vip5
569 }
570
571 #[classattr]
572 #[pyo3(name = "VIP6")]
573 fn py_vip6() -> Self {
574 Self::Vip6
575 }
576
577 #[classattr]
578 #[pyo3(name = "VIP7")]
579 fn py_vip7() -> Self {
580 Self::Vip7
581 }
582
583 #[classattr]
584 #[pyo3(name = "VIP8")]
585 fn py_vip8() -> Self {
586 Self::Vip8
587 }
588
589 #[classattr]
590 #[pyo3(name = "VIP9")]
591 fn py_vip9() -> Self {
592 Self::Vip9
593 }
594}