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]
424 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
425 let t = Self::type_object(py);
426 Self::py_from_str(&t, value)
427 }
428
429 fn __hash__(&self) -> isize {
430 *self as isize
431 }
432
433 fn __repr__(&self) -> String {
434 format!(
435 "<{}.{}: '{}'>",
436 stringify!(OKXVipLevel),
437 self.name(),
438 self.value(),
439 )
440 }
441
442 fn __str__(&self) -> String {
443 self.to_string()
444 }
445
446 #[getter]
447 #[must_use]
448 pub fn name(&self) -> &str {
449 self.as_ref()
450 }
451
452 #[getter]
453 #[must_use]
454 pub fn value(&self) -> u8 {
455 *self as u8
456 }
457
458 #[staticmethod]
459 #[must_use]
460 fn variants() -> Vec<String> {
461 Self::iter().map(|x| x.to_string()).collect()
462 }
463
464 #[classmethod]
465 #[pyo3(name = "from_str")]
466 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
467 let data_str: String = data.str()?.extract()?;
468 Self::from_str(&data_str).map_err(to_pyvalue_err)
469 }
470}
471
472#[pymethods]
473#[pyo3_stub_gen::derive::gen_stub_pymethods]
474impl OKXEnvironment {
475 #[new]
477 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
478 let t = Self::type_object(py);
479 Self::py_from_str(&t, value)
480 }
481
482 const fn __hash__(&self) -> isize {
483 *self as isize
484 }
485
486 fn __str__(&self) -> String {
487 self.to_string()
488 }
489
490 #[getter]
491 #[must_use]
492 pub fn name(&self) -> String {
493 self.to_string()
494 }
495
496 #[getter]
497 #[must_use]
498 pub fn value(&self) -> u8 {
499 *self as u8
500 }
501
502 #[classmethod]
503 #[must_use]
504 fn variants(_: &Bound<'_, PyType>) -> Vec<String> {
505 Self::iter().map(|x| x.to_string()).collect()
506 }
507
508 #[classmethod]
509 #[pyo3(name = "from_str")]
510 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
511 let data_str: String = data.str()?.extract()?;
512 Self::from_str(&data_str).map_err(to_pyvalue_err)
513 }
514}
515
516#[pymethods]
517#[pyo3_stub_gen::derive::gen_stub_pymethods]
518impl OKXRegion {
519 #[new]
525 fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
526 let t = Self::type_object(py);
527 Self::py_from_str(&t, value)
528 }
529
530 const fn __hash__(&self) -> isize {
531 *self as isize
532 }
533
534 fn __str__(&self) -> String {
535 self.to_string()
536 }
537
538 #[getter]
539 #[must_use]
540 pub fn name(&self) -> String {
541 self.to_string()
542 }
543
544 #[getter]
545 #[must_use]
546 pub fn value(&self) -> u8 {
547 *self as u8
548 }
549
550 #[classmethod]
551 #[must_use]
552 fn variants(_: &Bound<'_, PyType>) -> Vec<String> {
553 Self::iter().map(|x| x.to_string()).collect()
554 }
555
556 #[classmethod]
557 #[pyo3(name = "from_str")]
558 fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
559 let data_str: String = data.str()?.extract()?;
560 Self::from_str(&data_str).map_err(to_pyvalue_err)
561 }
562}