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, AvgPxReconciliation,
26        BarAggregation, BarIntervalType, BetSide, BookAction, BookType, ContingencyType,
27        ContinuousFutureAdjustmentType, CurrencyType, ExerciseStyle, GreeksConvention,
28        InstrumentClass, InstrumentCloseType, LiquiditySide, MarketStatus, MarketStatusAction,
29        OmsType, OptionKind, OptionSideFilter, OrderSide, OrderStatus, OrderType, OtoTriggerMode,
30        PositionAdjustmentType, PositionSide, PriceType, RecordFlag, SettlementType, TimeInForce,
31        TradingState, TrailingOffsetType, TriggerType,
32    },
33    python::common::EnumIterator,
34};
35
36#[pymethods]
37#[pyo3_stub_gen::derive::gen_stub_pymethods]
38impl AccountType {
39    /// An account type provided by a trading venue or execution provider.
40    #[new]
41    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
42        let t = Self::type_object(py);
43        Self::py_from_str(&t, value)
44    }
45
46    const fn __hash__(&self) -> isize {
47        *self as isize
48    }
49
50    fn __str__(&self) -> String {
51        self.to_string()
52    }
53
54    #[getter]
55    #[must_use]
56    pub fn name(&self) -> String {
57        self.to_string()
58    }
59
60    #[getter]
61    #[must_use]
62    pub fn value(&self) -> u8 {
63        *self as u8
64    }
65
66    #[classmethod]
67    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
68        EnumIterator::new::<Self>(py)
69    }
70
71    #[classmethod]
72    #[pyo3(name = "from_str")]
73    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
74        let data_str: &str = data.extract()?;
75        let tokenized = data_str.to_uppercase();
76        Self::from_str(&tokenized).map_err(to_pyvalue_err)
77    }
78}
79
80#[pymethods]
81#[pyo3_stub_gen::derive::gen_stub_pymethods]
82impl PositionAdjustmentType {
83    /// The type of position adjustment.
84    #[new]
85    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
86        let t = Self::type_object(py);
87        Self::py_from_str(&t, value)
88    }
89
90    const fn __hash__(&self) -> isize {
91        *self as isize
92    }
93
94    fn __str__(&self) -> String {
95        self.to_string()
96    }
97
98    #[getter]
99    #[must_use]
100    pub fn name(&self) -> String {
101        self.to_string()
102    }
103
104    #[getter]
105    #[must_use]
106    pub fn value(&self) -> u8 {
107        *self as u8
108    }
109
110    #[classmethod]
111    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
112        EnumIterator::new::<Self>(py)
113    }
114
115    #[classmethod]
116    #[pyo3(name = "from_str")]
117    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
118        let data_str: &str = data.extract()?;
119        let tokenized = data_str.to_uppercase();
120        Self::from_str(&tokenized).map_err(to_pyvalue_err)
121    }
122}
123
124#[pymethods]
125#[pyo3_stub_gen::derive::gen_stub_pymethods]
126impl AggregationSource {
127    /// An aggregation source for derived data.
128    #[new]
129    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
130        let t = Self::type_object(py);
131        Self::py_from_str(&t, value)
132    }
133
134    const fn __hash__(&self) -> isize {
135        *self as isize
136    }
137
138    fn __str__(&self) -> String {
139        self.to_string()
140    }
141
142    #[getter]
143    #[must_use]
144    pub fn name(&self) -> String {
145        self.to_string()
146    }
147
148    #[getter]
149    #[must_use]
150    pub fn value(&self) -> u8 {
151        *self as u8
152    }
153
154    #[classmethod]
155    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
156        EnumIterator::new::<Self>(py)
157    }
158
159    #[classmethod]
160    #[pyo3(name = "from_str")]
161    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
162        let data_str: &str = data.extract()?;
163        let tokenized = data_str.to_uppercase();
164        Self::from_str(&tokenized).map_err(to_pyvalue_err)
165    }
166}
167
168#[pymethods]
169#[pyo3_stub_gen::derive::gen_stub_pymethods]
170impl AggressorSide {
171    /// The side for the aggressing order of a trade in a market.
172    #[new]
173    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
174        let t = Self::type_object(py);
175        Self::py_from_str(&t, value)
176    }
177
178    const fn __hash__(&self) -> isize {
179        *self as isize
180    }
181
182    fn __str__(&self) -> String {
183        self.to_string()
184    }
185
186    #[getter]
187    #[must_use]
188    pub fn name(&self) -> String {
189        self.to_string()
190    }
191
192    #[getter]
193    #[must_use]
194    pub fn value(&self) -> u8 {
195        *self as u8
196    }
197
198    #[classmethod]
199    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
200        EnumIterator::new::<Self>(py)
201    }
202
203    #[classmethod]
204    #[pyo3(name = "from_str")]
205    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
206        let data_str: &str = data.extract()?;
207        let tokenized = data_str.to_uppercase();
208        Self::from_str(&tokenized).map_err(to_pyvalue_err)
209    }
210}
211
212#[pymethods]
213#[pyo3_stub_gen::derive::gen_stub_pymethods]
214impl AssetClass {
215    /// A broad financial market asset class.
216    #[new]
217    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
218        let t = Self::type_object(py);
219        Self::py_from_str(&t, value)
220    }
221
222    const fn __hash__(&self) -> isize {
223        *self as isize
224    }
225
226    fn __str__(&self) -> String {
227        self.to_string()
228    }
229
230    #[getter]
231    #[must_use]
232    pub fn name(&self) -> String {
233        self.to_string()
234    }
235
236    #[getter]
237    #[must_use]
238    pub fn value(&self) -> u8 {
239        *self as u8
240    }
241
242    #[classmethod]
243    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
244        EnumIterator::new::<Self>(py)
245    }
246
247    #[classmethod]
248    #[pyo3(name = "from_str")]
249    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
250        let data_str: &str = data.extract()?;
251        let tokenized = data_str.to_uppercase();
252        Self::from_str(&tokenized).map_err(to_pyvalue_err)
253    }
254}
255
256#[pymethods]
257#[pyo3_stub_gen::derive::gen_stub_pymethods]
258impl AvgPxReconciliation {
259    /// How position reconciliation may use a venue-reported average entry price.
260    #[new]
261    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
262        let t = Self::type_object(py);
263        Self::py_from_str(&t, value)
264    }
265
266    const fn __hash__(&self) -> isize {
267        *self as isize
268    }
269
270    fn __str__(&self) -> String {
271        self.to_string()
272    }
273
274    #[getter]
275    #[must_use]
276    pub fn name(&self) -> String {
277        self.to_string()
278    }
279
280    #[getter]
281    #[must_use]
282    pub fn value(&self) -> u8 {
283        *self as u8
284    }
285
286    #[classmethod]
287    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
288        EnumIterator::new::<Self>(py)
289    }
290
291    #[classmethod]
292    #[pyo3(name = "from_str")]
293    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
294        let data_str: &str = data.extract()?;
295        let tokenized = data_str.to_uppercase();
296        Self::from_str(&tokenized).map_err(to_pyvalue_err)
297    }
298}
299
300#[pymethods]
301#[pyo3_stub_gen::derive::gen_stub_pymethods]
302impl InstrumentClass {
303    /// The instrument class.
304    #[new]
305    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
306        let t = Self::type_object(py);
307        Self::py_from_str(&t, value)
308    }
309
310    const fn __hash__(&self) -> isize {
311        *self as isize
312    }
313
314    fn __str__(&self) -> String {
315        self.to_string()
316    }
317
318    #[getter]
319    #[must_use]
320    pub fn name(&self) -> String {
321        self.to_string()
322    }
323
324    #[getter]
325    #[must_use]
326    pub fn value(&self) -> u8 {
327        *self as u8
328    }
329
330    #[classmethod]
331    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
332        EnumIterator::new::<Self>(py)
333    }
334
335    #[classmethod]
336    #[pyo3(name = "from_str")]
337    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
338        let data_str: &str = data.extract()?;
339        let tokenized = data_str.to_uppercase();
340        Self::from_str(&tokenized).map_err(to_pyvalue_err)
341    }
342
343    /// Returns whether this instrument class has an expiration.
344    #[pyo3(name = "has_expiration")]
345    #[must_use]
346    pub const fn py_has_expiration(&self) -> bool {
347        self.has_expiration()
348    }
349
350    /// Returns whether this instrument class allows negative prices.
351    ///
352    /// Futures allow negative prices, which occur as real settlement prices (e.g. WTI crude
353    /// oil in April 2020) and in back-adjusted continuous price series. Inverse instruments
354    /// whose notional divides by price still require a positive price.
355    #[pyo3(name = "allows_negative_price")]
356    #[must_use]
357    pub const fn py_allows_negative_price(&self) -> bool {
358        self.allows_negative_price()
359    }
360
361    /// Returns the canonical parent-symbol suffix for this class, if one exists.
362    ///
363    /// Always emits the short form (`FUT`, `OPT`) so that adapters constructing
364    /// parent ids produce a single canonical string per class.
365    #[pyo3(name = "parent_suffix")]
366    #[must_use]
367    pub const fn py_parent_suffix(&self) -> Option<&'static str> {
368        self.parent_suffix()
369    }
370
371    /// Returns the `InstrumentClass` for the parent-symbol suffix, if recognized.
372    ///
373    /// Matches strict uppercase forms only. Both Databento-style abbreviations
374    /// (`FUT`, `OPT`) and long forms (`FUTURE`, `OPTION`) are accepted.
375    #[classmethod]
376    #[pyo3(name = "try_from_parent_suffix")]
377    #[must_use]
378    pub fn py_try_from_parent_suffix(_: &Bound<'_, PyType>, suffix: &str) -> Option<Self> {
379        Self::try_from_parent_suffix(suffix)
380    }
381}
382
383#[pymethods]
384#[pyo3_stub_gen::derive::gen_stub_pymethods]
385impl BarAggregation {
386    /// The aggregation method through which a bar is generated and closed.
387    #[new]
388    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
389        let t = Self::type_object(py);
390        Self::py_from_str(&t, value)
391    }
392
393    const fn __hash__(&self) -> isize {
394        *self as isize
395    }
396
397    fn __str__(&self) -> String {
398        self.to_string()
399    }
400
401    #[getter]
402    #[must_use]
403    pub fn name(&self) -> String {
404        self.to_string()
405    }
406
407    #[getter]
408    #[must_use]
409    pub fn value(&self) -> u8 {
410        *self as u8
411    }
412
413    #[classmethod]
414    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
415        EnumIterator::new::<Self>(py)
416    }
417
418    #[classmethod]
419    #[pyo3(name = "from_str")]
420    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
421        let data_str: &str = data.extract()?;
422        let tokenized = data_str.to_uppercase();
423        Self::from_str(&tokenized).map_err(to_pyvalue_err)
424    }
425}
426
427#[pymethods]
428#[pyo3_stub_gen::derive::gen_stub_pymethods]
429impl BarIntervalType {
430    /// The interval type for bar aggregation.
431    #[new]
432    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
433        let t = Self::type_object(py);
434        Self::py_from_str(&t, value)
435    }
436
437    const fn __hash__(&self) -> isize {
438        *self as isize
439    }
440
441    fn __str__(&self) -> String {
442        self.to_string()
443    }
444
445    #[getter]
446    #[must_use]
447    pub fn name(&self) -> String {
448        self.to_string()
449    }
450
451    #[getter]
452    #[must_use]
453    pub fn value(&self) -> u8 {
454        *self as u8
455    }
456
457    #[classmethod]
458    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
459        EnumIterator::new::<Self>(py)
460    }
461
462    #[classmethod]
463    #[pyo3(name = "from_str")]
464    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
465        let data_str: &str = data.extract()?;
466        let tokenized = data_str.to_uppercase();
467        Self::from_str(&tokenized).map_err(to_pyvalue_err)
468    }
469}
470
471#[pymethods]
472#[pyo3_stub_gen::derive::gen_stub_pymethods]
473impl BetSide {
474    /// Represents the side of a bet in a betting market.
475    #[new]
476    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
477        let t = Self::type_object(py);
478        Self::py_from_str(&t, value)
479    }
480
481    const fn __hash__(&self) -> isize {
482        *self as isize
483    }
484
485    fn __str__(&self) -> String {
486        self.to_string()
487    }
488
489    #[getter]
490    #[must_use]
491    pub fn name(&self) -> String {
492        self.to_string()
493    }
494
495    #[getter]
496    #[must_use]
497    pub fn value(&self) -> u8 {
498        *self as u8
499    }
500
501    #[classmethod]
502    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
503        EnumIterator::new::<Self>(py)
504    }
505
506    #[classmethod]
507    #[pyo3(name = "from_str")]
508    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
509        let data_str: &str = data.extract()?;
510        let tokenized = data_str.to_uppercase();
511        Self::from_str(&tokenized).map_err(to_pyvalue_err)
512    }
513
514    #[classmethod]
515    #[pyo3(name = "from_order_side")]
516    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
517        order_side.into()
518    }
519
520    /// Returns the opposite betting side.
521    #[pyo3(name = "opposite")]
522    fn py_opposite(&self) -> Self {
523        self.opposite()
524    }
525}
526
527#[pymethods]
528#[pyo3_stub_gen::derive::gen_stub_pymethods]
529impl BookAction {
530    /// The type of order book action for an order book event.
531    #[new]
532    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
533        let t = Self::type_object(py);
534        Self::py_from_str(&t, value)
535    }
536
537    const fn __hash__(&self) -> isize {
538        *self as isize
539    }
540
541    fn __str__(&self) -> String {
542        self.to_string()
543    }
544
545    #[getter]
546    #[must_use]
547    pub fn name(&self) -> String {
548        self.to_string()
549    }
550
551    #[getter]
552    #[must_use]
553    pub fn value(&self) -> u8 {
554        *self as u8
555    }
556
557    #[classmethod]
558    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
559        EnumIterator::new::<Self>(py)
560    }
561
562    #[classmethod]
563    #[pyo3(name = "from_str")]
564    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
565        let data_str: &str = data.extract()?;
566        let tokenized = data_str.to_uppercase();
567        Self::from_str(&tokenized).map_err(to_pyvalue_err)
568    }
569}
570
571// The stub macro must run first so it records the compatibility class attribute
572#[pyo3_stub_gen::derive::gen_stub_pymethods]
573#[pymethods]
574impl ContingencyType {
575    /// The order contingency type which specifies the behavior of linked orders.
576    ///
577    /// [FIX 5.0 SP2 : ContingencyType <1385> field](https://www.onixs.biz/fix-dictionary/5.0.sp2/tagnum_1385.html).
578    ///
579    /// Python retains `NO_CONTINGENCY` as a compatibility alias for `None`. The alias is not an enum
580    /// variant and may be removed in a future version.
581    #[new]
582    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
583        let t = Self::type_object(py);
584        Self::py_from_str(&t, value)
585    }
586
587    /// Compatibility alias for the removed `NO_CONTINGENCY` variant.
588    ///
589    /// This alias returns `None` and may be removed in a future version.
590    #[classattr]
591    #[pyo3(name = "NO_CONTINGENCY")]
592    #[allow(clippy::use_self)]
593    const fn py_no_contingency() -> Option<ContingencyType> {
594        None
595    }
596
597    const fn __hash__(&self) -> isize {
598        *self as isize
599    }
600
601    fn __str__(&self) -> String {
602        self.to_string()
603    }
604
605    #[getter]
606    #[must_use]
607    pub fn name(&self) -> String {
608        self.to_string()
609    }
610
611    #[getter]
612    #[must_use]
613    pub fn value(&self) -> u8 {
614        *self as u8
615    }
616
617    #[classmethod]
618    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
619        EnumIterator::new::<Self>(py)
620    }
621
622    #[classmethod]
623    #[pyo3(name = "from_str")]
624    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
625        let data_str: &str = data.extract()?;
626        let tokenized = data_str.to_uppercase();
627        if tokenized == "NO_CONTINGENCY" {
628            Ok(None)
629        } else {
630            Self::from_str(&tokenized).map(Some).map_err(to_pyvalue_err)
631        }
632    }
633}
634
635#[pymethods]
636#[pyo3_stub_gen::derive::gen_stub_pymethods]
637impl ContinuousFutureAdjustmentType {
638    /// The price-adjustment scheme applied when stitching segment contracts into a
639    /// continuous future series.
640    ///
641    /// The direction (backward vs. forward) selects the anchor contract:
642    /// - Backward modes anchor on the most recent contract; prices in older
643    ///   segments are shifted into the latest contract's frame.
644    /// - Forward modes anchor on the first contract; prices in later segments
645    ///   are shifted into the first contract's frame.
646    ///
647    /// The kind (spread vs. ratio) selects how each transition's offset is combined:
648    /// - Spread modes accumulate additive offsets (`post_price - pre_price`).
649    /// - Ratio modes accumulate multiplicative factors (`post_price / pre_price`)
650    ///   and require strictly positive prices.
651    #[new]
652    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
653        let t = Self::type_object(py);
654        Self::py_from_str(&t, value)
655    }
656
657    const fn __hash__(&self) -> isize {
658        *self as isize
659    }
660
661    fn __str__(&self) -> String {
662        self.to_string()
663    }
664
665    #[getter]
666    #[must_use]
667    pub fn name(&self) -> String {
668        self.to_string()
669    }
670
671    #[getter]
672    #[must_use]
673    pub fn value(&self) -> u8 {
674        *self as u8
675    }
676
677    /// Returns whether this mode accumulates multiplicative factors.
678    #[getter(is_ratio)]
679    #[must_use]
680    pub const fn py_is_ratio(&self) -> bool {
681        self.is_ratio()
682    }
683
684    /// Returns whether this mode anchors on the most recent contract.
685    #[getter(is_backward)]
686    #[must_use]
687    pub const fn py_is_backward(&self) -> bool {
688        self.is_backward()
689    }
690
691    #[classmethod]
692    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
693        EnumIterator::new::<Self>(py)
694    }
695
696    #[classmethod]
697    #[pyo3(name = "from_str")]
698    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
699        let data_str: &str = data.extract()?;
700        let tokenized = data_str.to_uppercase();
701        Self::from_str(&tokenized).map_err(to_pyvalue_err)
702    }
703}
704
705#[pymethods]
706#[pyo3_stub_gen::derive::gen_stub_pymethods]
707impl CurrencyType {
708    /// The broad currency type.
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    const fn __hash__(&self) -> isize {
716        *self as isize
717    }
718
719    fn __str__(&self) -> String {
720        self.to_string()
721    }
722
723    #[getter]
724    #[must_use]
725    pub fn name(&self) -> String {
726        self.to_string()
727    }
728
729    #[getter]
730    #[must_use]
731    pub fn value(&self) -> u8 {
732        *self as u8
733    }
734
735    #[classmethod]
736    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
737        EnumIterator::new::<Self>(py)
738    }
739
740    #[classmethod]
741    #[pyo3(name = "from_str")]
742    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
743        let data_str: &str = data.extract()?;
744        let tokenized = data_str.to_uppercase();
745        Self::from_str(&tokenized).map_err(to_pyvalue_err)
746    }
747}
748
749#[pymethods]
750#[pyo3_stub_gen::derive::gen_stub_pymethods]
751impl ExerciseStyle {
752    /// The exercise style of an option, independent of its kind and settlement type.
753    #[new]
754    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
755        let t = Self::type_object(py);
756        Self::py_from_str(&t, value)
757    }
758
759    const fn __hash__(&self) -> isize {
760        *self as isize
761    }
762
763    fn __str__(&self) -> String {
764        self.to_string()
765    }
766
767    #[getter]
768    #[must_use]
769    pub fn name(&self) -> String {
770        self.to_string()
771    }
772
773    #[getter]
774    #[must_use]
775    pub fn value(&self) -> u8 {
776        *self as u8
777    }
778
779    #[classmethod]
780    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
781        EnumIterator::new::<Self>(py)
782    }
783
784    #[classmethod]
785    #[pyo3(name = "from_str")]
786    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
787        let data_str: &str = data.extract()?;
788        let tokenized = data_str.to_uppercase();
789        Self::from_str(&tokenized).map_err(to_pyvalue_err)
790    }
791}
792
793#[pymethods]
794#[pyo3_stub_gen::derive::gen_stub_pymethods]
795impl InstrumentCloseType {
796    /// The type of event for an instrument close.
797    #[new]
798    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
799        let t = Self::type_object(py);
800        Self::py_from_str(&t, value)
801    }
802
803    const fn __hash__(&self) -> isize {
804        *self as isize
805    }
806
807    fn __str__(&self) -> String {
808        self.to_string()
809    }
810
811    #[getter]
812    #[must_use]
813    pub fn name(&self) -> String {
814        self.to_string()
815    }
816
817    #[getter]
818    #[must_use]
819    pub fn value(&self) -> u8 {
820        *self as u8
821    }
822
823    #[classmethod]
824    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
825        EnumIterator::new::<Self>(py)
826    }
827
828    #[classmethod]
829    #[pyo3(name = "from_str")]
830    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
831        let data_str: &str = data.extract()?;
832        let tokenized = data_str.to_uppercase();
833        Self::from_str(&tokenized).map_err(to_pyvalue_err)
834    }
835}
836
837#[pymethods]
838#[pyo3_stub_gen::derive::gen_stub_pymethods]
839impl LiquiditySide {
840    /// The liquidity side for a trade.
841    #[new]
842    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
843        let t = Self::type_object(py);
844        Self::py_from_str(&t, value)
845    }
846
847    const fn __hash__(&self) -> isize {
848        *self as isize
849    }
850
851    fn __str__(&self) -> String {
852        self.to_string()
853    }
854
855    #[getter]
856    #[must_use]
857    pub fn name(&self) -> String {
858        self.to_string()
859    }
860
861    #[getter]
862    #[must_use]
863    pub fn value(&self) -> u8 {
864        *self as u8
865    }
866
867    #[classmethod]
868    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
869        EnumIterator::new::<Self>(py)
870    }
871
872    #[classmethod]
873    #[pyo3(name = "from_str")]
874    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
875        let data_str: &str = data.extract()?;
876        let tokenized = data_str.to_uppercase();
877        Self::from_str(&tokenized).map_err(to_pyvalue_err)
878    }
879}
880
881#[pymethods]
882#[pyo3_stub_gen::derive::gen_stub_pymethods]
883impl MarketStatus {
884    /// The status of an individual market on a trading venue.
885    #[new]
886    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
887        let t = Self::type_object(py);
888        Self::py_from_str(&t, value)
889    }
890
891    const fn __hash__(&self) -> isize {
892        *self as isize
893    }
894
895    fn __str__(&self) -> String {
896        self.to_string()
897    }
898
899    #[getter]
900    #[must_use]
901    pub fn name(&self) -> String {
902        self.to_string()
903    }
904
905    #[getter]
906    #[must_use]
907    pub fn value(&self) -> u8 {
908        *self as u8
909    }
910
911    #[classmethod]
912    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
913        EnumIterator::new::<Self>(py)
914    }
915
916    #[classmethod]
917    #[pyo3(name = "from_str")]
918    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
919        let data_str: &str = data.extract()?;
920        let tokenized = data_str.to_uppercase();
921        Self::from_str(&tokenized).map_err(to_pyvalue_err)
922    }
923}
924
925#[pymethods]
926#[pyo3_stub_gen::derive::gen_stub_pymethods]
927impl MarketStatusAction {
928    /// An action affecting the status of an individual market on a trading venue.
929    #[new]
930    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
931        let t = Self::type_object(py);
932        Self::py_from_str(&t, value)
933    }
934
935    const fn __hash__(&self) -> isize {
936        *self as isize
937    }
938
939    fn __str__(&self) -> String {
940        self.to_string()
941    }
942
943    #[getter]
944    #[must_use]
945    pub fn name(&self) -> String {
946        self.to_string()
947    }
948
949    #[getter]
950    #[must_use]
951    pub fn value(&self) -> u8 {
952        *self as u8
953    }
954
955    #[classmethod]
956    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
957        EnumIterator::new::<Self>(py)
958    }
959
960    #[classmethod]
961    #[pyo3(name = "from_str")]
962    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
963        let data_str: &str = data.extract()?;
964        let tokenized = data_str.to_uppercase();
965        Self::from_str(&tokenized).map_err(to_pyvalue_err)
966    }
967}
968
969#[pymethods]
970#[pyo3_stub_gen::derive::gen_stub_pymethods]
971impl OmsType {
972    /// The order management system (OMS) type for a trading venue or trading strategy.
973    #[new]
974    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
975        let t = Self::type_object(py);
976        Self::py_from_str(&t, value)
977    }
978
979    const fn __hash__(&self) -> isize {
980        *self as isize
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
1013#[pymethods]
1014#[pyo3_stub_gen::derive::gen_stub_pymethods]
1015impl OptionKind {
1016    /// The kind of option contract.
1017    #[new]
1018    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1019        let t = Self::type_object(py);
1020        Self::py_from_str(&t, value)
1021    }
1022
1023    const fn __hash__(&self) -> isize {
1024        *self as isize
1025    }
1026
1027    fn __str__(&self) -> String {
1028        self.to_string()
1029    }
1030
1031    #[getter]
1032    #[must_use]
1033    pub fn name(&self) -> String {
1034        self.to_string()
1035    }
1036
1037    #[getter]
1038    #[must_use]
1039    pub fn value(&self) -> u8 {
1040        *self as u8
1041    }
1042
1043    #[classmethod]
1044    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1045        EnumIterator::new::<Self>(py)
1046    }
1047
1048    #[classmethod]
1049    #[pyo3(name = "from_str")]
1050    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1051        let data_str: &str = data.extract()?;
1052        let tokenized = data_str.to_uppercase();
1053        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1054    }
1055}
1056
1057#[pymethods]
1058#[pyo3_stub_gen::derive::gen_stub_pymethods]
1059impl OptionSideFilter {
1060    /// Selects which option kinds an option chain carries at each strike position.
1061    #[new]
1062    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1063        let t = Self::type_object(py);
1064        Self::py_from_str(&t, value)
1065    }
1066
1067    const fn __hash__(&self) -> isize {
1068        *self as isize
1069    }
1070
1071    fn __str__(&self) -> String {
1072        self.to_string()
1073    }
1074
1075    #[getter]
1076    #[must_use]
1077    pub fn name(&self) -> String {
1078        self.to_string()
1079    }
1080
1081    #[getter]
1082    #[must_use]
1083    pub fn value(&self) -> u8 {
1084        *self as u8
1085    }
1086
1087    #[classmethod]
1088    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1089        EnumIterator::new::<Self>(py)
1090    }
1091
1092    #[classmethod]
1093    #[pyo3(name = "from_str")]
1094    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1095        let data_str: &str = data.extract()?;
1096        let tokenized = data_str.to_uppercase();
1097        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1098    }
1099}
1100
1101#[pymethods]
1102#[pyo3_stub_gen::derive::gen_stub_pymethods]
1103impl GreeksConvention {
1104    /// The numeraire convention for option greeks published by a venue.
1105    ///
1106    /// Crypto option venues commonly publish two parallel greek sets for the same
1107    /// instrument: Black-Scholes greeks in USD, and price-adjusted greeks denominated
1108    /// in the underlying/coin units. Deribit and OKX both expose the distinction;
1109    /// see the OKX reference for the canonical definition:
1110    /// <https://www.okx.com/docs-v5/en/#public-data-websocket-option-market-data>.
1111    ///
1112    /// This is orthogonal to the percent-greeks transformation in the internal
1113    /// `GreeksCalculator`,
1114    /// which rescales the delta/gamma input step rather than the numeraire.
1115    #[new]
1116    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1117        let t = Self::type_object(py);
1118        Self::py_from_str(&t, value)
1119    }
1120
1121    const fn __hash__(&self) -> isize {
1122        *self as isize
1123    }
1124
1125    fn __str__(&self) -> String {
1126        self.to_string()
1127    }
1128
1129    #[getter]
1130    #[must_use]
1131    pub fn name(&self) -> String {
1132        self.to_string()
1133    }
1134
1135    #[getter]
1136    #[must_use]
1137    pub fn value(&self) -> u8 {
1138        *self as u8
1139    }
1140
1141    #[classmethod]
1142    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1143        EnumIterator::new::<Self>(py)
1144    }
1145
1146    #[classmethod]
1147    #[pyo3(name = "from_str")]
1148    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1149        let data_str: &str = data.extract()?;
1150        let tokenized = data_str.to_uppercase();
1151        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1152    }
1153}
1154
1155#[pymethods]
1156#[pyo3_stub_gen::derive::gen_stub_pymethods]
1157impl OtoTriggerMode {
1158    /// Defines when OTO (One-Triggers-Other) child orders are released.
1159    #[new]
1160    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1161        let t = Self::type_object(py);
1162        Self::py_from_str(&t, value)
1163    }
1164
1165    const fn __hash__(&self) -> isize {
1166        *self as isize
1167    }
1168
1169    fn __str__(&self) -> String {
1170        self.to_string()
1171    }
1172
1173    #[getter]
1174    #[must_use]
1175    pub fn name(&self) -> String {
1176        self.to_string()
1177    }
1178
1179    #[getter]
1180    #[must_use]
1181    pub fn value(&self) -> u8 {
1182        *self as u8
1183    }
1184
1185    #[classmethod]
1186    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1187        EnumIterator::new::<Self>(py)
1188    }
1189
1190    #[classmethod]
1191    #[pyo3(name = "from_str")]
1192    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1193        let data_str: &str = data.extract()?;
1194        let tokenized = data_str.to_uppercase();
1195        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1196    }
1197}
1198
1199// The stub macro must run first so it records the compatibility class attribute
1200#[pyo3_stub_gen::derive::gen_stub_pymethods]
1201#[pymethods]
1202impl OrderSide {
1203    /// The order side (BUY or SELL).
1204    ///
1205    /// Python retains `NO_ORDER_SIDE` as a compatibility alias for `None`. The alias is not an enum
1206    /// variant and may be removed in a future version.
1207    #[new]
1208    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1209        let t = Self::type_object(py);
1210        Self::py_from_str(&t, value)
1211    }
1212
1213    /// Compatibility alias for the removed `NO_ORDER_SIDE` variant.
1214    ///
1215    /// This alias returns `None` and may be removed in a future version.
1216    #[classattr]
1217    #[pyo3(name = "NO_ORDER_SIDE")]
1218    #[allow(clippy::use_self)]
1219    const fn py_no_order_side() -> Option<OrderSide> {
1220        None
1221    }
1222
1223    const fn __hash__(&self) -> isize {
1224        *self as isize
1225    }
1226
1227    fn __str__(&self) -> String {
1228        self.to_string()
1229    }
1230
1231    #[getter]
1232    #[must_use]
1233    pub fn name(&self) -> String {
1234        self.to_string()
1235    }
1236
1237    #[getter]
1238    #[must_use]
1239    pub fn value(&self) -> u8 {
1240        *self as u8
1241    }
1242
1243    #[classmethod]
1244    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1245        EnumIterator::new::<Self>(py)
1246    }
1247
1248    #[classmethod]
1249    #[pyo3(name = "from_str")]
1250    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1251        let data_str: &str = data.extract()?;
1252        let tokenized = data_str.to_uppercase();
1253        if tokenized == "NO_ORDER_SIDE" {
1254            Ok(None)
1255        } else {
1256            Self::from_str(&tokenized).map(Some).map_err(to_pyvalue_err)
1257        }
1258    }
1259}
1260
1261#[pymethods]
1262#[pyo3_stub_gen::derive::gen_stub_pymethods]
1263impl OrderStatus {
1264    /// The status for a specific order.
1265    ///
1266    /// An order is considered _open_ for the following status:
1267    ///  - `ACCEPTED`
1268    ///  - `TRIGGERED`
1269    ///  - `PENDING_UPDATE`
1270    ///  - `PENDING_CANCEL`
1271    ///  - `PARTIALLY_FILLED`
1272    ///
1273    /// An order is considered _in-flight_ for the following status:
1274    ///  - `SUBMITTED`
1275    ///  - `PENDING_UPDATE`
1276    ///  - `PENDING_CANCEL`
1277    ///
1278    /// An order is considered _closed_ for the following status:
1279    ///  - `DENIED`
1280    ///  - `REJECTED`
1281    ///  - `CANCELED`
1282    ///  - `EXPIRED`
1283    ///  - `FILLED`
1284    ///  - `VOIDED`
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    const fn __hash__(&self) -> isize {
1292        *self as isize
1293    }
1294
1295    fn __str__(&self) -> String {
1296        self.to_string()
1297    }
1298
1299    #[getter]
1300    #[must_use]
1301    pub fn name(&self) -> String {
1302        self.to_string()
1303    }
1304
1305    #[getter]
1306    #[must_use]
1307    pub fn value(&self) -> u8 {
1308        *self as u8
1309    }
1310
1311    #[classmethod]
1312    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1313        EnumIterator::new::<Self>(py)
1314    }
1315
1316    #[classmethod]
1317    #[pyo3(name = "from_str")]
1318    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1319        let data_str: &str = data.extract()?;
1320        let tokenized = data_str.to_uppercase();
1321        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1322    }
1323}
1324
1325#[pymethods]
1326#[pyo3_stub_gen::derive::gen_stub_pymethods]
1327impl OrderType {
1328    /// The type of order.
1329    #[new]
1330    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1331        let t = Self::type_object(py);
1332        Self::py_from_str(&t, value)
1333    }
1334
1335    const fn __hash__(&self) -> isize {
1336        *self as isize
1337    }
1338
1339    fn __str__(&self) -> String {
1340        self.to_string()
1341    }
1342
1343    #[getter]
1344    #[must_use]
1345    pub fn name(&self) -> String {
1346        self.to_string()
1347    }
1348
1349    #[getter]
1350    #[must_use]
1351    pub fn value(&self) -> u8 {
1352        *self as u8
1353    }
1354
1355    #[classmethod]
1356    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1357        EnumIterator::new::<Self>(py)
1358    }
1359
1360    #[classmethod]
1361    #[pyo3(name = "from_str")]
1362    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1363        let data_str: &str = data.extract()?;
1364        let tokenized = data_str.to_uppercase();
1365        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1366    }
1367}
1368
1369// The stub macro must run first so it records the compatibility class attribute
1370#[pyo3_stub_gen::derive::gen_stub_pymethods]
1371#[pymethods]
1372impl PositionSide {
1373    /// The position side (FLAT, LONG, or SHORT).
1374    ///
1375    /// Python retains `NO_POSITION_SIDE` as a compatibility alias for `None`. The alias is not an enum
1376    /// variant and may be removed in a future version.
1377    #[new]
1378    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1379        let t = Self::type_object(py);
1380        Self::py_from_str(&t, value)
1381    }
1382
1383    /// Compatibility alias for the removed `NO_POSITION_SIDE` variant.
1384    ///
1385    /// This alias returns `None` and may be removed in a future version.
1386    #[classattr]
1387    #[pyo3(name = "NO_POSITION_SIDE")]
1388    #[allow(clippy::use_self)]
1389    const fn py_no_position_side() -> Option<PositionSide> {
1390        None
1391    }
1392
1393    const fn __hash__(&self) -> isize {
1394        *self as isize
1395    }
1396
1397    fn __str__(&self) -> String {
1398        self.to_string()
1399    }
1400
1401    #[getter]
1402    #[must_use]
1403    pub fn name(&self) -> String {
1404        self.to_string()
1405    }
1406
1407    #[getter]
1408    #[must_use]
1409    pub fn value(&self) -> u8 {
1410        *self as u8
1411    }
1412
1413    #[classmethod]
1414    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1415        EnumIterator::new::<Self>(py)
1416    }
1417
1418    #[classmethod]
1419    #[pyo3(name = "from_str")]
1420    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1421        let data_str: &str = data.extract()?;
1422        let tokenized = data_str.to_uppercase();
1423        if tokenized == "NO_POSITION_SIDE" {
1424            Ok(None)
1425        } else {
1426            Self::from_str(&tokenized).map(Some).map_err(to_pyvalue_err)
1427        }
1428    }
1429}
1430
1431#[pymethods]
1432#[pyo3_stub_gen::derive::gen_stub_pymethods]
1433impl PriceType {
1434    /// The type of price for an instrument in a market.
1435    #[new]
1436    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1437        let t = Self::type_object(py);
1438        Self::py_from_str(&t, value)
1439    }
1440
1441    const fn __hash__(&self) -> isize {
1442        *self as isize
1443    }
1444
1445    fn __str__(&self) -> String {
1446        self.to_string()
1447    }
1448
1449    #[getter]
1450    #[must_use]
1451    pub fn name(&self) -> String {
1452        self.to_string()
1453    }
1454
1455    #[getter]
1456    #[must_use]
1457    pub fn value(&self) -> u8 {
1458        *self as u8
1459    }
1460
1461    #[classmethod]
1462    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1463        EnumIterator::new::<Self>(py)
1464    }
1465
1466    #[classmethod]
1467    #[pyo3(name = "from_str")]
1468    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1469        let data_str: &str = data.extract()?;
1470        let tokenized = data_str.to_uppercase();
1471        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1472    }
1473
1474    #[classmethod]
1475    #[pyo3(name = "from_int")]
1476    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1477        Self::from_repr(value as usize)
1478            .ok_or_else(|| to_pyvalue_err(format!("Invalid PriceType value: {value}")))
1479    }
1480}
1481
1482#[pymethods]
1483#[pyo3_stub_gen::derive::gen_stub_pymethods]
1484impl RecordFlag {
1485    /// A record flag bit field, indicating event end and data information.
1486    #[new]
1487    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1488        let t = Self::type_object(py);
1489        Self::py_from_str(&t, value)
1490    }
1491
1492    const fn __hash__(&self) -> isize {
1493        *self as isize
1494    }
1495
1496    fn __str__(&self) -> String {
1497        self.to_string()
1498    }
1499
1500    #[getter]
1501    #[must_use]
1502    pub fn name(&self) -> String {
1503        self.to_string()
1504    }
1505
1506    #[getter]
1507    #[must_use]
1508    pub fn value(&self) -> u8 {
1509        *self as u8
1510    }
1511
1512    #[classmethod]
1513    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1514        EnumIterator::new::<Self>(py)
1515    }
1516
1517    #[classmethod]
1518    #[pyo3(name = "from_str")]
1519    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1520        let data_str: &str = data.extract()?;
1521        let tokenized = data_str.to_uppercase();
1522        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1523    }
1524
1525    /// Checks if the flag matches a given value.
1526    #[pyo3(name = "matches")]
1527    fn py_matches(&self, value: u8) -> bool {
1528        self.matches(value)
1529    }
1530}
1531
1532#[pymethods]
1533#[pyo3_stub_gen::derive::gen_stub_pymethods]
1534impl SettlementType {
1535    /// The contractual settlement of an option, independent of its exercise style.
1536    #[new]
1537    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1538        let t = Self::type_object(py);
1539        Self::py_from_str(&t, value)
1540    }
1541
1542    const fn __hash__(&self) -> isize {
1543        *self as isize
1544    }
1545
1546    fn __str__(&self) -> String {
1547        self.to_string()
1548    }
1549
1550    #[getter]
1551    #[must_use]
1552    pub fn name(&self) -> String {
1553        self.to_string()
1554    }
1555
1556    #[getter]
1557    #[must_use]
1558    pub fn value(&self) -> u8 {
1559        *self as u8
1560    }
1561
1562    #[classmethod]
1563    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1564        EnumIterator::new::<Self>(py)
1565    }
1566
1567    #[classmethod]
1568    #[pyo3(name = "from_str")]
1569    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1570        let data_str: &str = data.extract()?;
1571        let tokenized = data_str.to_uppercase();
1572        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1573    }
1574}
1575
1576#[pymethods]
1577#[pyo3_stub_gen::derive::gen_stub_pymethods]
1578impl TimeInForce {
1579    /// The 'Time in Force' instruction for an order.
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    const fn __hash__(&self) -> isize {
1587        *self as isize
1588    }
1589
1590    fn __str__(&self) -> String {
1591        self.to_string()
1592    }
1593
1594    #[getter]
1595    #[must_use]
1596    pub fn name(&self) -> String {
1597        self.to_string()
1598    }
1599
1600    #[getter]
1601    #[must_use]
1602    pub fn value(&self) -> u8 {
1603        *self as u8
1604    }
1605
1606    #[classmethod]
1607    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1608        EnumIterator::new::<Self>(py)
1609    }
1610
1611    #[classmethod]
1612    #[pyo3(name = "from_str")]
1613    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1614        let data_str: &str = data.extract()?;
1615        let tokenized = data_str.to_uppercase();
1616        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1617    }
1618}
1619
1620// The stub macro must run first so it records the compatibility class attribute
1621#[pyo3_stub_gen::derive::gen_stub_pymethods]
1622#[pymethods]
1623impl TrailingOffsetType {
1624    /// The trailing offset type for an order type which specifies a trailing stop/trigger or limit price.
1625    ///
1626    /// Python retains `NO_TRAILING_OFFSET` as a compatibility alias for `None`. The alias is not an enum
1627    /// variant and may be removed in a future version.
1628    #[new]
1629    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1630        let t = Self::type_object(py);
1631        Self::py_from_str(&t, value)
1632    }
1633
1634    /// Compatibility alias for the removed `NO_TRAILING_OFFSET` variant.
1635    ///
1636    /// This alias returns `None` and may be removed in a future version.
1637    #[classattr]
1638    #[pyo3(name = "NO_TRAILING_OFFSET")]
1639    #[allow(clippy::use_self)]
1640    const fn py_no_trailing_offset() -> Option<TrailingOffsetType> {
1641        None
1642    }
1643
1644    const fn __hash__(&self) -> isize {
1645        *self as isize
1646    }
1647
1648    fn __str__(&self) -> String {
1649        self.to_string()
1650    }
1651
1652    #[getter]
1653    #[must_use]
1654    pub fn name(&self) -> String {
1655        self.to_string()
1656    }
1657
1658    #[getter]
1659    #[must_use]
1660    pub fn value(&self) -> u8 {
1661        *self as u8
1662    }
1663
1664    #[classmethod]
1665    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1666        EnumIterator::new::<Self>(py)
1667    }
1668
1669    #[classmethod]
1670    #[pyo3(name = "from_str")]
1671    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1672        let data_str: &str = data.extract()?;
1673        let tokenized = data_str.to_uppercase();
1674        if tokenized == "NO_TRAILING_OFFSET" {
1675            Ok(None)
1676        } else {
1677            Self::from_str(&tokenized).map(Some).map_err(to_pyvalue_err)
1678        }
1679    }
1680}
1681
1682// The stub macro must run first so it records the compatibility class attribute
1683#[pyo3_stub_gen::derive::gen_stub_pymethods]
1684#[pymethods]
1685impl TriggerType {
1686    /// The trigger type for the stop/trigger price of an order.
1687    ///
1688    /// Python retains `NO_TRIGGER` as a compatibility alias for `None`. The alias is not an enum variant
1689    /// and may be removed in a future version.
1690    #[new]
1691    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1692        let t = Self::type_object(py);
1693        Self::py_from_str(&t, value)
1694    }
1695
1696    /// Compatibility alias for the removed `NO_TRIGGER` variant.
1697    ///
1698    /// This alias returns `None` and may be removed in a future version.
1699    #[classattr]
1700    #[pyo3(name = "NO_TRIGGER")]
1701    #[allow(clippy::use_self)]
1702    const fn py_no_trigger() -> Option<TriggerType> {
1703        None
1704    }
1705
1706    const fn __hash__(&self) -> isize {
1707        *self as isize
1708    }
1709
1710    fn __str__(&self) -> String {
1711        self.to_string()
1712    }
1713
1714    #[getter]
1715    #[must_use]
1716    pub fn name(&self) -> String {
1717        self.to_string()
1718    }
1719
1720    #[getter]
1721    #[must_use]
1722    pub fn value(&self) -> u8 {
1723        *self as u8
1724    }
1725
1726    #[classmethod]
1727    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1728        EnumIterator::new::<Self>(py)
1729    }
1730
1731    #[classmethod]
1732    #[pyo3(name = "from_str")]
1733    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Option<Self>> {
1734        let data_str: &str = data.extract()?;
1735        let tokenized = data_str.to_uppercase();
1736        if tokenized == "NO_TRIGGER" {
1737            Ok(None)
1738        } else {
1739            Self::from_str(&tokenized).map(Some).map_err(to_pyvalue_err)
1740        }
1741    }
1742}
1743
1744#[pymethods]
1745#[pyo3_stub_gen::derive::gen_stub_pymethods]
1746impl BookType {
1747    /// The order book type, representing the type of levels granularity and delta updating heuristics.
1748    #[new]
1749    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1750        let t = Self::type_object(py);
1751        Self::py_from_str(&t, value)
1752    }
1753
1754    const fn __hash__(&self) -> isize {
1755        *self as isize
1756    }
1757
1758    fn __str__(&self) -> String {
1759        self.to_string()
1760    }
1761
1762    #[getter]
1763    #[must_use]
1764    pub fn name(&self) -> String {
1765        self.to_string()
1766    }
1767
1768    #[getter]
1769    #[must_use]
1770    pub fn value(&self) -> u8 {
1771        *self as u8
1772    }
1773
1774    #[classmethod]
1775    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1776        EnumIterator::new::<Self>(py)
1777    }
1778
1779    #[classmethod]
1780    #[pyo3(name = "from_str")]
1781    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1782        let data_str: &str = data.extract()?;
1783        let tokenized = data_str.to_uppercase();
1784        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1785    }
1786}
1787
1788#[pymethods]
1789#[pyo3_stub_gen::derive::gen_stub_pymethods]
1790impl TradingState {
1791    /// The trading state for a node.
1792    #[new]
1793    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1794        let t = Self::type_object(py);
1795        Self::py_from_str(&t, value)
1796    }
1797
1798    const fn __hash__(&self) -> isize {
1799        *self as isize
1800    }
1801
1802    fn __str__(&self) -> String {
1803        self.to_string()
1804    }
1805
1806    #[getter]
1807    #[must_use]
1808    pub fn name(&self) -> String {
1809        self.to_string()
1810    }
1811
1812    #[getter]
1813    #[must_use]
1814    pub fn value(&self) -> u8 {
1815        *self as u8
1816    }
1817
1818    #[classmethod]
1819    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1820        EnumIterator::new::<Self>(py)
1821    }
1822
1823    #[classmethod]
1824    #[pyo3(name = "from_str")]
1825    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1826        let data_str: &str = data.extract()?;
1827        let tokenized = data_str.to_uppercase();
1828        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1829    }
1830}