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, BetSide,
26        BookAction, BookType, ContingencyType, CurrencyType, InstrumentClass, InstrumentCloseType,
27        LiquiditySide, MarketStatus, MarketStatusAction, OmsType, OptionKind, OrderSide,
28        OrderStatus, OrderType, OtoTriggerMode, PositionAdjustmentType, PositionSide, PriceType,
29        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    fn __repr__(&self) -> String {
43        format!(
44            "<{}.{}: '{}'>",
45            stringify!(AccountType),
46            self.name(),
47            self.value(),
48        )
49    }
50
51    fn __str__(&self) -> String {
52        self.to_string()
53    }
54
55    #[getter]
56    #[must_use]
57    pub fn name(&self) -> String {
58        self.to_string()
59    }
60
61    #[getter]
62    #[must_use]
63    pub fn value(&self) -> u8 {
64        *self as u8
65    }
66
67    #[classmethod]
68    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
69        EnumIterator::new::<Self>(py)
70    }
71
72    #[classmethod]
73    #[pyo3(name = "from_str")]
74    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
75        let data_str: &str = data.extract()?;
76        let tokenized = data_str.to_uppercase();
77        Self::from_str(&tokenized).map_err(to_pyvalue_err)
78    }
79}
80
81#[pymethods]
82impl PositionAdjustmentType {
83    #[new]
84    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
85        let t = Self::type_object(py);
86        Self::py_from_str(&t, value)
87    }
88
89    fn __hash__(&self) -> isize {
90        *self as isize
91    }
92
93    fn __repr__(&self) -> String {
94        format!(
95            "<{}.{}: '{}'>",
96            stringify!(PositionAdjustmentType),
97            self.name(),
98            self.value(),
99        )
100    }
101
102    fn __str__(&self) -> String {
103        self.to_string()
104    }
105
106    #[getter]
107    #[must_use]
108    pub fn name(&self) -> String {
109        self.to_string()
110    }
111
112    #[getter]
113    #[must_use]
114    pub fn value(&self) -> u8 {
115        *self as u8
116    }
117
118    #[classmethod]
119    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
120        EnumIterator::new::<Self>(py)
121    }
122
123    #[classmethod]
124    #[pyo3(name = "from_str")]
125    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
126        let data_str: &str = data.extract()?;
127        let tokenized = data_str.to_uppercase();
128        Self::from_str(&tokenized).map_err(to_pyvalue_err)
129    }
130}
131
132#[pymethods]
133impl AggregationSource {
134    #[new]
135    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
136        let t = Self::type_object(py);
137        Self::py_from_str(&t, value)
138    }
139
140    fn __repr__(&self) -> String {
141        format!(
142            "<{}.{}: '{}'>",
143            stringify!(AggregationSource),
144            self.name(),
145            self.value(),
146        )
147    }
148
149    fn __str__(&self) -> String {
150        self.to_string()
151    }
152
153    #[getter]
154    #[must_use]
155    pub fn name(&self) -> String {
156        self.to_string()
157    }
158
159    #[getter]
160    #[must_use]
161    pub fn value(&self) -> u8 {
162        *self as u8
163    }
164
165    #[classmethod]
166    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
167        EnumIterator::new::<Self>(py)
168    }
169
170    #[classmethod]
171    #[pyo3(name = "from_str")]
172    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
173        let data_str: &str = data.extract()?;
174        let tokenized = data_str.to_uppercase();
175        Self::from_str(&tokenized).map_err(to_pyvalue_err)
176    }
177}
178
179#[pymethods]
180impl AggressorSide {
181    #[new]
182    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
183        let t = Self::type_object(py);
184        Self::py_from_str(&t, value)
185    }
186
187    fn __repr__(&self) -> String {
188        format!(
189            "<{}.{}: '{}'>",
190            stringify!(AggressorSide),
191            self.name(),
192            self.value(),
193        )
194    }
195
196    fn __str__(&self) -> String {
197        self.to_string()
198    }
199
200    #[getter]
201    #[must_use]
202    pub fn name(&self) -> String {
203        self.to_string()
204    }
205
206    #[getter]
207    #[must_use]
208    pub fn value(&self) -> u8 {
209        *self as u8
210    }
211
212    #[classmethod]
213    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
214        EnumIterator::new::<Self>(py)
215    }
216
217    #[classmethod]
218    #[pyo3(name = "from_str")]
219    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
220        let data_str: &str = data.extract()?;
221        let tokenized = data_str.to_uppercase();
222        Self::from_str(&tokenized).map_err(to_pyvalue_err)
223    }
224}
225
226#[pymethods]
227impl AssetClass {
228    #[new]
229    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
230        let t = Self::type_object(py);
231        Self::py_from_str(&t, value)
232    }
233
234    fn __repr__(&self) -> String {
235        format!(
236            "<{}.{}: '{}'>",
237            stringify!(AssetClass),
238            self.name(),
239            self.value(),
240        )
241    }
242
243    fn __str__(&self) -> String {
244        self.to_string()
245    }
246
247    #[getter]
248    #[must_use]
249    pub fn name(&self) -> String {
250        self.to_string()
251    }
252
253    #[getter]
254    #[must_use]
255    pub fn value(&self) -> u8 {
256        *self as u8
257    }
258
259    #[classmethod]
260    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
261        EnumIterator::new::<Self>(py)
262    }
263
264    #[classmethod]
265    #[pyo3(name = "from_str")]
266    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
267        let data_str: &str = data.extract()?;
268        let tokenized = data_str.to_uppercase();
269        Self::from_str(&tokenized).map_err(to_pyvalue_err)
270    }
271}
272
273#[pymethods]
274impl InstrumentClass {
275    #[new]
276    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
277        let t = Self::type_object(py);
278        Self::py_from_str(&t, value)
279    }
280
281    fn __repr__(&self) -> String {
282        format!(
283            "<{}.{}: '{}'>",
284            stringify!(InstrumentClass),
285            self.name(),
286            self.value(),
287        )
288    }
289
290    fn __str__(&self) -> String {
291        self.to_string()
292    }
293
294    #[getter]
295    #[must_use]
296    pub fn name(&self) -> String {
297        self.to_string()
298    }
299
300    #[getter]
301    #[must_use]
302    pub fn value(&self) -> u8 {
303        *self as u8
304    }
305
306    #[classmethod]
307    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
308        EnumIterator::new::<Self>(py)
309    }
310
311    #[classmethod]
312    #[pyo3(name = "from_str")]
313    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
314        let data_str: &str = data.extract()?;
315        let tokenized = data_str.to_uppercase();
316        Self::from_str(&tokenized).map_err(to_pyvalue_err)
317    }
318}
319
320#[pymethods]
321impl BarAggregation {
322    #[new]
323    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
324        let t = Self::type_object(py);
325        Self::py_from_str(&t, value)
326    }
327
328    fn __repr__(&self) -> String {
329        format!(
330            "<{}.{}: '{}'>",
331            stringify!(BarAggregation),
332            self.name(),
333            self.value(),
334        )
335    }
336
337    fn __str__(&self) -> String {
338        self.to_string()
339    }
340
341    #[getter]
342    #[must_use]
343    pub fn name(&self) -> String {
344        self.to_string()
345    }
346
347    #[getter]
348    #[must_use]
349    pub fn value(&self) -> u8 {
350        *self as u8
351    }
352
353    #[classmethod]
354    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
355        EnumIterator::new::<Self>(py)
356    }
357
358    #[classmethod]
359    #[pyo3(name = "from_str")]
360    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
361        let data_str: &str = data.extract()?;
362        let tokenized = data_str.to_uppercase();
363        Self::from_str(&tokenized).map_err(to_pyvalue_err)
364    }
365}
366
367#[pymethods]
368impl BetSide {
369    #[new]
370    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
371        let t = Self::type_object(py);
372        Self::py_from_str(&t, value)
373    }
374
375    fn __repr__(&self) -> String {
376        format!(
377            "<{}.{}: '{}'>",
378            stringify!(BetSide),
379            self.name(),
380            self.value(),
381        )
382    }
383
384    fn __str__(&self) -> String {
385        self.to_string()
386    }
387
388    #[getter]
389    #[must_use]
390    pub fn name(&self) -> String {
391        self.to_string()
392    }
393
394    #[getter]
395    #[must_use]
396    pub fn value(&self) -> u8 {
397        *self as u8
398    }
399
400    #[classmethod]
401    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
402        EnumIterator::new::<Self>(py)
403    }
404
405    #[classmethod]
406    #[pyo3(name = "from_str")]
407    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
408        let data_str: &str = data.extract()?;
409        let tokenized = data_str.to_uppercase();
410        Self::from_str(&tokenized).map_err(to_pyvalue_err)
411    }
412
413    #[classmethod]
414    #[pyo3(name = "from_order_side")]
415    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
416        order_side.into()
417    }
418
419    #[pyo3(name = "opposite")]
420    fn py_opposite(&self) -> Self {
421        self.opposite()
422    }
423}
424
425#[pymethods]
426impl BookAction {
427    #[new]
428    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
429        let t = Self::type_object(py);
430        Self::py_from_str(&t, value)
431    }
432
433    fn __repr__(&self) -> String {
434        format!(
435            "<{}.{}: '{}'>",
436            stringify!(BookAction),
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) -> 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 ContingencyType {
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    fn __repr__(&self) -> String {
481        format!(
482            "<{}.{}: '{}'>",
483            stringify!(ContingencyType),
484            self.name(),
485            self.value(),
486        )
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    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
507        EnumIterator::new::<Self>(py)
508    }
509
510    #[classmethod]
511    #[pyo3(name = "from_str")]
512    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
513        let data_str: &str = data.extract()?;
514        let tokenized = data_str.to_uppercase();
515        Self::from_str(&tokenized).map_err(to_pyvalue_err)
516    }
517}
518
519#[pymethods]
520impl CurrencyType {
521    #[new]
522    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
523        let t = Self::type_object(py);
524        Self::py_from_str(&t, value)
525    }
526
527    fn __repr__(&self) -> String {
528        format!(
529            "<{}.{}: '{}'>",
530            stringify!(CurrencyType),
531            self.name(),
532            self.value(),
533        )
534    }
535
536    fn __str__(&self) -> String {
537        self.to_string()
538    }
539
540    #[getter]
541    #[must_use]
542    pub fn name(&self) -> String {
543        self.to_string()
544    }
545
546    #[getter]
547    #[must_use]
548    pub fn value(&self) -> u8 {
549        *self as u8
550    }
551
552    #[classmethod]
553    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
554        EnumIterator::new::<Self>(py)
555    }
556
557    #[classmethod]
558    #[pyo3(name = "from_str")]
559    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
560        let data_str: &str = data.extract()?;
561        let tokenized = data_str.to_uppercase();
562        Self::from_str(&tokenized).map_err(to_pyvalue_err)
563    }
564}
565
566#[pymethods]
567impl InstrumentCloseType {
568    #[new]
569    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
570        let t = Self::type_object(py);
571        Self::py_from_str(&t, value)
572    }
573
574    fn __repr__(&self) -> String {
575        format!(
576            "<{}.{}: '{}'>",
577            stringify!(InstrumentCloseType),
578            self.name(),
579            self.value(),
580        )
581    }
582
583    fn __str__(&self) -> String {
584        self.to_string()
585    }
586
587    #[getter]
588    #[must_use]
589    pub fn name(&self) -> String {
590        self.to_string()
591    }
592
593    #[getter]
594    #[must_use]
595    pub fn value(&self) -> u8 {
596        *self as u8
597    }
598
599    #[classmethod]
600    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
601        EnumIterator::new::<Self>(py)
602    }
603
604    #[classmethod]
605    #[pyo3(name = "from_str")]
606    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
607        let data_str: &str = data.extract()?;
608        let tokenized = data_str.to_uppercase();
609        Self::from_str(&tokenized).map_err(to_pyvalue_err)
610    }
611}
612
613#[pymethods]
614impl LiquiditySide {
615    #[new]
616    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
617        let t = Self::type_object(py);
618        Self::py_from_str(&t, value)
619    }
620
621    fn __repr__(&self) -> String {
622        format!(
623            "<{}.{}: '{}'>",
624            stringify!(LiquiditySide),
625            self.name(),
626            self.value(),
627        )
628    }
629
630    fn __str__(&self) -> String {
631        self.to_string()
632    }
633
634    #[getter]
635    #[must_use]
636    pub fn name(&self) -> String {
637        self.to_string()
638    }
639
640    #[getter]
641    #[must_use]
642    pub fn value(&self) -> u8 {
643        *self as u8
644    }
645
646    #[classmethod]
647    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
648        EnumIterator::new::<Self>(py)
649    }
650
651    #[classmethod]
652    #[pyo3(name = "from_str")]
653    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
654        let data_str: &str = data.extract()?;
655        let tokenized = data_str.to_uppercase();
656        Self::from_str(&tokenized).map_err(to_pyvalue_err)
657    }
658}
659
660#[pymethods]
661impl MarketStatus {
662    #[new]
663    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
664        let t = Self::type_object(py);
665        Self::py_from_str(&t, value)
666    }
667
668    fn __repr__(&self) -> String {
669        format!(
670            "<{}.{}: '{}'>",
671            stringify!(MarketStatus),
672            self.name(),
673            self.value(),
674        )
675    }
676
677    fn __str__(&self) -> String {
678        self.to_string()
679    }
680
681    #[getter]
682    #[must_use]
683    pub fn name(&self) -> String {
684        self.to_string()
685    }
686
687    #[getter]
688    #[must_use]
689    pub fn value(&self) -> u8 {
690        *self as u8
691    }
692
693    #[classmethod]
694    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
695        EnumIterator::new::<Self>(py)
696    }
697
698    #[classmethod]
699    #[pyo3(name = "from_str")]
700    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
701        let data_str: &str = data.extract()?;
702        let tokenized = data_str.to_uppercase();
703        Self::from_str(&tokenized).map_err(to_pyvalue_err)
704    }
705}
706
707#[pymethods]
708impl MarketStatusAction {
709    #[new]
710    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
711        let t = Self::type_object(py);
712        Self::py_from_str(&t, value)
713    }
714
715    fn __repr__(&self) -> String {
716        format!(
717            "<{}.{}: '{}'>",
718            stringify!(MarketStatus),
719            self.name(),
720            self.value(),
721        )
722    }
723
724    fn __str__(&self) -> String {
725        self.to_string()
726    }
727
728    #[getter]
729    #[must_use]
730    pub fn name(&self) -> String {
731        self.to_string()
732    }
733
734    #[getter]
735    #[must_use]
736    pub fn value(&self) -> u8 {
737        *self as u8
738    }
739
740    #[classmethod]
741    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
742        EnumIterator::new::<Self>(py)
743    }
744
745    #[classmethod]
746    #[pyo3(name = "from_str")]
747    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
748        let data_str: &str = data.extract()?;
749        let tokenized = data_str.to_uppercase();
750        Self::from_str(&tokenized).map_err(to_pyvalue_err)
751    }
752}
753
754#[pymethods]
755impl OmsType {
756    #[new]
757    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
758        let t = Self::type_object(py);
759        Self::py_from_str(&t, value)
760    }
761
762    fn __repr__(&self) -> String {
763        format!(
764            "<{}.{}: '{}'>",
765            stringify!(OmsType),
766            self.name(),
767            self.value(),
768        )
769    }
770
771    fn __str__(&self) -> String {
772        self.to_string()
773    }
774
775    #[getter]
776    #[must_use]
777    pub fn name(&self) -> String {
778        self.to_string()
779    }
780
781    #[getter]
782    #[must_use]
783    pub fn value(&self) -> u8 {
784        *self as u8
785    }
786
787    #[classmethod]
788    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
789        EnumIterator::new::<Self>(py)
790    }
791
792    #[classmethod]
793    #[pyo3(name = "from_str")]
794    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
795        let data_str: &str = data.extract()?;
796        let tokenized = data_str.to_uppercase();
797        Self::from_str(&tokenized).map_err(to_pyvalue_err)
798    }
799}
800
801#[pymethods]
802impl OptionKind {
803    #[new]
804    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
805        let t = Self::type_object(py);
806        Self::py_from_str(&t, value)
807    }
808
809    fn __repr__(&self) -> String {
810        format!(
811            "<{}.{}: '{}'>",
812            stringify!(OptionKind),
813            self.name(),
814            self.value(),
815        )
816    }
817
818    fn __str__(&self) -> String {
819        self.to_string()
820    }
821
822    #[getter]
823    #[must_use]
824    pub fn name(&self) -> String {
825        self.to_string()
826    }
827
828    #[getter]
829    #[must_use]
830    pub fn value(&self) -> u8 {
831        *self as u8
832    }
833
834    #[classmethod]
835    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
836        EnumIterator::new::<Self>(py)
837    }
838
839    #[classmethod]
840    #[pyo3(name = "from_str")]
841    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
842        let data_str: &str = data.extract()?;
843        let tokenized = data_str.to_uppercase();
844        Self::from_str(&tokenized).map_err(to_pyvalue_err)
845    }
846}
847
848#[pymethods]
849impl OtoTriggerMode {
850    #[new]
851    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
852        let t = Self::type_object(py);
853        Self::py_from_str(&t, value)
854    }
855
856    fn __repr__(&self) -> String {
857        format!(
858            "<{}.{}: '{}'>",
859            stringify!(OtoTriggerMode),
860            self.name(),
861            self.value(),
862        )
863    }
864
865    fn __str__(&self) -> String {
866        self.to_string()
867    }
868
869    #[getter]
870    #[must_use]
871    pub fn name(&self) -> String {
872        self.to_string()
873    }
874
875    #[getter]
876    #[must_use]
877    pub fn value(&self) -> u8 {
878        *self as u8
879    }
880
881    #[classmethod]
882    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
883        EnumIterator::new::<Self>(py)
884    }
885
886    #[classmethod]
887    #[pyo3(name = "from_str")]
888    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
889        let data_str: &str = data.extract()?;
890        let tokenized = data_str.to_uppercase();
891        Self::from_str(&tokenized).map_err(to_pyvalue_err)
892    }
893}
894
895#[pymethods]
896impl OrderSide {
897    #[new]
898    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
899        let t = Self::type_object(py);
900        Self::py_from_str(&t, value)
901    }
902
903    fn __repr__(&self) -> String {
904        format!(
905            "<{}.{}: '{}'>",
906            stringify!(OrderSide),
907            self.name(),
908            self.value(),
909        )
910    }
911
912    fn __str__(&self) -> String {
913        self.to_string()
914    }
915
916    #[getter]
917    #[must_use]
918    pub fn name(&self) -> String {
919        self.to_string()
920    }
921
922    #[getter]
923    #[must_use]
924    pub fn value(&self) -> u8 {
925        *self as u8
926    }
927
928    #[classmethod]
929    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
930        EnumIterator::new::<Self>(py)
931    }
932
933    #[classmethod]
934    #[pyo3(name = "from_str")]
935    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
936        let data_str: &str = data.extract()?;
937        let tokenized = data_str.to_uppercase();
938        Self::from_str(&tokenized).map_err(to_pyvalue_err)
939    }
940}
941
942#[pymethods]
943impl OrderStatus {
944    #[new]
945    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
946        let t = Self::type_object(py);
947        Self::py_from_str(&t, value)
948    }
949
950    fn __repr__(&self) -> String {
951        format!(
952            "<{}.{}: '{}'>",
953            stringify!(OrderStatus),
954            self.name(),
955            self.value(),
956        )
957    }
958
959    fn __str__(&self) -> String {
960        self.to_string()
961    }
962
963    #[getter]
964    #[must_use]
965    pub fn name(&self) -> String {
966        self.to_string()
967    }
968
969    #[getter]
970    #[must_use]
971    pub fn value(&self) -> u8 {
972        *self as u8
973    }
974
975    #[classmethod]
976    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
977        EnumIterator::new::<Self>(py)
978    }
979
980    #[classmethod]
981    #[pyo3(name = "from_str")]
982    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
983        let data_str: &str = data.extract()?;
984        let tokenized = data_str.to_uppercase();
985        Self::from_str(&tokenized).map_err(to_pyvalue_err)
986    }
987}
988
989#[pymethods]
990impl OrderType {
991    #[new]
992    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
993        let t = Self::type_object(py);
994        Self::py_from_str(&t, value)
995    }
996
997    fn __repr__(&self) -> String {
998        format!(
999            "<{}.{}: '{}'>",
1000            stringify!(OrderType),
1001            self.name(),
1002            self.value(),
1003        )
1004    }
1005
1006    fn __str__(&self) -> String {
1007        self.to_string()
1008    }
1009
1010    #[getter]
1011    #[must_use]
1012    pub fn name(&self) -> String {
1013        self.to_string()
1014    }
1015
1016    #[getter]
1017    #[must_use]
1018    pub fn value(&self) -> u8 {
1019        *self as u8
1020    }
1021
1022    #[classmethod]
1023    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1024        EnumIterator::new::<Self>(py)
1025    }
1026
1027    #[classmethod]
1028    #[pyo3(name = "from_str")]
1029    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1030        let data_str: &str = data.extract()?;
1031        let tokenized = data_str.to_uppercase();
1032        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1033    }
1034}
1035
1036#[pymethods]
1037impl PositionSide {
1038    #[new]
1039    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1040        let t = Self::type_object(py);
1041        Self::py_from_str(&t, value)
1042    }
1043
1044    fn __repr__(&self) -> String {
1045        format!(
1046            "<{}.{}: '{}'>",
1047            stringify!(PositionSide),
1048            self.name(),
1049            self.value(),
1050        )
1051    }
1052
1053    fn __str__(&self) -> String {
1054        self.to_string()
1055    }
1056
1057    #[getter]
1058    #[must_use]
1059    pub fn name(&self) -> String {
1060        self.to_string()
1061    }
1062
1063    #[getter]
1064    #[must_use]
1065    pub fn value(&self) -> u8 {
1066        *self as u8
1067    }
1068
1069    #[classmethod]
1070    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1071        EnumIterator::new::<Self>(py)
1072    }
1073
1074    #[classmethod]
1075    #[pyo3(name = "from_str")]
1076    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1077        let data_str: &str = data.extract()?;
1078        let tokenized = data_str.to_uppercase();
1079        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1080    }
1081}
1082
1083#[pymethods]
1084impl PriceType {
1085    #[new]
1086    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1087        let t = Self::type_object(py);
1088        Self::py_from_str(&t, value)
1089    }
1090
1091    fn __repr__(&self) -> String {
1092        format!(
1093            "<{}.{}: '{}'>",
1094            stringify!(PositionSide),
1095            self.name(),
1096            self.value(),
1097        )
1098    }
1099
1100    fn __str__(&self) -> String {
1101        self.to_string()
1102    }
1103
1104    #[getter]
1105    #[must_use]
1106    pub fn name(&self) -> String {
1107        self.to_string()
1108    }
1109
1110    #[getter]
1111    #[must_use]
1112    pub fn value(&self) -> u8 {
1113        *self as u8
1114    }
1115
1116    #[classmethod]
1117    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1118        EnumIterator::new::<Self>(py)
1119    }
1120
1121    #[classmethod]
1122    #[pyo3(name = "from_str")]
1123    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1124        let data_str: &str = data.extract()?;
1125        let tokenized = data_str.to_uppercase();
1126        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1127    }
1128
1129    #[classmethod]
1130    #[pyo3(name = "from_int")]
1131    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1132        Self::from_repr(value as usize)
1133            .ok_or_else(|| to_pyvalue_err(format!("Invalid PriceType value: {value}")))
1134    }
1135}
1136
1137#[pymethods]
1138impl RecordFlag {
1139    #[new]
1140    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1141        let t = Self::type_object(py);
1142        Self::py_from_str(&t, value)
1143    }
1144
1145    fn __repr__(&self) -> String {
1146        format!(
1147            "<{}.{}: '{}'>",
1148            stringify!(RecordFlag),
1149            self.name(),
1150            self.value(),
1151        )
1152    }
1153
1154    fn __str__(&self) -> String {
1155        self.to_string()
1156    }
1157
1158    #[getter]
1159    #[must_use]
1160    pub fn name(&self) -> String {
1161        self.to_string()
1162    }
1163
1164    #[getter]
1165    #[must_use]
1166    pub fn value(&self) -> u8 {
1167        *self as u8
1168    }
1169
1170    #[classmethod]
1171    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1172        EnumIterator::new::<Self>(py)
1173    }
1174
1175    #[classmethod]
1176    #[pyo3(name = "from_str")]
1177    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1178        let data_str: &str = data.extract()?;
1179        let tokenized = data_str.to_uppercase();
1180        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1181    }
1182
1183    #[pyo3(name = "matches")]
1184    fn py_matches(&self, value: u8) -> bool {
1185        self.matches(value)
1186    }
1187}
1188
1189#[pymethods]
1190impl TimeInForce {
1191    #[new]
1192    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1193        let t = Self::type_object(py);
1194        Self::py_from_str(&t, value)
1195    }
1196
1197    fn __repr__(&self) -> String {
1198        format!(
1199            "<{}.{}: '{}'>",
1200            stringify!(TimeInForce),
1201            self.name(),
1202            self.value(),
1203        )
1204    }
1205
1206    fn __str__(&self) -> String {
1207        self.to_string()
1208    }
1209
1210    #[getter]
1211    #[must_use]
1212    pub fn name(&self) -> String {
1213        self.to_string()
1214    }
1215
1216    #[getter]
1217    #[must_use]
1218    pub fn value(&self) -> u8 {
1219        *self as u8
1220    }
1221
1222    #[classmethod]
1223    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1224        EnumIterator::new::<Self>(py)
1225    }
1226
1227    #[classmethod]
1228    #[pyo3(name = "from_str")]
1229    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1230        let data_str: &str = data.extract()?;
1231        let tokenized = data_str.to_uppercase();
1232        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1233    }
1234}
1235
1236#[pymethods]
1237impl TrailingOffsetType {
1238    #[new]
1239    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1240        let t = Self::type_object(py);
1241        Self::py_from_str(&t, value)
1242    }
1243
1244    fn __repr__(&self) -> String {
1245        format!(
1246            "<{}.{}: '{}'>",
1247            stringify!(TrailingOffsetType),
1248            self.name(),
1249            self.value(),
1250        )
1251    }
1252
1253    fn __str__(&self) -> String {
1254        self.to_string()
1255    }
1256
1257    #[getter]
1258    #[must_use]
1259    pub fn name(&self) -> String {
1260        self.to_string()
1261    }
1262
1263    #[getter]
1264    #[must_use]
1265    pub fn value(&self) -> u8 {
1266        *self as u8
1267    }
1268
1269    #[classmethod]
1270    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1271        EnumIterator::new::<Self>(py)
1272    }
1273
1274    #[classmethod]
1275    #[pyo3(name = "from_str")]
1276    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1277        let data_str: &str = data.extract()?;
1278        let tokenized = data_str.to_uppercase();
1279        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1280    }
1281}
1282
1283#[pymethods]
1284impl TriggerType {
1285    #[new]
1286    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1287        let t = Self::type_object(py);
1288        Self::py_from_str(&t, value)
1289    }
1290
1291    fn __repr__(&self) -> String {
1292        format!(
1293            "<{}.{}: '{}'>",
1294            stringify!(TriggerType),
1295            self.name(),
1296            self.value(),
1297        )
1298    }
1299
1300    fn __str__(&self) -> String {
1301        self.to_string()
1302    }
1303
1304    #[getter]
1305    #[must_use]
1306    pub fn name(&self) -> String {
1307        self.to_string()
1308    }
1309
1310    #[getter]
1311    #[must_use]
1312    pub fn value(&self) -> u8 {
1313        *self as u8
1314    }
1315
1316    #[classmethod]
1317    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1318        EnumIterator::new::<Self>(py)
1319    }
1320
1321    #[classmethod]
1322    #[pyo3(name = "from_str")]
1323    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1324        let data_str: &str = data.extract()?;
1325        let tokenized = data_str.to_uppercase();
1326        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1327    }
1328}
1329
1330#[pymethods]
1331impl BookType {
1332    #[new]
1333    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1334        let t = Self::type_object(py);
1335        Self::py_from_str(&t, value)
1336    }
1337
1338    fn __repr__(&self) -> String {
1339        format!(
1340            "<{}.{}: '{}'>",
1341            stringify!(BookType),
1342            self.name(),
1343            self.value(),
1344        )
1345    }
1346
1347    fn __str__(&self) -> String {
1348        self.to_string()
1349    }
1350
1351    #[getter]
1352    #[must_use]
1353    pub fn name(&self) -> String {
1354        self.to_string()
1355    }
1356
1357    #[getter]
1358    #[must_use]
1359    pub fn value(&self) -> u8 {
1360        *self as u8
1361    }
1362
1363    #[classmethod]
1364    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1365        EnumIterator::new::<Self>(py)
1366    }
1367
1368    #[classmethod]
1369    #[pyo3(name = "from_str")]
1370    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1371        let data_str: &str = data.extract()?;
1372        let tokenized = data_str.to_uppercase();
1373        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1374    }
1375}
1376
1377#[pymethods]
1378impl TradingState {
1379    #[new]
1380    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1381        let t = Self::type_object(py);
1382        Self::py_from_str(&t, value)
1383    }
1384
1385    fn __repr__(&self) -> String {
1386        format!(
1387            "<{}.{}: '{}'>",
1388            stringify!(TradingState),
1389            self.name(),
1390            self.value(),
1391        )
1392    }
1393
1394    fn __str__(&self) -> String {
1395        self.to_string()
1396    }
1397
1398    #[getter]
1399    #[must_use]
1400    pub fn name(&self) -> String {
1401        self.to_string()
1402    }
1403
1404    #[getter]
1405    #[must_use]
1406    pub fn value(&self) -> u8 {
1407        *self as u8
1408    }
1409
1410    #[classmethod]
1411    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1412        EnumIterator::new::<Self>(py)
1413    }
1414
1415    #[classmethod]
1416    #[pyo3(name = "from_str")]
1417    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1418        let data_str: &str = data.extract()?;
1419        let tokenized = data_str.to_uppercase();
1420        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1421    }
1422}