1use 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 OKXAlgoOrderStatus, OKXContractType, OKXEnvironment, OKXInstrumentType, OKXMarginMode,
26 OKXOrderStatus, OKXPositionMode, OKXRegion, OKXTradeMode, OKXVipLevel,
27};
28
29#[pymethods]
30#[pyo3_stub_gen::derive::gen_stub_pymethods]
31impl OKXInstrumentType {
32 #[new]
34 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
35 let t = Self::type_object(py);
36 Self::py_from_str(&t, value)
37 }
38
39 fn __hash__(&self) -> isize {
40 *self as isize
41 }
42
43 fn __repr__(&self) -> String {
44 format!(
45 "<{}.{}: '{}'>",
46 stringify!(OKXInstrumentType),
47 self.name(),
48 self.value(),
49 )
50 }
51
52 fn __str__(&self) -> String {
53 self.to_string()
54 }
55
56 #[getter]
57 #[must_use]
58 pub fn name(&self) -> &str {
59 self.as_ref()
60 }
61
62 #[getter]
63 #[must_use]
64 pub fn value(&self) -> u8 {
65 *self as u8
66 }
67
68 #[staticmethod]
69 #[must_use]
70 fn variants() -> Vec<String> {
71 Self::iter().map(|x| x.to_string()).collect()
72 }
73
74 #[classmethod]
75 #[pyo3(name = "from_str")]
76 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
77 let data_str: String = data.str()?.extract()?;
78 Self::from_str(&data_str).map_err(to_pyvalue_err)
79 }
80}
81
82#[pymethods]
83#[pyo3_stub_gen::derive::gen_stub_pymethods]
84impl OKXContractType {
85 #[new]
87 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
88 let t = Self::type_object(py);
89 Self::py_from_str(&t, value)
90 }
91
92 fn __hash__(&self) -> isize {
93 *self as isize
94 }
95
96 fn __repr__(&self) -> String {
97 format!(
98 "<{}.{}: '{}'>",
99 stringify!(OKXContractType),
100 self.name(),
101 self.value(),
102 )
103 }
104
105 fn __str__(&self) -> String {
106 self.to_string()
107 }
108
109 #[getter]
110 #[must_use]
111 pub fn name(&self) -> &str {
112 self.as_ref()
113 }
114
115 #[getter]
116 #[must_use]
117 pub fn value(&self) -> u8 {
118 *self as u8
119 }
120
121 #[classmethod]
122 #[pyo3(name = "from_str")]
123 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
124 let data_str: String = data.str()?.extract()?;
125 Self::from_str(&data_str).map_err(to_pyvalue_err)
126 }
127
128 #[staticmethod]
129 #[must_use]
130 fn variants() -> Vec<String> {
131 Self::iter().map(|x| x.to_string()).collect()
132 }
133}
134
135#[pymethods]
136#[pyo3_stub_gen::derive::gen_stub_pymethods]
137impl OKXMarginMode {
138 #[new]
146 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
147 let t = Self::type_object(py);
148 Self::py_from_str(&t, value)
149 }
150
151 fn __hash__(&self) -> isize {
152 *self as isize
153 }
154
155 fn __repr__(&self) -> String {
156 format!(
157 "<{}.{}: '{}'>",
158 stringify!(OKXMarginMode),
159 self.name(),
160 self.value(),
161 )
162 }
163
164 fn __str__(&self) -> String {
165 self.to_string()
166 }
167
168 #[getter]
169 #[must_use]
170 pub fn name(&self) -> &str {
171 self.as_ref()
172 }
173
174 #[getter]
175 #[must_use]
176 pub fn value(&self) -> u8 {
177 *self as u8
178 }
179
180 #[staticmethod]
181 #[must_use]
182 fn variants() -> Vec<String> {
183 Self::iter().map(|x| x.to_string()).collect()
184 }
185
186 #[classmethod]
187 #[pyo3(name = "from_str")]
188 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
189 let data_str: String = data.str()?.extract()?;
190 Self::from_str(&data_str).map_err(to_pyvalue_err)
191 }
192}
193
194#[pymethods]
195#[pyo3_stub_gen::derive::gen_stub_pymethods]
196impl OKXTradeMode {
197 #[new]
199 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
200 let t = Self::type_object(py);
201 Self::py_from_str(&t, value)
202 }
203
204 fn __hash__(&self) -> isize {
205 *self as isize
206 }
207
208 fn __repr__(&self) -> String {
209 format!(
210 "<{}.{}: '{}'>",
211 stringify!(OKXTradeMode),
212 self.name(),
213 self.value(),
214 )
215 }
216
217 fn __str__(&self) -> String {
218 self.to_string()
219 }
220
221 #[getter]
222 #[must_use]
223 pub fn name(&self) -> &str {
224 self.as_ref()
225 }
226
227 #[getter]
228 #[must_use]
229 pub fn value(&self) -> u8 {
230 *self as u8
231 }
232
233 #[staticmethod]
234 #[must_use]
235 fn variants() -> Vec<String> {
236 Self::iter().map(|x| x.to_string()).collect()
237 }
238
239 #[classmethod]
240 #[pyo3(name = "from_str")]
241 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
242 let data_str: String = data.str()?.extract()?;
243 Self::from_str(&data_str).map_err(to_pyvalue_err)
244 }
245}
246
247#[pymethods]
248#[pyo3_stub_gen::derive::gen_stub_pymethods]
249impl OKXPositionMode {
250 #[new]
256 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
257 let t = Self::type_object(py);
258 Self::py_from_str(&t, value)
259 }
260
261 fn __hash__(&self) -> isize {
262 *self as isize
263 }
264
265 fn __repr__(&self) -> String {
266 format!(
267 "<{}.{}: '{}'>",
268 stringify!(OKXPositionMode),
269 self.name(),
270 self.value(),
271 )
272 }
273
274 fn __str__(&self) -> String {
275 self.to_string()
276 }
277
278 #[getter]
279 #[must_use]
280 pub fn name(&self) -> &str {
281 self.as_ref()
282 }
283
284 #[getter]
285 #[must_use]
286 pub fn value(&self) -> u8 {
287 *self as u8
288 }
289
290 #[staticmethod]
291 #[must_use]
292 fn variants() -> Vec<String> {
293 Self::iter().map(|x| x.to_string()).collect()
294 }
295
296 #[classmethod]
297 #[pyo3(name = "from_str")]
298 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
299 let data_str: String = data.str()?.extract()?;
300 Self::from_str(&data_str).map_err(to_pyvalue_err)
301 }
302}
303
304#[pymethods]
305#[pyo3_stub_gen::derive::gen_stub_pymethods]
306impl OKXOrderStatus {
307 #[new]
309 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
310 let t = Self::type_object(py);
311 Self::py_from_str(&t, value)
312 }
313
314 fn __hash__(&self) -> isize {
315 *self as isize
316 }
317
318 fn __repr__(&self) -> String {
319 format!(
320 "<{}.{}: '{}'>",
321 stringify!(OKXOrderStatus),
322 self.name(),
323 self.value(),
324 )
325 }
326
327 fn __str__(&self) -> String {
328 self.to_string()
329 }
330
331 #[getter]
332 #[must_use]
333 pub fn name(&self) -> &str {
334 self.as_ref()
335 }
336
337 #[getter]
338 #[must_use]
339 pub fn value(&self) -> u8 {
340 *self as u8
341 }
342
343 #[staticmethod]
344 #[must_use]
345 fn variants() -> Vec<String> {
346 Self::iter().map(|x| x.to_string()).collect()
347 }
348
349 #[classmethod]
350 #[pyo3(name = "from_str")]
351 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
352 let data_str: String = data.str()?.extract()?;
353 Self::from_str(&data_str).map_err(to_pyvalue_err)
354 }
355}
356
357#[pymethods]
358#[pyo3_stub_gen::derive::gen_stub_pymethods]
359impl OKXAlgoOrderStatus {
360 #[new]
362 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
363 let t = Self::type_object(py);
364 Self::py_from_str(&t, value)
365 }
366
367 fn __hash__(&self) -> isize {
368 *self as isize
369 }
370
371 fn __repr__(&self) -> String {
372 format!(
373 "<{}.{}: '{}'>",
374 stringify!(OKXAlgoOrderStatus),
375 self.name(),
376 self.value(),
377 )
378 }
379
380 fn __str__(&self) -> String {
381 self.to_string()
382 }
383
384 #[getter]
385 #[must_use]
386 pub fn name(&self) -> &str {
387 self.as_ref()
388 }
389
390 #[getter]
391 #[must_use]
392 pub fn value(&self) -> u8 {
393 *self as u8
394 }
395
396 #[staticmethod]
397 #[must_use]
398 fn variants() -> Vec<String> {
399 Self::iter().map(|x| x.to_string()).collect()
400 }
401
402 #[classmethod]
403 #[pyo3(name = "from_str")]
404 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
405 let data_str: String = data.str()?.extract()?;
406 Self::from_str(&data_str).map_err(to_pyvalue_err)
407 }
408}
409
410#[pymethods]
411#[pyo3_stub_gen::derive::gen_stub_pymethods]
412impl OKXVipLevel {
413 #[new]
427 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
428 let t = Self::type_object(py);
429 Self::py_from_str(&t, value)
430 }
431
432 fn __hash__(&self) -> isize {
433 *self as isize
434 }
435
436 fn __repr__(&self) -> String {
437 format!(
438 "<{}.{}: '{}'>",
439 stringify!(OKXVipLevel),
440 self.name(),
441 self.value(),
442 )
443 }
444
445 fn __str__(&self) -> String {
446 self.to_string()
447 }
448
449 #[getter]
450 #[must_use]
451 pub fn name(&self) -> &str {
452 self.as_ref()
453 }
454
455 #[getter]
456 #[must_use]
457 pub fn value(&self) -> u8 {
458 *self as u8
459 }
460
461 #[staticmethod]
462 #[must_use]
463 fn variants() -> Vec<String> {
464 Self::iter().map(|x| x.to_string()).collect()
465 }
466
467 #[classmethod]
468 #[pyo3(name = "from_str")]
469 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
470 let data_str: String = data.str()?.extract()?;
471 Self::from_str(&data_str).map_err(to_pyvalue_err)
472 }
473}
474
475#[pymethods]
476#[pyo3_stub_gen::derive::gen_stub_pymethods]
477impl OKXEnvironment {
478 #[new]
480 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
481 let t = Self::type_object(py);
482 Self::py_from_str(&t, value)
483 }
484
485 const fn __hash__(&self) -> isize {
486 *self as isize
487 }
488
489 fn __str__(&self) -> String {
490 self.to_string()
491 }
492
493 #[getter]
494 #[must_use]
495 pub fn name(&self) -> String {
496 self.to_string()
497 }
498
499 #[getter]
500 #[must_use]
501 pub fn value(&self) -> u8 {
502 *self as u8
503 }
504
505 #[classmethod]
506 #[must_use]
507 fn variants(_: &Bound<'_, PyType>) -> Vec<String> {
508 Self::iter().map(|x| x.to_string()).collect()
509 }
510
511 #[classmethod]
512 #[pyo3(name = "from_str")]
513 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
514 let data_str: String = data.str()?.extract()?;
515 Self::from_str(&data_str).map_err(to_pyvalue_err)
516 }
517}
518
519#[pymethods]
520#[pyo3_stub_gen::derive::gen_stub_pymethods]
521impl OKXRegion {
522 #[new]
528 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
529 let t = Self::type_object(py);
530 Self::py_from_str(&t, value)
531 }
532
533 const fn __hash__(&self) -> isize {
534 *self as isize
535 }
536
537 fn __str__(&self) -> String {
538 self.to_string()
539 }
540
541 #[getter]
542 #[must_use]
543 pub fn name(&self) -> String {
544 self.to_string()
545 }
546
547 #[getter]
548 #[must_use]
549 pub fn value(&self) -> u8 {
550 *self as u8
551 }
552
553 #[classmethod]
554 #[must_use]
555 fn variants(_: &Bound<'_, PyType>) -> Vec<String> {
556 Self::iter().map(|x| x.to_string()).collect()
557 }
558
559 #[classmethod]
560 #[pyo3(name = "from_str")]
561 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
562 let data_str: String = data.str()?.extract()?;
563 Self::from_str(&data_str).map_err(to_pyvalue_err)
564 }
565}