nautilus_model/python/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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, exceptions::PyValueError, 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, PositionAdjustmentType, PositionSide, PriceType, RecordFlag,
29        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    #[classattr]
81    #[pyo3(name = "CASH")]
82    fn py_cash() -> Self {
83        Self::Cash
84    }
85
86    #[classattr]
87    #[pyo3(name = "MARGIN")]
88    fn py_margin() -> Self {
89        Self::Margin
90    }
91
92    #[classattr]
93    #[pyo3(name = "BETTING")]
94    fn py_betting() -> Self {
95        Self::Betting
96    }
97}
98
99#[pymethods]
100impl PositionAdjustmentType {
101    #[new]
102    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
103        let t = Self::type_object(py);
104        Self::py_from_str(&t, value)
105    }
106
107    fn __hash__(&self) -> isize {
108        *self as isize
109    }
110
111    fn __repr__(&self) -> String {
112        format!(
113            "<{}.{}: '{}'>",
114            stringify!(PositionAdjustmentType),
115            self.name(),
116            self.value(),
117        )
118    }
119
120    fn __str__(&self) -> String {
121        self.to_string()
122    }
123
124    #[getter]
125    #[must_use]
126    pub fn name(&self) -> String {
127        self.to_string()
128    }
129
130    #[getter]
131    #[must_use]
132    pub fn value(&self) -> u8 {
133        *self as u8
134    }
135
136    #[classmethod]
137    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
138        EnumIterator::new::<Self>(py)
139    }
140
141    #[classmethod]
142    #[pyo3(name = "from_str")]
143    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
144        let data_str: &str = data.extract()?;
145        let tokenized = data_str.to_uppercase();
146        Self::from_str(&tokenized).map_err(to_pyvalue_err)
147    }
148
149    #[classattr]
150    #[pyo3(name = "COMMISSION")]
151    fn py_commission() -> Self {
152        Self::Commission
153    }
154
155    #[classattr]
156    #[pyo3(name = "FUNDING")]
157    fn py_funding() -> Self {
158        Self::Funding
159    }
160}
161
162#[pymethods]
163impl AggregationSource {
164    #[new]
165    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
166        let t = Self::type_object(py);
167        Self::py_from_str(&t, value)
168    }
169
170    fn __repr__(&self) -> String {
171        format!(
172            "<{}.{}: '{}'>",
173            stringify!(AggregationSource),
174            self.name(),
175            self.value(),
176        )
177    }
178
179    fn __str__(&self) -> String {
180        self.to_string()
181    }
182
183    #[getter]
184    #[must_use]
185    pub fn name(&self) -> String {
186        self.to_string()
187    }
188
189    #[getter]
190    #[must_use]
191    pub fn value(&self) -> u8 {
192        *self as u8
193    }
194
195    #[classmethod]
196    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
197        EnumIterator::new::<Self>(py)
198    }
199
200    #[classmethod]
201    #[pyo3(name = "from_str")]
202    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
203        let data_str: &str = data.extract()?;
204        let tokenized = data_str.to_uppercase();
205        Self::from_str(&tokenized).map_err(to_pyvalue_err)
206    }
207
208    #[classattr]
209    #[pyo3(name = "EXTERNAL")]
210    fn py_external() -> Self {
211        Self::External
212    }
213
214    #[classattr]
215    #[pyo3(name = "INTERNAL")]
216    fn py_internal() -> Self {
217        Self::Internal
218    }
219}
220
221#[pymethods]
222impl AggressorSide {
223    #[new]
224    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
225        let t = Self::type_object(py);
226        Self::py_from_str(&t, value)
227    }
228
229    fn __repr__(&self) -> String {
230        format!(
231            "<{}.{}: '{}'>",
232            stringify!(AggressorSide),
233            self.name(),
234            self.value(),
235        )
236    }
237
238    fn __str__(&self) -> String {
239        self.to_string()
240    }
241
242    #[getter]
243    #[must_use]
244    pub fn name(&self) -> String {
245        self.to_string()
246    }
247
248    #[getter]
249    #[must_use]
250    pub fn value(&self) -> u8 {
251        *self as u8
252    }
253
254    #[classmethod]
255    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
256        EnumIterator::new::<Self>(py)
257    }
258
259    #[classmethod]
260    #[pyo3(name = "from_str")]
261    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
262        let data_str: &str = data.extract()?;
263        let tokenized = data_str.to_uppercase();
264        Self::from_str(&tokenized).map_err(to_pyvalue_err)
265    }
266
267    #[classattr]
268    #[pyo3(name = "NO_AGGRESSOR")]
269    fn py_no_aggressor() -> Self {
270        Self::NoAggressor
271    }
272
273    #[classattr]
274    #[pyo3(name = "BUYER")]
275    fn py_buyer() -> Self {
276        Self::Buyer
277    }
278
279    #[classattr]
280    #[pyo3(name = "SELLER")]
281    fn py_seller() -> Self {
282        Self::Seller
283    }
284}
285
286#[pymethods]
287impl AssetClass {
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    fn __repr__(&self) -> String {
295        format!(
296            "<{}.{}: '{}'>",
297            stringify!(AssetClass),
298            self.name(),
299            self.value(),
300        )
301    }
302
303    fn __str__(&self) -> String {
304        self.to_string()
305    }
306
307    #[getter]
308    #[must_use]
309    pub fn name(&self) -> String {
310        self.to_string()
311    }
312
313    #[getter]
314    #[must_use]
315    pub fn value(&self) -> u8 {
316        *self as u8
317    }
318
319    #[classmethod]
320    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
321        EnumIterator::new::<Self>(py)
322    }
323
324    #[classmethod]
325    #[pyo3(name = "from_str")]
326    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
327        let data_str: &str = data.extract()?;
328        let tokenized = data_str.to_uppercase();
329        Self::from_str(&tokenized).map_err(to_pyvalue_err)
330    }
331
332    #[classattr]
333    #[pyo3(name = "FX")]
334    fn py_fx() -> Self {
335        Self::FX
336    }
337
338    #[classattr]
339    #[pyo3(name = "EQUITY")]
340    fn py_equity() -> Self {
341        Self::Equity
342    }
343
344    #[classattr]
345    #[pyo3(name = "COMMODITY")]
346    fn py_commodity() -> Self {
347        Self::Commodity
348    }
349
350    #[classattr]
351    #[pyo3(name = "DEBT")]
352    fn py_debt() -> Self {
353        Self::Debt
354    }
355
356    #[classattr]
357    #[pyo3(name = "INDEX")]
358    fn py_index() -> Self {
359        Self::Index
360    }
361
362    #[classattr]
363    #[pyo3(name = "CRYPTOCURRENCY")]
364    fn py_cryptocurrency() -> Self {
365        Self::Cryptocurrency
366    }
367
368    #[classattr]
369    #[pyo3(name = "ALTERNATIVE")]
370    fn py_alternative() -> Self {
371        Self::Alternative
372    }
373}
374
375#[pymethods]
376impl InstrumentClass {
377    #[new]
378    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
379        let t = Self::type_object(py);
380        Self::py_from_str(&t, value)
381    }
382
383    fn __repr__(&self) -> String {
384        format!(
385            "<{}.{}: '{}'>",
386            stringify!(InstrumentClass),
387            self.name(),
388            self.value(),
389        )
390    }
391
392    fn __str__(&self) -> String {
393        self.to_string()
394    }
395
396    #[getter]
397    #[must_use]
398    pub fn name(&self) -> String {
399        self.to_string()
400    }
401
402    #[getter]
403    #[must_use]
404    pub fn value(&self) -> u8 {
405        *self as u8
406    }
407
408    #[classmethod]
409    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
410        EnumIterator::new::<Self>(py)
411    }
412
413    #[classmethod]
414    #[pyo3(name = "from_str")]
415    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
416        let data_str: &str = data.extract()?;
417        let tokenized = data_str.to_uppercase();
418        Self::from_str(&tokenized).map_err(to_pyvalue_err)
419    }
420
421    #[classattr]
422    #[pyo3(name = "SPOT")]
423    fn py_spot() -> Self {
424        Self::Spot
425    }
426
427    #[classattr]
428    #[pyo3(name = "SWAP")]
429    fn py_swap() -> Self {
430        Self::Swap
431    }
432
433    #[classattr]
434    #[pyo3(name = "FUTURE")]
435    fn py_future() -> Self {
436        Self::Future
437    }
438
439    #[classattr]
440    #[pyo3(name = "FORWARD")]
441    fn py_forward() -> Self {
442        Self::Forward
443    }
444
445    #[classattr]
446    #[pyo3(name = "CFD")]
447    fn py_cfd() -> Self {
448        Self::Cfd
449    }
450
451    #[classattr]
452    #[pyo3(name = "BOND")]
453    fn py_bond() -> Self {
454        Self::Bond
455    }
456
457    #[classattr]
458    #[pyo3(name = "OPTION")]
459    fn py_option() -> Self {
460        Self::Option
461    }
462
463    #[classattr]
464    #[pyo3(name = "WARRANT")]
465    fn py_warrant() -> Self {
466        Self::Warrant
467    }
468
469    #[classattr]
470    #[pyo3(name = "SPORTS_BETTING")]
471    fn py_sports_betting() -> Self {
472        Self::SportsBetting
473    }
474}
475
476#[pymethods]
477impl BarAggregation {
478    #[new]
479    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
480        let t = Self::type_object(py);
481        Self::py_from_str(&t, value)
482    }
483
484    fn __repr__(&self) -> String {
485        format!(
486            "<{}.{}: '{}'>",
487            stringify!(BarAggregation),
488            self.name(),
489            self.value(),
490        )
491    }
492
493    fn __str__(&self) -> String {
494        self.to_string()
495    }
496
497    #[getter]
498    #[must_use]
499    pub fn name(&self) -> String {
500        self.to_string()
501    }
502
503    #[getter]
504    #[must_use]
505    pub fn value(&self) -> u8 {
506        *self as u8
507    }
508
509    #[classmethod]
510    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
511        EnumIterator::new::<Self>(py)
512    }
513
514    #[classmethod]
515    #[pyo3(name = "from_str")]
516    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
517        let data_str: &str = data.extract()?;
518        let tokenized = data_str.to_uppercase();
519        Self::from_str(&tokenized).map_err(to_pyvalue_err)
520    }
521    #[classattr]
522    #[pyo3(name = "TICK")]
523    fn py_tick() -> Self {
524        Self::Tick
525    }
526
527    #[classattr]
528    #[pyo3(name = "TICK_IMBALANCE")]
529    fn py_tick_imbalance() -> Self {
530        Self::TickImbalance
531    }
532
533    #[classattr]
534    #[pyo3(name = "TICK_RUNS")]
535    fn py_tick_runs() -> Self {
536        Self::TickRuns
537    }
538
539    #[classattr]
540    #[pyo3(name = "VOLUME")]
541    fn py_volume() -> Self {
542        Self::Volume
543    }
544
545    #[classattr]
546    #[pyo3(name = "VOLUME_IMBALANCE")]
547    fn py_volume_imbalance() -> Self {
548        Self::VolumeImbalance
549    }
550
551    #[classattr]
552    #[pyo3(name = "VOLUME_RUNS")]
553    fn py_volume_runs() -> Self {
554        Self::VolumeRuns
555    }
556
557    #[classattr]
558    #[pyo3(name = "VALUE")]
559    fn py_value() -> Self {
560        Self::Value
561    }
562
563    #[classattr]
564    #[pyo3(name = "VALUE_IMBALANCE")]
565    fn py_value_imbalance() -> Self {
566        Self::ValueImbalance
567    }
568
569    #[classattr]
570    #[pyo3(name = "VALUE_RUNS")]
571    fn py_value_runs() -> Self {
572        Self::ValueRuns
573    }
574
575    #[classattr]
576    #[pyo3(name = "MILLISECOND")]
577    fn py_millisecond() -> Self {
578        Self::Millisecond
579    }
580
581    #[classattr]
582    #[pyo3(name = "SECOND")]
583    fn py_second() -> Self {
584        Self::Second
585    }
586
587    #[classattr]
588    #[pyo3(name = "MINUTE")]
589    fn py_minute() -> Self {
590        Self::Minute
591    }
592
593    #[classattr]
594    #[pyo3(name = "HOUR")]
595    fn py_hour() -> Self {
596        Self::Hour
597    }
598
599    #[classattr]
600    #[pyo3(name = "DAY")]
601    fn py_day() -> Self {
602        Self::Day
603    }
604
605    #[classattr]
606    #[pyo3(name = "WEEK")]
607    fn py_week() -> Self {
608        Self::Week
609    }
610
611    #[classattr]
612    #[pyo3(name = "MONTH")]
613    fn py_month() -> Self {
614        Self::Month
615    }
616
617    #[classattr]
618    #[pyo3(name = "YEAR")]
619    fn py_year() -> Self {
620        Self::Year
621    }
622
623    #[classattr]
624    #[pyo3(name = "RENKO")]
625    fn py_renko() -> Self {
626        Self::Renko
627    }
628}
629
630#[pymethods]
631impl BetSide {
632    #[new]
633    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
634        let t = Self::type_object(py);
635        Self::py_from_str(&t, value)
636    }
637
638    fn __repr__(&self) -> String {
639        format!(
640            "<{}.{}: '{}'>",
641            stringify!(BetSide),
642            self.name(),
643            self.value(),
644        )
645    }
646
647    fn __str__(&self) -> String {
648        self.to_string()
649    }
650
651    #[getter]
652    #[must_use]
653    pub fn name(&self) -> String {
654        self.to_string()
655    }
656
657    #[getter]
658    #[must_use]
659    pub fn value(&self) -> u8 {
660        *self as u8
661    }
662
663    #[classmethod]
664    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
665        EnumIterator::new::<Self>(py)
666    }
667
668    #[classmethod]
669    #[pyo3(name = "from_str")]
670    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
671        let data_str: &str = data.extract()?;
672        let tokenized = data_str.to_uppercase();
673        Self::from_str(&tokenized).map_err(to_pyvalue_err)
674    }
675
676    #[classmethod]
677    #[pyo3(name = "from_order_side")]
678    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
679        order_side.into()
680    }
681
682    #[classattr]
683    #[pyo3(name = "BACK")]
684    fn py_back() -> Self {
685        Self::Back
686    }
687
688    #[classattr]
689    #[pyo3(name = "LAY")]
690    fn py_lay() -> Self {
691        Self::Lay
692    }
693
694    #[pyo3(name = "opposite")]
695    fn py_opposite(&self) -> Self {
696        self.opposite()
697    }
698}
699
700#[pymethods]
701impl BookAction {
702    #[new]
703    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
704        let t = Self::type_object(py);
705        Self::py_from_str(&t, value)
706    }
707
708    fn __repr__(&self) -> String {
709        format!(
710            "<{}.{}: '{}'>",
711            stringify!(BookAction),
712            self.name(),
713            self.value(),
714        )
715    }
716
717    fn __str__(&self) -> String {
718        self.to_string()
719    }
720
721    #[getter]
722    #[must_use]
723    pub fn name(&self) -> String {
724        self.to_string()
725    }
726
727    #[getter]
728    #[must_use]
729    pub fn value(&self) -> u8 {
730        *self as u8
731    }
732
733    #[classmethod]
734    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
735        EnumIterator::new::<Self>(py)
736    }
737
738    #[classmethod]
739    #[pyo3(name = "from_str")]
740    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
741        let data_str: &str = data.extract()?;
742        let tokenized = data_str.to_uppercase();
743        Self::from_str(&tokenized).map_err(to_pyvalue_err)
744    }
745
746    #[classattr]
747    #[pyo3(name = "ADD")]
748    fn py_add() -> Self {
749        Self::Add
750    }
751
752    #[classattr]
753    #[pyo3(name = "UPDATE")]
754    fn py_update() -> Self {
755        Self::Update
756    }
757
758    #[classattr]
759    #[pyo3(name = "DELETE")]
760    fn py_delete() -> Self {
761        Self::Delete
762    }
763
764    #[classattr]
765    #[pyo3(name = "CLEAR")]
766    fn py_clear() -> Self {
767        Self::Clear
768    }
769}
770
771#[pymethods]
772impl ContingencyType {
773    #[new]
774    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
775        let t = Self::type_object(py);
776        Self::py_from_str(&t, value)
777    }
778
779    fn __repr__(&self) -> String {
780        format!(
781            "<{}.{}: '{}'>",
782            stringify!(ContingencyType),
783            self.name(),
784            self.value(),
785        )
786    }
787
788    fn __str__(&self) -> String {
789        self.to_string()
790    }
791
792    #[getter]
793    #[must_use]
794    pub fn name(&self) -> String {
795        self.to_string()
796    }
797
798    #[getter]
799    #[must_use]
800    pub fn value(&self) -> u8 {
801        *self as u8
802    }
803
804    #[classmethod]
805    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
806        EnumIterator::new::<Self>(py)
807    }
808
809    #[classmethod]
810    #[pyo3(name = "from_str")]
811    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
812        let data_str: &str = data.extract()?;
813        let tokenized = data_str.to_uppercase();
814        Self::from_str(&tokenized).map_err(to_pyvalue_err)
815    }
816
817    #[classattr]
818    #[pyo3(name = "NO_CONTINGENCY")]
819    fn py_no_contingency() -> Self {
820        Self::NoContingency
821    }
822
823    #[classattr]
824    #[pyo3(name = "OCO")]
825    fn py_oco() -> Self {
826        Self::Oco
827    }
828
829    #[classattr]
830    #[pyo3(name = "OTO")]
831    fn py_oto() -> Self {
832        Self::Oto
833    }
834
835    #[classattr]
836    #[pyo3(name = "OUO")]
837    fn py_ouo() -> Self {
838        Self::Ouo
839    }
840}
841
842#[pymethods]
843impl CurrencyType {
844    #[new]
845    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
846        let t = Self::type_object(py);
847        Self::py_from_str(&t, value)
848    }
849
850    fn __repr__(&self) -> String {
851        format!(
852            "<{}.{}: '{}'>",
853            stringify!(CurrencyType),
854            self.name(),
855            self.value(),
856        )
857    }
858
859    fn __str__(&self) -> String {
860        self.to_string()
861    }
862
863    #[getter]
864    #[must_use]
865    pub fn name(&self) -> String {
866        self.to_string()
867    }
868
869    #[getter]
870    #[must_use]
871    pub fn value(&self) -> u8 {
872        *self as u8
873    }
874
875    #[classmethod]
876    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
877        EnumIterator::new::<Self>(py)
878    }
879
880    #[classmethod]
881    #[pyo3(name = "from_str")]
882    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
883        let data_str: &str = data.extract()?;
884        let tokenized = data_str.to_uppercase();
885        Self::from_str(&tokenized).map_err(to_pyvalue_err)
886    }
887
888    #[classattr]
889    #[pyo3(name = "CRYPTO")]
890    fn py_crypto() -> Self {
891        Self::Crypto
892    }
893
894    #[classattr]
895    #[pyo3(name = "FIAT")]
896    fn py_fiat() -> Self {
897        Self::Fiat
898    }
899
900    #[classattr]
901    #[pyo3(name = "COMMODITY_BACKED")]
902    fn py_commodity_backed() -> Self {
903        Self::CommodityBacked
904    }
905}
906
907#[pymethods]
908impl InstrumentCloseType {
909    #[new]
910    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
911        let t = Self::type_object(py);
912        Self::py_from_str(&t, value)
913    }
914
915    fn __repr__(&self) -> String {
916        format!(
917            "<{}.{}: '{}'>",
918            stringify!(InstrumentCloseType),
919            self.name(),
920            self.value(),
921        )
922    }
923
924    fn __str__(&self) -> String {
925        self.to_string()
926    }
927
928    #[getter]
929    #[must_use]
930    pub fn name(&self) -> String {
931        self.to_string()
932    }
933
934    #[getter]
935    #[must_use]
936    pub fn value(&self) -> u8 {
937        *self as u8
938    }
939
940    #[classmethod]
941    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
942        EnumIterator::new::<Self>(py)
943    }
944
945    #[classmethod]
946    #[pyo3(name = "from_str")]
947    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
948        let data_str: &str = data.extract()?;
949        let tokenized = data_str.to_uppercase();
950        Self::from_str(&tokenized).map_err(to_pyvalue_err)
951    }
952
953    #[classattr]
954    #[pyo3(name = "END_OF_SESSION")]
955    fn py_end_of_session() -> Self {
956        Self::EndOfSession
957    }
958
959    #[classattr]
960    #[pyo3(name = "CONTRACT_EXPIRED")]
961    fn py_contract_expired() -> Self {
962        Self::ContractExpired
963    }
964}
965
966#[pymethods]
967impl LiquiditySide {
968    #[new]
969    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
970        let t = Self::type_object(py);
971        Self::py_from_str(&t, value)
972    }
973
974    fn __repr__(&self) -> String {
975        format!(
976            "<{}.{}: '{}'>",
977            stringify!(LiquiditySide),
978            self.name(),
979            self.value(),
980        )
981    }
982
983    fn __str__(&self) -> String {
984        self.to_string()
985    }
986
987    #[getter]
988    #[must_use]
989    pub fn name(&self) -> String {
990        self.to_string()
991    }
992
993    #[getter]
994    #[must_use]
995    pub fn value(&self) -> u8 {
996        *self as u8
997    }
998
999    #[classmethod]
1000    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1001        EnumIterator::new::<Self>(py)
1002    }
1003
1004    #[classmethod]
1005    #[pyo3(name = "from_str")]
1006    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1007        let data_str: &str = data.extract()?;
1008        let tokenized = data_str.to_uppercase();
1009        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1010    }
1011
1012    #[classattr]
1013    #[pyo3(name = "NO_LIQUIDITY_SIDE")]
1014    fn py_no_liquidity_side() -> Self {
1015        Self::NoLiquiditySide
1016    }
1017
1018    #[classattr]
1019    #[pyo3(name = "MAKER")]
1020    fn py_maker() -> Self {
1021        Self::Maker
1022    }
1023
1024    #[classattr]
1025    #[pyo3(name = "TAKER")]
1026    fn py_taker() -> Self {
1027        Self::Taker
1028    }
1029}
1030
1031#[pymethods]
1032impl MarketStatus {
1033    #[new]
1034    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1035        let t = Self::type_object(py);
1036        Self::py_from_str(&t, value)
1037    }
1038
1039    fn __repr__(&self) -> String {
1040        format!(
1041            "<{}.{}: '{}'>",
1042            stringify!(MarketStatus),
1043            self.name(),
1044            self.value(),
1045        )
1046    }
1047
1048    fn __str__(&self) -> String {
1049        self.to_string()
1050    }
1051
1052    #[getter]
1053    #[must_use]
1054    pub fn name(&self) -> String {
1055        self.to_string()
1056    }
1057
1058    #[getter]
1059    #[must_use]
1060    pub fn value(&self) -> u8 {
1061        *self as u8
1062    }
1063
1064    #[classmethod]
1065    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1066        EnumIterator::new::<Self>(py)
1067    }
1068
1069    #[classmethod]
1070    #[pyo3(name = "from_str")]
1071    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1072        let data_str: &str = data.extract()?;
1073        let tokenized = data_str.to_uppercase();
1074        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1075    }
1076
1077    #[classattr]
1078    #[pyo3(name = "Open")]
1079    fn py_open() -> Self {
1080        Self::Open
1081    }
1082
1083    #[classattr]
1084    #[pyo3(name = "CLOSED")]
1085    fn py_closed() -> Self {
1086        Self::Closed
1087    }
1088
1089    #[classattr]
1090    #[pyo3(name = "PAUSED")]
1091    fn py_paused() -> Self {
1092        Self::Paused
1093    }
1094
1095    // # TODO: Unfortunately can't use this yet due to Cython (C enum namespacing)
1096    // #[classattr]
1097    // #[pyo3(name = "HALTED")]
1098    // fn py_halted() -> Self {
1099    //     Self::Halted
1100    // }
1101
1102    #[classattr]
1103    #[pyo3(name = "SUSPENDED")]
1104    fn py_suspended() -> Self {
1105        Self::Suspended
1106    }
1107
1108    #[classattr]
1109    #[pyo3(name = "NOT_AVAILABLE")]
1110    fn py_not_available() -> Self {
1111        Self::NotAvailable
1112    }
1113}
1114
1115#[pymethods]
1116impl MarketStatusAction {
1117    #[new]
1118    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1119        let t = Self::type_object(py);
1120        Self::py_from_str(&t, value)
1121    }
1122
1123    fn __repr__(&self) -> String {
1124        format!(
1125            "<{}.{}: '{}'>",
1126            stringify!(MarketStatus),
1127            self.name(),
1128            self.value(),
1129        )
1130    }
1131
1132    fn __str__(&self) -> String {
1133        self.to_string()
1134    }
1135
1136    #[getter]
1137    #[must_use]
1138    pub fn name(&self) -> String {
1139        self.to_string()
1140    }
1141
1142    #[getter]
1143    #[must_use]
1144    pub fn value(&self) -> u8 {
1145        *self as u8
1146    }
1147
1148    #[classmethod]
1149    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1150        EnumIterator::new::<Self>(py)
1151    }
1152
1153    #[classmethod]
1154    #[pyo3(name = "from_str")]
1155    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1156        let data_str: &str = data.extract()?;
1157        let tokenized = data_str.to_uppercase();
1158        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1159    }
1160
1161    #[classattr]
1162    #[pyo3(name = "NONE")]
1163    fn py_none() -> Self {
1164        Self::None
1165    }
1166
1167    #[classattr]
1168    #[pyo3(name = "PRE_OPEN")]
1169    fn py_pre_open() -> Self {
1170        Self::PreOpen
1171    }
1172
1173    #[classattr]
1174    #[pyo3(name = "PRE_CROSS")]
1175    fn py_pre_cross() -> Self {
1176        Self::Pause
1177    }
1178
1179    #[classattr]
1180    #[pyo3(name = "QUOTING")]
1181    fn py_quoting() -> Self {
1182        Self::Quoting
1183    }
1184
1185    #[classattr]
1186    #[pyo3(name = "CROSS")]
1187    fn py_cross() -> Self {
1188        Self::Cross
1189    }
1190
1191    #[classattr]
1192    #[pyo3(name = "ROTATION")]
1193    fn py_rotation() -> Self {
1194        Self::Rotation
1195    }
1196
1197    #[classattr]
1198    #[pyo3(name = "NEW_PRICE_INDICATION")]
1199    fn py_new_price_indication() -> Self {
1200        Self::NewPriceIndication
1201    }
1202
1203    #[classattr]
1204    #[pyo3(name = "TRADING")]
1205    fn py_trading() -> Self {
1206        Self::Trading
1207    }
1208
1209    #[classattr]
1210    #[pyo3(name = "HALT")]
1211    fn py_halt() -> Self {
1212        Self::Halt
1213    }
1214
1215    #[classattr]
1216    #[pyo3(name = "PAUSE")]
1217    fn py_pause() -> Self {
1218        Self::Pause
1219    }
1220
1221    #[classattr]
1222    #[pyo3(name = "SUSPEND")]
1223    fn py_suspend() -> Self {
1224        Self::Suspend
1225    }
1226
1227    #[classattr]
1228    #[pyo3(name = "PRE_CLOSE")]
1229    fn py_pre_close() -> Self {
1230        Self::PreClose
1231    }
1232
1233    #[classattr]
1234    #[pyo3(name = "CLOSE")]
1235    fn py_close() -> Self {
1236        Self::Close
1237    }
1238
1239    #[classattr]
1240    #[pyo3(name = "POST_CLOSE")]
1241    fn py_post_close() -> Self {
1242        Self::PostClose
1243    }
1244
1245    #[classattr]
1246    #[pyo3(name = "SHORT_SELL_RESTRICTION_CHANGE")]
1247    fn py_short_sell_restriction() -> Self {
1248        Self::ShortSellRestrictionChange
1249    }
1250
1251    #[classattr]
1252    #[pyo3(name = "NOT_AVAILABLE_FOR_TRADING")]
1253    fn py_not_available_for_trading() -> Self {
1254        Self::NotAvailableForTrading
1255    }
1256}
1257
1258#[pymethods]
1259impl OmsType {
1260    #[new]
1261    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1262        let t = Self::type_object(py);
1263        Self::py_from_str(&t, value)
1264    }
1265
1266    fn __repr__(&self) -> String {
1267        format!(
1268            "<{}.{}: '{}'>",
1269            stringify!(OmsType),
1270            self.name(),
1271            self.value(),
1272        )
1273    }
1274
1275    fn __str__(&self) -> String {
1276        self.to_string()
1277    }
1278
1279    #[getter]
1280    #[must_use]
1281    pub fn name(&self) -> String {
1282        self.to_string()
1283    }
1284
1285    #[getter]
1286    #[must_use]
1287    pub fn value(&self) -> u8 {
1288        *self as u8
1289    }
1290
1291    #[classmethod]
1292    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1293        EnumIterator::new::<Self>(py)
1294    }
1295
1296    #[classmethod]
1297    #[pyo3(name = "from_str")]
1298    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1299        let data_str: &str = data.extract()?;
1300        let tokenized = data_str.to_uppercase();
1301        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1302    }
1303
1304    #[classattr]
1305    #[pyo3(name = "UNSPECIFIED")]
1306    fn py_unspecified() -> Self {
1307        Self::Unspecified
1308    }
1309
1310    #[classattr]
1311    #[pyo3(name = "NETTING")]
1312    fn py_netting() -> Self {
1313        Self::Netting
1314    }
1315
1316    #[classattr]
1317    #[pyo3(name = "HEDGING")]
1318    fn py_hedging() -> Self {
1319        Self::Hedging
1320    }
1321}
1322
1323#[pymethods]
1324impl OptionKind {
1325    #[new]
1326    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1327        let t = Self::type_object(py);
1328        Self::py_from_str(&t, value)
1329    }
1330
1331    fn __repr__(&self) -> String {
1332        format!(
1333            "<{}.{}: '{}'>",
1334            stringify!(OptionKind),
1335            self.name(),
1336            self.value(),
1337        )
1338    }
1339
1340    fn __str__(&self) -> String {
1341        self.to_string()
1342    }
1343
1344    #[getter]
1345    #[must_use]
1346    pub fn name(&self) -> String {
1347        self.to_string()
1348    }
1349
1350    #[getter]
1351    #[must_use]
1352    pub fn value(&self) -> u8 {
1353        *self as u8
1354    }
1355
1356    #[classmethod]
1357    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1358        EnumIterator::new::<Self>(py)
1359    }
1360
1361    #[classmethod]
1362    #[pyo3(name = "from_str")]
1363    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1364        let data_str: &str = data.extract()?;
1365        let tokenized = data_str.to_uppercase();
1366        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1367    }
1368
1369    #[classattr]
1370    #[pyo3(name = "CALL")]
1371    fn py_call() -> Self {
1372        Self::Call
1373    }
1374
1375    #[classattr]
1376    #[pyo3(name = "PUT")]
1377    fn py_put() -> Self {
1378        Self::Put
1379    }
1380}
1381
1382#[pymethods]
1383impl OrderSide {
1384    #[new]
1385    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1386        let t = Self::type_object(py);
1387        Self::py_from_str(&t, value)
1388    }
1389
1390    fn __repr__(&self) -> String {
1391        format!(
1392            "<{}.{}: '{}'>",
1393            stringify!(OrderSide),
1394            self.name(),
1395            self.value(),
1396        )
1397    }
1398
1399    fn __str__(&self) -> String {
1400        self.to_string()
1401    }
1402
1403    #[getter]
1404    #[must_use]
1405    pub fn name(&self) -> String {
1406        self.to_string()
1407    }
1408
1409    #[getter]
1410    #[must_use]
1411    pub fn value(&self) -> u8 {
1412        *self as u8
1413    }
1414
1415    #[classmethod]
1416    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1417        EnumIterator::new::<Self>(py)
1418    }
1419
1420    #[classmethod]
1421    #[pyo3(name = "from_str")]
1422    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1423        let data_str: &str = data.extract()?;
1424        let tokenized = data_str.to_uppercase();
1425        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1426    }
1427
1428    #[classattr]
1429    #[pyo3(name = "NO_ORDER_SIDE")]
1430    fn py_no_order_side() -> Self {
1431        Self::NoOrderSide
1432    }
1433
1434    #[classattr]
1435    #[pyo3(name = "BUY")]
1436    fn py_buy() -> Self {
1437        Self::Buy
1438    }
1439
1440    #[classattr]
1441    #[pyo3(name = "SELL")]
1442    fn py_sell() -> Self {
1443        Self::Sell
1444    }
1445}
1446
1447#[pymethods]
1448impl OrderStatus {
1449    #[new]
1450    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1451        let t = Self::type_object(py);
1452        Self::py_from_str(&t, value)
1453    }
1454
1455    fn __repr__(&self) -> String {
1456        format!(
1457            "<{}.{}: '{}'>",
1458            stringify!(OrderStatus),
1459            self.name(),
1460            self.value(),
1461        )
1462    }
1463
1464    fn __str__(&self) -> String {
1465        self.to_string()
1466    }
1467
1468    #[getter]
1469    #[must_use]
1470    pub fn name(&self) -> String {
1471        self.to_string()
1472    }
1473
1474    #[getter]
1475    #[must_use]
1476    pub fn value(&self) -> u8 {
1477        *self as u8
1478    }
1479
1480    #[classmethod]
1481    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1482        EnumIterator::new::<Self>(py)
1483    }
1484
1485    #[classmethod]
1486    #[pyo3(name = "from_str")]
1487    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1488        let data_str: &str = data.extract()?;
1489        let tokenized = data_str.to_uppercase();
1490        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1491    }
1492
1493    #[classattr]
1494    #[pyo3(name = "INITIALIZED")]
1495    fn py_initialized() -> Self {
1496        Self::Initialized
1497    }
1498
1499    #[classattr]
1500    #[pyo3(name = "DENIED")]
1501    fn py_denied() -> Self {
1502        Self::Denied
1503    }
1504
1505    #[classattr]
1506    #[pyo3(name = "EMULATED")]
1507    fn py_emulated() -> Self {
1508        Self::Emulated
1509    }
1510
1511    #[classattr]
1512    #[pyo3(name = "RELEASED")]
1513    fn py_released() -> Self {
1514        Self::Released
1515    }
1516
1517    #[classattr]
1518    #[pyo3(name = "SUBMITTED")]
1519    fn py_submitted() -> Self {
1520        Self::Submitted
1521    }
1522
1523    #[classattr]
1524    #[pyo3(name = "ACCEPTED")]
1525    fn py_accepted() -> Self {
1526        Self::Accepted
1527    }
1528
1529    #[classattr]
1530    #[pyo3(name = "REJECTED")]
1531    fn py_rejected() -> Self {
1532        Self::Rejected
1533    }
1534
1535    #[classattr]
1536    #[pyo3(name = "CANCELED")]
1537    fn py_canceled() -> Self {
1538        Self::Canceled
1539    }
1540
1541    #[classattr]
1542    #[pyo3(name = "EXPIRED")]
1543    fn py_expired() -> Self {
1544        Self::Expired
1545    }
1546
1547    #[classattr]
1548    #[pyo3(name = "TRIGGERED")]
1549    fn py_triggered() -> Self {
1550        Self::Triggered
1551    }
1552
1553    #[classattr]
1554    #[pyo3(name = "PENDING_UPDATE")]
1555    fn py_pending_update() -> Self {
1556        Self::PendingUpdate
1557    }
1558
1559    #[classattr]
1560    #[pyo3(name = "PENDING_CANCEL")]
1561    fn py_pending_cancel() -> Self {
1562        Self::PendingCancel
1563    }
1564
1565    #[classattr]
1566    #[pyo3(name = "PARTIALLY_FILLED")]
1567    fn py_partially_filled() -> Self {
1568        Self::PartiallyFilled
1569    }
1570
1571    #[classattr]
1572    #[pyo3(name = "FILLED")]
1573    fn py_filled() -> Self {
1574        Self::Filled
1575    }
1576}
1577
1578#[pymethods]
1579impl OrderType {
1580    #[new]
1581    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1582        let t = Self::type_object(py);
1583        Self::py_from_str(&t, value)
1584    }
1585
1586    fn __repr__(&self) -> String {
1587        format!(
1588            "<{}.{}: '{}'>",
1589            stringify!(OrderType),
1590            self.name(),
1591            self.value(),
1592        )
1593    }
1594
1595    fn __str__(&self) -> String {
1596        self.to_string()
1597    }
1598
1599    #[getter]
1600    #[must_use]
1601    pub fn name(&self) -> String {
1602        self.to_string()
1603    }
1604
1605    #[getter]
1606    #[must_use]
1607    pub fn value(&self) -> u8 {
1608        *self as u8
1609    }
1610
1611    #[classmethod]
1612    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1613        EnumIterator::new::<Self>(py)
1614    }
1615
1616    #[classmethod]
1617    #[pyo3(name = "from_str")]
1618    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1619        let data_str: &str = data.extract()?;
1620        let tokenized = data_str.to_uppercase();
1621        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1622    }
1623
1624    #[classattr]
1625    #[pyo3(name = "MARKET")]
1626    fn py_market() -> Self {
1627        Self::Market
1628    }
1629
1630    #[classattr]
1631    #[pyo3(name = "LIMIT")]
1632    fn py_limit() -> Self {
1633        Self::Limit
1634    }
1635
1636    #[classattr]
1637    #[pyo3(name = "STOP_MARKET")]
1638    fn py_stop_market() -> Self {
1639        Self::StopMarket
1640    }
1641
1642    #[classattr]
1643    #[pyo3(name = "STOP_LIMIT")]
1644    fn py_stop_limit() -> Self {
1645        Self::StopLimit
1646    }
1647
1648    #[classattr]
1649    #[pyo3(name = "MARKET_TO_LIMIT")]
1650    fn py_market_to_limit() -> Self {
1651        Self::MarketToLimit
1652    }
1653
1654    #[classattr]
1655    #[pyo3(name = "MARKET_IF_TOUCHED")]
1656    fn py_market_if_touched() -> Self {
1657        Self::MarketIfTouched
1658    }
1659
1660    #[classattr]
1661    #[pyo3(name = "LIMIT_IF_TOUCHED")]
1662    fn py_limit_if_touched() -> Self {
1663        Self::LimitIfTouched
1664    }
1665
1666    #[classattr]
1667    #[pyo3(name = "TRAILING_STOP_MARKET")]
1668    fn py_trailing_stop_market() -> Self {
1669        Self::TrailingStopMarket
1670    }
1671
1672    #[classattr]
1673    #[pyo3(name = "TRAILING_STOP_LIMIT")]
1674    fn py_trailing_stop_limit() -> Self {
1675        Self::TrailingStopLimit
1676    }
1677}
1678
1679#[pymethods]
1680impl PositionSide {
1681    #[new]
1682    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1683        let t = Self::type_object(py);
1684        Self::py_from_str(&t, value)
1685    }
1686
1687    fn __repr__(&self) -> String {
1688        format!(
1689            "<{}.{}: '{}'>",
1690            stringify!(PositionSide),
1691            self.name(),
1692            self.value(),
1693        )
1694    }
1695
1696    fn __str__(&self) -> String {
1697        self.to_string()
1698    }
1699
1700    #[getter]
1701    #[must_use]
1702    pub fn name(&self) -> String {
1703        self.to_string()
1704    }
1705
1706    #[getter]
1707    #[must_use]
1708    pub fn value(&self) -> u8 {
1709        *self as u8
1710    }
1711
1712    #[classmethod]
1713    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1714        EnumIterator::new::<Self>(py)
1715    }
1716
1717    #[classmethod]
1718    #[pyo3(name = "from_str")]
1719    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1720        let data_str: &str = data.extract()?;
1721        let tokenized = data_str.to_uppercase();
1722        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1723    }
1724
1725    #[classattr]
1726    #[pyo3(name = "NO_POSITION_SIDE")]
1727    fn py_no_position_side() -> Self {
1728        Self::NoPositionSide
1729    }
1730
1731    #[classattr]
1732    #[pyo3(name = "FLAT")]
1733    fn py_flat() -> Self {
1734        Self::Flat
1735    }
1736
1737    #[classattr]
1738    #[pyo3(name = "LONG")]
1739    fn py_long() -> Self {
1740        Self::Long
1741    }
1742
1743    #[classattr]
1744    #[pyo3(name = "SHORT")]
1745    fn py_short() -> Self {
1746        Self::Short
1747    }
1748}
1749
1750#[pymethods]
1751impl PriceType {
1752    #[new]
1753    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1754        let t = Self::type_object(py);
1755        Self::py_from_str(&t, value)
1756    }
1757
1758    fn __repr__(&self) -> String {
1759        format!(
1760            "<{}.{}: '{}'>",
1761            stringify!(PositionSide),
1762            self.name(),
1763            self.value(),
1764        )
1765    }
1766
1767    fn __str__(&self) -> String {
1768        self.to_string()
1769    }
1770
1771    #[getter]
1772    #[must_use]
1773    pub fn name(&self) -> String {
1774        self.to_string()
1775    }
1776
1777    #[getter]
1778    #[must_use]
1779    pub fn value(&self) -> u8 {
1780        *self as u8
1781    }
1782
1783    #[classmethod]
1784    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1785        EnumIterator::new::<Self>(py)
1786    }
1787
1788    #[classmethod]
1789    #[pyo3(name = "from_str")]
1790    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1791        let data_str: &str = data.extract()?;
1792        let tokenized = data_str.to_uppercase();
1793        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1794    }
1795
1796    #[classmethod]
1797    #[pyo3(name = "from_int")]
1798    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1799        Self::from_repr(value as usize)
1800            .ok_or_else(|| PyValueError::new_err(format!("Invalid PriceType value: {value}")))
1801    }
1802
1803    #[classattr]
1804    #[pyo3(name = "BID")]
1805    fn py_bid() -> Self {
1806        Self::Bid
1807    }
1808
1809    #[classattr]
1810    #[pyo3(name = "ASK")]
1811    fn py_ask() -> Self {
1812        Self::Ask
1813    }
1814
1815    #[classattr]
1816    #[pyo3(name = "MID")]
1817    fn py_mid() -> Self {
1818        Self::Mid
1819    }
1820
1821    #[classattr]
1822    #[pyo3(name = "LAST")]
1823    fn py_last() -> Self {
1824        Self::Last
1825    }
1826
1827    #[classattr]
1828    #[pyo3(name = "MARK")]
1829    fn py_mark() -> Self {
1830        Self::Mark
1831    }
1832}
1833
1834#[pymethods]
1835impl RecordFlag {
1836    #[new]
1837    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1838        let t = Self::type_object(py);
1839        Self::py_from_str(&t, value)
1840    }
1841
1842    fn __repr__(&self) -> String {
1843        format!(
1844            "<{}.{}: '{}'>",
1845            stringify!(RecordFlag),
1846            self.name(),
1847            self.value(),
1848        )
1849    }
1850
1851    fn __str__(&self) -> String {
1852        self.to_string()
1853    }
1854
1855    #[getter]
1856    #[must_use]
1857    pub fn name(&self) -> String {
1858        self.to_string()
1859    }
1860
1861    #[getter]
1862    #[must_use]
1863    pub fn value(&self) -> u8 {
1864        *self as u8
1865    }
1866
1867    #[classmethod]
1868    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1869        EnumIterator::new::<Self>(py)
1870    }
1871
1872    #[classmethod]
1873    #[pyo3(name = "from_str")]
1874    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1875        let data_str: &str = data.extract()?;
1876        let tokenized = data_str.to_uppercase();
1877        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1878    }
1879
1880    #[classattr]
1881    #[pyo3(name = "LAST")]
1882    fn py_last() -> Self {
1883        Self::F_LAST
1884    }
1885
1886    #[classattr]
1887    #[pyo3(name = "TOB")]
1888    fn py_tob() -> Self {
1889        Self::F_TOB
1890    }
1891
1892    #[classattr]
1893    #[pyo3(name = "SNAPSHOT")]
1894    fn py_snapshot() -> Self {
1895        Self::F_SNAPSHOT
1896    }
1897
1898    #[classattr]
1899    #[pyo3(name = "MBP")]
1900    fn py_mbp() -> Self {
1901        Self::F_MBP
1902    }
1903
1904    #[pyo3(name = "matches")]
1905    fn py_matches(&self, value: u8) -> bool {
1906        self.matches(value)
1907    }
1908}
1909
1910#[pymethods]
1911impl TimeInForce {
1912    #[new]
1913    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1914        let t = Self::type_object(py);
1915        Self::py_from_str(&t, value)
1916    }
1917
1918    fn __repr__(&self) -> String {
1919        format!(
1920            "<{}.{}: '{}'>",
1921            stringify!(TimeInForce),
1922            self.name(),
1923            self.value(),
1924        )
1925    }
1926
1927    fn __str__(&self) -> String {
1928        self.to_string()
1929    }
1930
1931    #[getter]
1932    #[must_use]
1933    pub fn name(&self) -> String {
1934        self.to_string()
1935    }
1936
1937    #[getter]
1938    #[must_use]
1939    pub fn value(&self) -> u8 {
1940        *self as u8
1941    }
1942
1943    #[classmethod]
1944    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1945        EnumIterator::new::<Self>(py)
1946    }
1947
1948    #[classmethod]
1949    #[pyo3(name = "from_str")]
1950    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1951        let data_str: &str = data.extract()?;
1952        let tokenized = data_str.to_uppercase();
1953        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1954    }
1955
1956    #[classattr]
1957    #[pyo3(name = "GTC")]
1958    fn py_gtc() -> Self {
1959        Self::Gtc
1960    }
1961
1962    #[classattr]
1963    #[pyo3(name = "IOC")]
1964    fn py_ioc() -> Self {
1965        Self::Ioc
1966    }
1967
1968    #[classattr]
1969    #[pyo3(name = "FOK")]
1970    fn py_fok() -> Self {
1971        Self::Fok
1972    }
1973
1974    #[classattr]
1975    #[pyo3(name = "GTD")]
1976    fn py_gtd() -> Self {
1977        Self::Gtd
1978    }
1979
1980    #[classattr]
1981    #[pyo3(name = "DAY")]
1982    fn py_day() -> Self {
1983        Self::Day
1984    }
1985
1986    #[classattr]
1987    #[pyo3(name = "AT_THE_OPEN")]
1988    fn py_at_the_open() -> Self {
1989        Self::AtTheOpen
1990    }
1991
1992    #[classattr]
1993    #[pyo3(name = "AT_THE_CLOSE")]
1994    fn py_at_the_close() -> Self {
1995        Self::AtTheClose
1996    }
1997}
1998
1999#[pymethods]
2000impl TrailingOffsetType {
2001    #[new]
2002    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
2003        let t = Self::type_object(py);
2004        Self::py_from_str(&t, value)
2005    }
2006
2007    fn __repr__(&self) -> String {
2008        format!(
2009            "<{}.{}: '{}'>",
2010            stringify!(TrailingOffsetType),
2011            self.name(),
2012            self.value(),
2013        )
2014    }
2015
2016    fn __str__(&self) -> String {
2017        self.to_string()
2018    }
2019
2020    #[getter]
2021    #[must_use]
2022    pub fn name(&self) -> String {
2023        self.to_string()
2024    }
2025
2026    #[getter]
2027    #[must_use]
2028    pub fn value(&self) -> u8 {
2029        *self as u8
2030    }
2031
2032    #[classmethod]
2033    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
2034        EnumIterator::new::<Self>(py)
2035    }
2036
2037    #[classmethod]
2038    #[pyo3(name = "from_str")]
2039    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
2040        let data_str: &str = data.extract()?;
2041        let tokenized = data_str.to_uppercase();
2042        Self::from_str(&tokenized).map_err(to_pyvalue_err)
2043    }
2044
2045    #[classattr]
2046    #[pyo3(name = "NO_TRAILING_OFFSET")]
2047    fn py_no_trailing_offset() -> Self {
2048        Self::NoTrailingOffset
2049    }
2050
2051    #[classattr]
2052    #[pyo3(name = "PRICE")]
2053    fn py_price() -> Self {
2054        Self::Price
2055    }
2056
2057    #[classattr]
2058    #[pyo3(name = "BASIS_POINTS")]
2059    fn py_basis_points() -> Self {
2060        Self::BasisPoints
2061    }
2062
2063    #[classattr]
2064    #[pyo3(name = "TICKS")]
2065    fn py_ticks() -> Self {
2066        Self::Ticks
2067    }
2068
2069    #[classattr]
2070    #[pyo3(name = "PRICE_TIER")]
2071    fn py_price_tier() -> Self {
2072        Self::PriceTier
2073    }
2074}
2075
2076#[pymethods]
2077impl TriggerType {
2078    #[new]
2079    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
2080        let t = Self::type_object(py);
2081        Self::py_from_str(&t, value)
2082    }
2083
2084    fn __repr__(&self) -> String {
2085        format!(
2086            "<{}.{}: '{}'>",
2087            stringify!(TriggerType),
2088            self.name(),
2089            self.value(),
2090        )
2091    }
2092
2093    fn __str__(&self) -> String {
2094        self.to_string()
2095    }
2096
2097    #[getter]
2098    #[must_use]
2099    pub fn name(&self) -> String {
2100        self.to_string()
2101    }
2102
2103    #[getter]
2104    #[must_use]
2105    pub fn value(&self) -> u8 {
2106        *self as u8
2107    }
2108
2109    #[classmethod]
2110    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
2111        EnumIterator::new::<Self>(py)
2112    }
2113
2114    #[classmethod]
2115    #[pyo3(name = "from_str")]
2116    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
2117        let data_str: &str = data.extract()?;
2118        let tokenized = data_str.to_uppercase();
2119        Self::from_str(&tokenized).map_err(to_pyvalue_err)
2120    }
2121
2122    #[classattr]
2123    #[pyo3(name = "NO_TRIGGER")]
2124    fn py_no_trigger() -> Self {
2125        Self::NoTrigger
2126    }
2127
2128    #[classattr]
2129    #[pyo3(name = "DEFAULT")]
2130    fn py_default() -> Self {
2131        Self::Default
2132    }
2133
2134    #[classattr]
2135    #[pyo3(name = "BID_ASK")]
2136    fn py_bid_ask() -> Self {
2137        Self::BidAsk
2138    }
2139
2140    #[classattr]
2141    #[pyo3(name = "LAST_PRICE")]
2142    fn py_last_trade() -> Self {
2143        Self::LastPrice
2144    }
2145
2146    #[classattr]
2147    #[pyo3(name = "DOUBLE_LAST")]
2148    fn py_double_last() -> Self {
2149        Self::DoubleLast
2150    }
2151
2152    #[classattr]
2153    #[pyo3(name = "DOUBLE_BID_ASK")]
2154    fn py_double_bid_ask() -> Self {
2155        Self::DoubleBidAsk
2156    }
2157
2158    #[classattr]
2159    #[pyo3(name = "LAST_OR_BID_ASK")]
2160    fn py_last_or_bid_ask() -> Self {
2161        Self::LastOrBidAsk
2162    }
2163
2164    #[classattr]
2165    #[pyo3(name = "MID_POINT")]
2166    fn py_mid_point() -> Self {
2167        Self::MidPoint
2168    }
2169
2170    #[classattr]
2171    #[pyo3(name = "MARK_PRICE")]
2172    fn py_mark_price() -> Self {
2173        Self::MarkPrice
2174    }
2175
2176    #[classattr]
2177    #[pyo3(name = "INDEX_PRICE")]
2178    fn py_index_price() -> Self {
2179        Self::IndexPrice
2180    }
2181}
2182
2183#[pymethods]
2184impl BookType {
2185    #[new]
2186    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
2187        let t = Self::type_object(py);
2188        Self::py_from_str(&t, value)
2189    }
2190
2191    fn __repr__(&self) -> String {
2192        format!(
2193            "<{}.{}: '{}'>",
2194            stringify!(BookType),
2195            self.name(),
2196            self.value(),
2197        )
2198    }
2199
2200    fn __str__(&self) -> String {
2201        self.to_string()
2202    }
2203
2204    #[getter]
2205    #[must_use]
2206    pub fn name(&self) -> String {
2207        self.to_string()
2208    }
2209
2210    #[getter]
2211    #[must_use]
2212    pub fn value(&self) -> u8 {
2213        *self as u8
2214    }
2215
2216    #[classmethod]
2217    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
2218        EnumIterator::new::<Self>(py)
2219    }
2220
2221    #[classmethod]
2222    #[pyo3(name = "from_str")]
2223    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
2224        let data_str: &str = data.extract()?;
2225        let tokenized = data_str.to_uppercase();
2226        Self::from_str(&tokenized).map_err(to_pyvalue_err)
2227    }
2228
2229    #[classattr]
2230    #[pyo3(name = "L1_MBP")]
2231    fn py_l1_mbp() -> Self {
2232        Self::L1_MBP
2233    }
2234
2235    #[classattr]
2236    #[pyo3(name = "L2_MBP")]
2237    fn py_l2_mbp() -> Self {
2238        Self::L2_MBP
2239    }
2240
2241    #[classattr]
2242    #[pyo3(name = "L3_MBO")]
2243    fn py_l3_mbo() -> Self {
2244        Self::L3_MBO
2245    }
2246}
2247
2248#[pymethods]
2249impl TradingState {
2250    #[new]
2251    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
2252        let t = Self::type_object(py);
2253        Self::py_from_str(&t, value)
2254    }
2255
2256    fn __repr__(&self) -> String {
2257        format!(
2258            "<{}.{}: '{}'>",
2259            stringify!(TradingState),
2260            self.name(),
2261            self.value(),
2262        )
2263    }
2264
2265    fn __str__(&self) -> String {
2266        self.to_string()
2267    }
2268
2269    #[getter]
2270    #[must_use]
2271    pub fn name(&self) -> String {
2272        self.to_string()
2273    }
2274
2275    #[getter]
2276    #[must_use]
2277    pub fn value(&self) -> u8 {
2278        *self as u8
2279    }
2280
2281    #[classmethod]
2282    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
2283        EnumIterator::new::<Self>(py)
2284    }
2285
2286    #[classmethod]
2287    #[pyo3(name = "from_str")]
2288    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
2289        let data_str: &str = data.extract()?;
2290        let tokenized = data_str.to_uppercase();
2291        Self::from_str(&tokenized).map_err(to_pyvalue_err)
2292    }
2293
2294    #[classattr]
2295    #[pyo3(name = "ACTIVE")]
2296    fn py_active() -> Self {
2297        Self::Active
2298    }
2299
2300    #[classattr]
2301    #[pyo3(name = "HALTED")]
2302    fn py_halted() -> Self {
2303        Self::Halted
2304    }
2305
2306    #[classattr]
2307    #[pyo3(name = "REDUCING")]
2308    fn py_reducing() -> Self {
2309        Self::Reducing
2310    }
2311}