Skip to main content

nautilus_model/python/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Enumerations for the trading domain model.
17
18use std::str::FromStr;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyTypeInfo, prelude::*, types::PyType};
22
23use crate::{
24    enums::{
25        AccountType, AggregationSource, AggressorSide, AssetClass, BarAggregation, BarIntervalType,
26        BetSide, BookAction, BookType, ContingencyType, CurrencyType, InstrumentClass,
27        InstrumentCloseType, LiquiditySide, MarketStatus, MarketStatusAction, OmsType, OptionKind,
28        OrderSide, OrderStatus, OrderType, OtoTriggerMode, PositionAdjustmentType, PositionSide,
29        PriceType, RecordFlag, TimeInForce, TradingState, TrailingOffsetType, TriggerType,
30    },
31    python::common::EnumIterator,
32};
33
34#[pymethods]
35impl AccountType {
36    #[new]
37    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
38        let t = Self::type_object(py);
39        Self::py_from_str(&t, value)
40    }
41
42    const fn __hash__(&self) -> isize {
43        *self as isize
44    }
45
46    fn __str__(&self) -> String {
47        self.to_string()
48    }
49
50    #[getter]
51    #[must_use]
52    pub fn name(&self) -> String {
53        self.to_string()
54    }
55
56    #[getter]
57    #[must_use]
58    pub fn value(&self) -> u8 {
59        *self as u8
60    }
61
62    #[classmethod]
63    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
64        EnumIterator::new::<Self>(py)
65    }
66
67    #[classmethod]
68    #[pyo3(name = "from_str")]
69    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
70        let data_str: &str = data.extract()?;
71        let tokenized = data_str.to_uppercase();
72        Self::from_str(&tokenized).map_err(to_pyvalue_err)
73    }
74}
75
76#[pymethods]
77impl PositionAdjustmentType {
78    #[new]
79    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
80        let t = Self::type_object(py);
81        Self::py_from_str(&t, value)
82    }
83
84    const fn __hash__(&self) -> isize {
85        *self as isize
86    }
87
88    fn __str__(&self) -> String {
89        self.to_string()
90    }
91
92    #[getter]
93    #[must_use]
94    pub fn name(&self) -> String {
95        self.to_string()
96    }
97
98    #[getter]
99    #[must_use]
100    pub fn value(&self) -> u8 {
101        *self as u8
102    }
103
104    #[classmethod]
105    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
106        EnumIterator::new::<Self>(py)
107    }
108
109    #[classmethod]
110    #[pyo3(name = "from_str")]
111    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
112        let data_str: &str = data.extract()?;
113        let tokenized = data_str.to_uppercase();
114        Self::from_str(&tokenized).map_err(to_pyvalue_err)
115    }
116}
117
118#[pymethods]
119impl AggregationSource {
120    #[new]
121    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
122        let t = Self::type_object(py);
123        Self::py_from_str(&t, value)
124    }
125
126    const fn __hash__(&self) -> isize {
127        *self as isize
128    }
129
130    fn __str__(&self) -> String {
131        self.to_string()
132    }
133
134    #[getter]
135    #[must_use]
136    pub fn name(&self) -> String {
137        self.to_string()
138    }
139
140    #[getter]
141    #[must_use]
142    pub fn value(&self) -> u8 {
143        *self as u8
144    }
145
146    #[classmethod]
147    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
148        EnumIterator::new::<Self>(py)
149    }
150
151    #[classmethod]
152    #[pyo3(name = "from_str")]
153    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
154        let data_str: &str = data.extract()?;
155        let tokenized = data_str.to_uppercase();
156        Self::from_str(&tokenized).map_err(to_pyvalue_err)
157    }
158}
159
160#[pymethods]
161impl AggressorSide {
162    #[new]
163    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
164        let t = Self::type_object(py);
165        Self::py_from_str(&t, value)
166    }
167
168    const fn __hash__(&self) -> isize {
169        *self as isize
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 fn value(&self) -> u8 {
185        *self as u8
186    }
187
188    #[classmethod]
189    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
190        EnumIterator::new::<Self>(py)
191    }
192
193    #[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}
201
202#[pymethods]
203impl AssetClass {
204    #[new]
205    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
206        let t = Self::type_object(py);
207        Self::py_from_str(&t, value)
208    }
209
210    const fn __hash__(&self) -> isize {
211        *self as isize
212    }
213
214    fn __str__(&self) -> String {
215        self.to_string()
216    }
217
218    #[getter]
219    #[must_use]
220    pub fn name(&self) -> String {
221        self.to_string()
222    }
223
224    #[getter]
225    #[must_use]
226    pub fn value(&self) -> u8 {
227        *self as u8
228    }
229
230    #[classmethod]
231    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
232        EnumIterator::new::<Self>(py)
233    }
234
235    #[classmethod]
236    #[pyo3(name = "from_str")]
237    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
238        let data_str: &str = data.extract()?;
239        let tokenized = data_str.to_uppercase();
240        Self::from_str(&tokenized).map_err(to_pyvalue_err)
241    }
242}
243
244#[pymethods]
245impl InstrumentClass {
246    #[new]
247    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
248        let t = Self::type_object(py);
249        Self::py_from_str(&t, value)
250    }
251
252    const fn __hash__(&self) -> isize {
253        *self as isize
254    }
255
256    fn __str__(&self) -> String {
257        self.to_string()
258    }
259
260    #[getter]
261    #[must_use]
262    pub fn name(&self) -> String {
263        self.to_string()
264    }
265
266    #[getter]
267    #[must_use]
268    pub fn value(&self) -> u8 {
269        *self as u8
270    }
271
272    #[classmethod]
273    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
274        EnumIterator::new::<Self>(py)
275    }
276
277    #[classmethod]
278    #[pyo3(name = "from_str")]
279    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
280        let data_str: &str = data.extract()?;
281        let tokenized = data_str.to_uppercase();
282        Self::from_str(&tokenized).map_err(to_pyvalue_err)
283    }
284}
285
286#[pymethods]
287impl BarAggregation {
288    #[new]
289    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
290        let t = Self::type_object(py);
291        Self::py_from_str(&t, value)
292    }
293
294    const fn __hash__(&self) -> isize {
295        *self as isize
296    }
297
298    fn __str__(&self) -> String {
299        self.to_string()
300    }
301
302    #[getter]
303    #[must_use]
304    pub fn name(&self) -> String {
305        self.to_string()
306    }
307
308    #[getter]
309    #[must_use]
310    pub fn value(&self) -> u8 {
311        *self as u8
312    }
313
314    #[classmethod]
315    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
316        EnumIterator::new::<Self>(py)
317    }
318
319    #[classmethod]
320    #[pyo3(name = "from_str")]
321    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
322        let data_str: &str = data.extract()?;
323        let tokenized = data_str.to_uppercase();
324        Self::from_str(&tokenized).map_err(to_pyvalue_err)
325    }
326}
327
328#[pymethods]
329impl BarIntervalType {
330    const fn __hash__(&self) -> isize {
331        *self as isize
332    }
333}
334
335#[pymethods]
336impl BetSide {
337    #[new]
338    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
339        let t = Self::type_object(py);
340        Self::py_from_str(&t, value)
341    }
342
343    const fn __hash__(&self) -> isize {
344        *self as isize
345    }
346
347    fn __str__(&self) -> String {
348        self.to_string()
349    }
350
351    #[getter]
352    #[must_use]
353    pub fn name(&self) -> String {
354        self.to_string()
355    }
356
357    #[getter]
358    #[must_use]
359    pub fn value(&self) -> u8 {
360        *self as u8
361    }
362
363    #[classmethod]
364    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
365        EnumIterator::new::<Self>(py)
366    }
367
368    #[classmethod]
369    #[pyo3(name = "from_str")]
370    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
371        let data_str: &str = data.extract()?;
372        let tokenized = data_str.to_uppercase();
373        Self::from_str(&tokenized).map_err(to_pyvalue_err)
374    }
375
376    #[classmethod]
377    #[pyo3(name = "from_order_side")]
378    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
379        order_side.into()
380    }
381
382    #[pyo3(name = "opposite")]
383    fn py_opposite(&self) -> Self {
384        self.opposite()
385    }
386}
387
388#[pymethods]
389impl BookAction {
390    #[new]
391    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
392        let t = Self::type_object(py);
393        Self::py_from_str(&t, value)
394    }
395
396    const fn __hash__(&self) -> isize {
397        *self as isize
398    }
399
400    fn __str__(&self) -> String {
401        self.to_string()
402    }
403
404    #[getter]
405    #[must_use]
406    pub fn name(&self) -> String {
407        self.to_string()
408    }
409
410    #[getter]
411    #[must_use]
412    pub fn value(&self) -> u8 {
413        *self as u8
414    }
415
416    #[classmethod]
417    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
418        EnumIterator::new::<Self>(py)
419    }
420
421    #[classmethod]
422    #[pyo3(name = "from_str")]
423    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
424        let data_str: &str = data.extract()?;
425        let tokenized = data_str.to_uppercase();
426        Self::from_str(&tokenized).map_err(to_pyvalue_err)
427    }
428}
429
430#[pymethods]
431impl ContingencyType {
432    #[new]
433    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
434        let t = Self::type_object(py);
435        Self::py_from_str(&t, value)
436    }
437
438    const fn __hash__(&self) -> isize {
439        *self as isize
440    }
441
442    fn __str__(&self) -> String {
443        self.to_string()
444    }
445
446    #[getter]
447    #[must_use]
448    pub fn name(&self) -> String {
449        self.to_string()
450    }
451
452    #[getter]
453    #[must_use]
454    pub fn value(&self) -> u8 {
455        *self as u8
456    }
457
458    #[classmethod]
459    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
460        EnumIterator::new::<Self>(py)
461    }
462
463    #[classmethod]
464    #[pyo3(name = "from_str")]
465    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
466        let data_str: &str = data.extract()?;
467        let tokenized = data_str.to_uppercase();
468        Self::from_str(&tokenized).map_err(to_pyvalue_err)
469    }
470}
471
472#[pymethods]
473impl CurrencyType {
474    #[new]
475    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
476        let t = Self::type_object(py);
477        Self::py_from_str(&t, value)
478    }
479
480    const fn __hash__(&self) -> isize {
481        *self as isize
482    }
483
484    fn __str__(&self) -> String {
485        self.to_string()
486    }
487
488    #[getter]
489    #[must_use]
490    pub fn name(&self) -> String {
491        self.to_string()
492    }
493
494    #[getter]
495    #[must_use]
496    pub fn value(&self) -> u8 {
497        *self as u8
498    }
499
500    #[classmethod]
501    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
502        EnumIterator::new::<Self>(py)
503    }
504
505    #[classmethod]
506    #[pyo3(name = "from_str")]
507    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
508        let data_str: &str = data.extract()?;
509        let tokenized = data_str.to_uppercase();
510        Self::from_str(&tokenized).map_err(to_pyvalue_err)
511    }
512}
513
514#[pymethods]
515impl InstrumentCloseType {
516    #[new]
517    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
518        let t = Self::type_object(py);
519        Self::py_from_str(&t, value)
520    }
521
522    const fn __hash__(&self) -> isize {
523        *self as isize
524    }
525
526    fn __str__(&self) -> String {
527        self.to_string()
528    }
529
530    #[getter]
531    #[must_use]
532    pub fn name(&self) -> String {
533        self.to_string()
534    }
535
536    #[getter]
537    #[must_use]
538    pub fn value(&self) -> u8 {
539        *self as u8
540    }
541
542    #[classmethod]
543    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
544        EnumIterator::new::<Self>(py)
545    }
546
547    #[classmethod]
548    #[pyo3(name = "from_str")]
549    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
550        let data_str: &str = data.extract()?;
551        let tokenized = data_str.to_uppercase();
552        Self::from_str(&tokenized).map_err(to_pyvalue_err)
553    }
554}
555
556#[pymethods]
557impl LiquiditySide {
558    #[new]
559    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
560        let t = Self::type_object(py);
561        Self::py_from_str(&t, value)
562    }
563
564    const fn __hash__(&self) -> isize {
565        *self as isize
566    }
567
568    fn __str__(&self) -> String {
569        self.to_string()
570    }
571
572    #[getter]
573    #[must_use]
574    pub fn name(&self) -> String {
575        self.to_string()
576    }
577
578    #[getter]
579    #[must_use]
580    pub fn value(&self) -> u8 {
581        *self as u8
582    }
583
584    #[classmethod]
585    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
586        EnumIterator::new::<Self>(py)
587    }
588
589    #[classmethod]
590    #[pyo3(name = "from_str")]
591    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
592        let data_str: &str = data.extract()?;
593        let tokenized = data_str.to_uppercase();
594        Self::from_str(&tokenized).map_err(to_pyvalue_err)
595    }
596}
597
598#[pymethods]
599impl MarketStatus {
600    #[new]
601    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
602        let t = Self::type_object(py);
603        Self::py_from_str(&t, value)
604    }
605
606    const fn __hash__(&self) -> isize {
607        *self as isize
608    }
609
610    fn __str__(&self) -> String {
611        self.to_string()
612    }
613
614    #[getter]
615    #[must_use]
616    pub fn name(&self) -> String {
617        self.to_string()
618    }
619
620    #[getter]
621    #[must_use]
622    pub fn value(&self) -> u8 {
623        *self as u8
624    }
625
626    #[classmethod]
627    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
628        EnumIterator::new::<Self>(py)
629    }
630
631    #[classmethod]
632    #[pyo3(name = "from_str")]
633    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
634        let data_str: &str = data.extract()?;
635        let tokenized = data_str.to_uppercase();
636        Self::from_str(&tokenized).map_err(to_pyvalue_err)
637    }
638}
639
640#[pymethods]
641impl MarketStatusAction {
642    #[new]
643    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
644        let t = Self::type_object(py);
645        Self::py_from_str(&t, value)
646    }
647
648    const fn __hash__(&self) -> isize {
649        *self as isize
650    }
651
652    fn __str__(&self) -> String {
653        self.to_string()
654    }
655
656    #[getter]
657    #[must_use]
658    pub fn name(&self) -> String {
659        self.to_string()
660    }
661
662    #[getter]
663    #[must_use]
664    pub fn value(&self) -> u8 {
665        *self as u8
666    }
667
668    #[classmethod]
669    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
670        EnumIterator::new::<Self>(py)
671    }
672
673    #[classmethod]
674    #[pyo3(name = "from_str")]
675    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
676        let data_str: &str = data.extract()?;
677        let tokenized = data_str.to_uppercase();
678        Self::from_str(&tokenized).map_err(to_pyvalue_err)
679    }
680}
681
682#[pymethods]
683impl OmsType {
684    #[new]
685    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
686        let t = Self::type_object(py);
687        Self::py_from_str(&t, value)
688    }
689
690    const fn __hash__(&self) -> isize {
691        *self as isize
692    }
693
694    fn __str__(&self) -> String {
695        self.to_string()
696    }
697
698    #[getter]
699    #[must_use]
700    pub fn name(&self) -> String {
701        self.to_string()
702    }
703
704    #[getter]
705    #[must_use]
706    pub fn value(&self) -> u8 {
707        *self as u8
708    }
709
710    #[classmethod]
711    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
712        EnumIterator::new::<Self>(py)
713    }
714
715    #[classmethod]
716    #[pyo3(name = "from_str")]
717    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
718        let data_str: &str = data.extract()?;
719        let tokenized = data_str.to_uppercase();
720        Self::from_str(&tokenized).map_err(to_pyvalue_err)
721    }
722}
723
724#[pymethods]
725impl OptionKind {
726    #[new]
727    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
728        let t = Self::type_object(py);
729        Self::py_from_str(&t, value)
730    }
731
732    const fn __hash__(&self) -> isize {
733        *self as isize
734    }
735
736    fn __str__(&self) -> String {
737        self.to_string()
738    }
739
740    #[getter]
741    #[must_use]
742    pub fn name(&self) -> String {
743        self.to_string()
744    }
745
746    #[getter]
747    #[must_use]
748    pub fn value(&self) -> u8 {
749        *self as u8
750    }
751
752    #[classmethod]
753    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
754        EnumIterator::new::<Self>(py)
755    }
756
757    #[classmethod]
758    #[pyo3(name = "from_str")]
759    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
760        let data_str: &str = data.extract()?;
761        let tokenized = data_str.to_uppercase();
762        Self::from_str(&tokenized).map_err(to_pyvalue_err)
763    }
764}
765
766#[pymethods]
767impl OtoTriggerMode {
768    #[new]
769    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
770        let t = Self::type_object(py);
771        Self::py_from_str(&t, value)
772    }
773
774    const fn __hash__(&self) -> isize {
775        *self as isize
776    }
777
778    fn __str__(&self) -> String {
779        self.to_string()
780    }
781
782    #[getter]
783    #[must_use]
784    pub fn name(&self) -> String {
785        self.to_string()
786    }
787
788    #[getter]
789    #[must_use]
790    pub fn value(&self) -> u8 {
791        *self as u8
792    }
793
794    #[classmethod]
795    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
796        EnumIterator::new::<Self>(py)
797    }
798
799    #[classmethod]
800    #[pyo3(name = "from_str")]
801    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
802        let data_str: &str = data.extract()?;
803        let tokenized = data_str.to_uppercase();
804        Self::from_str(&tokenized).map_err(to_pyvalue_err)
805    }
806}
807
808#[pymethods]
809impl OrderSide {
810    #[new]
811    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
812        let t = Self::type_object(py);
813        Self::py_from_str(&t, value)
814    }
815
816    const fn __hash__(&self) -> isize {
817        *self as isize
818    }
819
820    fn __str__(&self) -> String {
821        self.to_string()
822    }
823
824    #[getter]
825    #[must_use]
826    pub fn name(&self) -> String {
827        self.to_string()
828    }
829
830    #[getter]
831    #[must_use]
832    pub fn value(&self) -> u8 {
833        *self as u8
834    }
835
836    #[classmethod]
837    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
838        EnumIterator::new::<Self>(py)
839    }
840
841    #[classmethod]
842    #[pyo3(name = "from_str")]
843    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
844        let data_str: &str = data.extract()?;
845        let tokenized = data_str.to_uppercase();
846        Self::from_str(&tokenized).map_err(to_pyvalue_err)
847    }
848}
849
850#[pymethods]
851impl OrderStatus {
852    #[new]
853    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
854        let t = Self::type_object(py);
855        Self::py_from_str(&t, value)
856    }
857
858    const fn __hash__(&self) -> isize {
859        *self as isize
860    }
861
862    fn __str__(&self) -> String {
863        self.to_string()
864    }
865
866    #[getter]
867    #[must_use]
868    pub fn name(&self) -> String {
869        self.to_string()
870    }
871
872    #[getter]
873    #[must_use]
874    pub fn value(&self) -> u8 {
875        *self as u8
876    }
877
878    #[classmethod]
879    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
880        EnumIterator::new::<Self>(py)
881    }
882
883    #[classmethod]
884    #[pyo3(name = "from_str")]
885    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
886        let data_str: &str = data.extract()?;
887        let tokenized = data_str.to_uppercase();
888        Self::from_str(&tokenized).map_err(to_pyvalue_err)
889    }
890}
891
892#[pymethods]
893impl OrderType {
894    #[new]
895    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
896        let t = Self::type_object(py);
897        Self::py_from_str(&t, value)
898    }
899
900    const fn __hash__(&self) -> isize {
901        *self as isize
902    }
903
904    fn __str__(&self) -> String {
905        self.to_string()
906    }
907
908    #[getter]
909    #[must_use]
910    pub fn name(&self) -> String {
911        self.to_string()
912    }
913
914    #[getter]
915    #[must_use]
916    pub fn value(&self) -> u8 {
917        *self as u8
918    }
919
920    #[classmethod]
921    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
922        EnumIterator::new::<Self>(py)
923    }
924
925    #[classmethod]
926    #[pyo3(name = "from_str")]
927    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
928        let data_str: &str = data.extract()?;
929        let tokenized = data_str.to_uppercase();
930        Self::from_str(&tokenized).map_err(to_pyvalue_err)
931    }
932}
933
934#[pymethods]
935impl PositionSide {
936    #[new]
937    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
938        let t = Self::type_object(py);
939        Self::py_from_str(&t, value)
940    }
941
942    const fn __hash__(&self) -> isize {
943        *self as isize
944    }
945
946    fn __str__(&self) -> String {
947        self.to_string()
948    }
949
950    #[getter]
951    #[must_use]
952    pub fn name(&self) -> String {
953        self.to_string()
954    }
955
956    #[getter]
957    #[must_use]
958    pub fn value(&self) -> u8 {
959        *self as u8
960    }
961
962    #[classmethod]
963    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
964        EnumIterator::new::<Self>(py)
965    }
966
967    #[classmethod]
968    #[pyo3(name = "from_str")]
969    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
970        let data_str: &str = data.extract()?;
971        let tokenized = data_str.to_uppercase();
972        Self::from_str(&tokenized).map_err(to_pyvalue_err)
973    }
974}
975
976#[pymethods]
977impl PriceType {
978    #[new]
979    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
980        let t = Self::type_object(py);
981        Self::py_from_str(&t, value)
982    }
983
984    const fn __hash__(&self) -> isize {
985        *self as isize
986    }
987
988    fn __str__(&self) -> String {
989        self.to_string()
990    }
991
992    #[getter]
993    #[must_use]
994    pub fn name(&self) -> String {
995        self.to_string()
996    }
997
998    #[getter]
999    #[must_use]
1000    pub fn value(&self) -> u8 {
1001        *self as u8
1002    }
1003
1004    #[classmethod]
1005    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1006        EnumIterator::new::<Self>(py)
1007    }
1008
1009    #[classmethod]
1010    #[pyo3(name = "from_str")]
1011    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1012        let data_str: &str = data.extract()?;
1013        let tokenized = data_str.to_uppercase();
1014        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1015    }
1016
1017    #[classmethod]
1018    #[pyo3(name = "from_int")]
1019    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1020        Self::from_repr(value as usize)
1021            .ok_or_else(|| to_pyvalue_err(format!("Invalid PriceType value: {value}")))
1022    }
1023}
1024
1025#[pymethods]
1026impl RecordFlag {
1027    #[new]
1028    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1029        let t = Self::type_object(py);
1030        Self::py_from_str(&t, value)
1031    }
1032
1033    const fn __hash__(&self) -> isize {
1034        *self as isize
1035    }
1036
1037    fn __str__(&self) -> String {
1038        self.to_string()
1039    }
1040
1041    #[getter]
1042    #[must_use]
1043    pub fn name(&self) -> String {
1044        self.to_string()
1045    }
1046
1047    #[getter]
1048    #[must_use]
1049    pub fn value(&self) -> u8 {
1050        *self as u8
1051    }
1052
1053    #[classmethod]
1054    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1055        EnumIterator::new::<Self>(py)
1056    }
1057
1058    #[classmethod]
1059    #[pyo3(name = "from_str")]
1060    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1061        let data_str: &str = data.extract()?;
1062        let tokenized = data_str.to_uppercase();
1063        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1064    }
1065
1066    #[pyo3(name = "matches")]
1067    fn py_matches(&self, value: u8) -> bool {
1068        self.matches(value)
1069    }
1070}
1071
1072#[pymethods]
1073impl TimeInForce {
1074    #[new]
1075    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1076        let t = Self::type_object(py);
1077        Self::py_from_str(&t, value)
1078    }
1079
1080    const fn __hash__(&self) -> isize {
1081        *self as isize
1082    }
1083
1084    fn __str__(&self) -> String {
1085        self.to_string()
1086    }
1087
1088    #[getter]
1089    #[must_use]
1090    pub fn name(&self) -> String {
1091        self.to_string()
1092    }
1093
1094    #[getter]
1095    #[must_use]
1096    pub fn value(&self) -> u8 {
1097        *self as u8
1098    }
1099
1100    #[classmethod]
1101    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1102        EnumIterator::new::<Self>(py)
1103    }
1104
1105    #[classmethod]
1106    #[pyo3(name = "from_str")]
1107    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1108        let data_str: &str = data.extract()?;
1109        let tokenized = data_str.to_uppercase();
1110        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1111    }
1112}
1113
1114#[pymethods]
1115impl TrailingOffsetType {
1116    #[new]
1117    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1118        let t = Self::type_object(py);
1119        Self::py_from_str(&t, value)
1120    }
1121
1122    const fn __hash__(&self) -> isize {
1123        *self as isize
1124    }
1125
1126    fn __str__(&self) -> String {
1127        self.to_string()
1128    }
1129
1130    #[getter]
1131    #[must_use]
1132    pub fn name(&self) -> String {
1133        self.to_string()
1134    }
1135
1136    #[getter]
1137    #[must_use]
1138    pub fn value(&self) -> u8 {
1139        *self as u8
1140    }
1141
1142    #[classmethod]
1143    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1144        EnumIterator::new::<Self>(py)
1145    }
1146
1147    #[classmethod]
1148    #[pyo3(name = "from_str")]
1149    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1150        let data_str: &str = data.extract()?;
1151        let tokenized = data_str.to_uppercase();
1152        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1153    }
1154}
1155
1156#[pymethods]
1157impl TriggerType {
1158    #[new]
1159    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1160        let t = Self::type_object(py);
1161        Self::py_from_str(&t, value)
1162    }
1163
1164    const fn __hash__(&self) -> isize {
1165        *self as isize
1166    }
1167
1168    fn __str__(&self) -> String {
1169        self.to_string()
1170    }
1171
1172    #[getter]
1173    #[must_use]
1174    pub fn name(&self) -> String {
1175        self.to_string()
1176    }
1177
1178    #[getter]
1179    #[must_use]
1180    pub fn value(&self) -> u8 {
1181        *self as u8
1182    }
1183
1184    #[classmethod]
1185    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1186        EnumIterator::new::<Self>(py)
1187    }
1188
1189    #[classmethod]
1190    #[pyo3(name = "from_str")]
1191    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1192        let data_str: &str = data.extract()?;
1193        let tokenized = data_str.to_uppercase();
1194        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1195    }
1196}
1197
1198#[pymethods]
1199impl BookType {
1200    #[new]
1201    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1202        let t = Self::type_object(py);
1203        Self::py_from_str(&t, value)
1204    }
1205
1206    const fn __hash__(&self) -> isize {
1207        *self as isize
1208    }
1209
1210    fn __str__(&self) -> String {
1211        self.to_string()
1212    }
1213
1214    #[getter]
1215    #[must_use]
1216    pub fn name(&self) -> String {
1217        self.to_string()
1218    }
1219
1220    #[getter]
1221    #[must_use]
1222    pub fn value(&self) -> u8 {
1223        *self as u8
1224    }
1225
1226    #[classmethod]
1227    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1228        EnumIterator::new::<Self>(py)
1229    }
1230
1231    #[classmethod]
1232    #[pyo3(name = "from_str")]
1233    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1234        let data_str: &str = data.extract()?;
1235        let tokenized = data_str.to_uppercase();
1236        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1237    }
1238}
1239
1240#[pymethods]
1241impl TradingState {
1242    #[new]
1243    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1244        let t = Self::type_object(py);
1245        Self::py_from_str(&t, value)
1246    }
1247
1248    const fn __hash__(&self) -> isize {
1249        *self as isize
1250    }
1251
1252    fn __str__(&self) -> String {
1253        self.to_string()
1254    }
1255
1256    #[getter]
1257    #[must_use]
1258    pub fn name(&self) -> String {
1259        self.to_string()
1260    }
1261
1262    #[getter]
1263    #[must_use]
1264    pub fn value(&self) -> u8 {
1265        *self as u8
1266    }
1267
1268    #[classmethod]
1269    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1270        EnumIterator::new::<Self>(py)
1271    }
1272
1273    #[classmethod]
1274    #[pyo3(name = "from_str")]
1275    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1276        let data_str: &str = data.extract()?;
1277        let tokenized = data_str.to_uppercase();
1278        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1279    }
1280}