Skip to main content

nautilus_model/python/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Enumerations for the trading domain model.
17
18use std::str::FromStr;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyTypeInfo, prelude::*, types::PyType};
22
23use crate::{
24    enums::{
25        AccountType, AggregationSource, AggressorSide, AssetClass, BarAggregation, BarIntervalType,
26        BetSide, BookAction, BookType, ContingencyType, ContinuousFutureAdjustmentType,
27        CurrencyType, GreeksConvention, InstrumentClass, InstrumentCloseType, LiquiditySide,
28        MarketStatus, MarketStatusAction, OmsType, OptionKind, OrderSide, OrderStatus, OrderType,
29        OtoTriggerMode, PositionAdjustmentType, PositionSide, PriceType, RecordFlag, TimeInForce,
30        TradingState, TrailingOffsetType, TriggerType,
31    },
32    python::common::EnumIterator,
33};
34
35#[pymethods]
36#[pyo3_stub_gen::derive::gen_stub_pymethods]
37impl AccountType {
38    /// An account type provided by a trading venue or broker.
39    #[new]
40    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
41        let t = Self::type_object(py);
42        Self::py_from_str(&t, value)
43    }
44
45    const fn __hash__(&self) -> isize {
46        *self as isize
47    }
48
49    fn __str__(&self) -> String {
50        self.to_string()
51    }
52
53    #[getter]
54    #[must_use]
55    pub fn name(&self) -> String {
56        self.to_string()
57    }
58
59    #[getter]
60    #[must_use]
61    pub fn value(&self) -> u8 {
62        *self as u8
63    }
64
65    #[classmethod]
66    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
67        EnumIterator::new::<Self>(py)
68    }
69
70    #[classmethod]
71    #[pyo3(name = "from_str")]
72    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
73        let data_str: &str = data.extract()?;
74        let tokenized = data_str.to_uppercase();
75        Self::from_str(&tokenized).map_err(to_pyvalue_err)
76    }
77}
78
79#[pymethods]
80#[pyo3_stub_gen::derive::gen_stub_pymethods]
81impl PositionAdjustmentType {
82    /// The type of position adjustment.
83    #[new]
84    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
85        let t = Self::type_object(py);
86        Self::py_from_str(&t, value)
87    }
88
89    const fn __hash__(&self) -> isize {
90        *self as isize
91    }
92
93    fn __str__(&self) -> String {
94        self.to_string()
95    }
96
97    #[getter]
98    #[must_use]
99    pub fn name(&self) -> String {
100        self.to_string()
101    }
102
103    #[getter]
104    #[must_use]
105    pub fn value(&self) -> u8 {
106        *self as u8
107    }
108
109    #[classmethod]
110    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
111        EnumIterator::new::<Self>(py)
112    }
113
114    #[classmethod]
115    #[pyo3(name = "from_str")]
116    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
117        let data_str: &str = data.extract()?;
118        let tokenized = data_str.to_uppercase();
119        Self::from_str(&tokenized).map_err(to_pyvalue_err)
120    }
121}
122
123#[pymethods]
124#[pyo3_stub_gen::derive::gen_stub_pymethods]
125impl AggregationSource {
126    /// An aggregation source for derived data.
127    #[new]
128    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
129        let t = Self::type_object(py);
130        Self::py_from_str(&t, value)
131    }
132
133    const fn __hash__(&self) -> isize {
134        *self as isize
135    }
136
137    fn __str__(&self) -> String {
138        self.to_string()
139    }
140
141    #[getter]
142    #[must_use]
143    pub fn name(&self) -> String {
144        self.to_string()
145    }
146
147    #[getter]
148    #[must_use]
149    pub fn value(&self) -> u8 {
150        *self as u8
151    }
152
153    #[classmethod]
154    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
155        EnumIterator::new::<Self>(py)
156    }
157
158    #[classmethod]
159    #[pyo3(name = "from_str")]
160    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
161        let data_str: &str = data.extract()?;
162        let tokenized = data_str.to_uppercase();
163        Self::from_str(&tokenized).map_err(to_pyvalue_err)
164    }
165}
166
167#[pymethods]
168#[pyo3_stub_gen::derive::gen_stub_pymethods]
169impl AggressorSide {
170    /// The side for the aggressing order of a trade in a market.
171    #[new]
172    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
173        let t = Self::type_object(py);
174        Self::py_from_str(&t, value)
175    }
176
177    const fn __hash__(&self) -> isize {
178        *self as isize
179    }
180
181    fn __str__(&self) -> String {
182        self.to_string()
183    }
184
185    #[getter]
186    #[must_use]
187    pub fn name(&self) -> String {
188        self.to_string()
189    }
190
191    #[getter]
192    #[must_use]
193    pub fn value(&self) -> u8 {
194        *self as u8
195    }
196
197    #[classmethod]
198    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
199        EnumIterator::new::<Self>(py)
200    }
201
202    #[classmethod]
203    #[pyo3(name = "from_str")]
204    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
205        let data_str: &str = data.extract()?;
206        let tokenized = data_str.to_uppercase();
207        Self::from_str(&tokenized).map_err(to_pyvalue_err)
208    }
209}
210
211#[pymethods]
212#[pyo3_stub_gen::derive::gen_stub_pymethods]
213impl AssetClass {
214    /// A broad financial market asset class.
215    #[new]
216    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
217        let t = Self::type_object(py);
218        Self::py_from_str(&t, value)
219    }
220
221    const fn __hash__(&self) -> isize {
222        *self as isize
223    }
224
225    fn __str__(&self) -> String {
226        self.to_string()
227    }
228
229    #[getter]
230    #[must_use]
231    pub fn name(&self) -> String {
232        self.to_string()
233    }
234
235    #[getter]
236    #[must_use]
237    pub fn value(&self) -> u8 {
238        *self as u8
239    }
240
241    #[classmethod]
242    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
243        EnumIterator::new::<Self>(py)
244    }
245
246    #[classmethod]
247    #[pyo3(name = "from_str")]
248    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
249        let data_str: &str = data.extract()?;
250        let tokenized = data_str.to_uppercase();
251        Self::from_str(&tokenized).map_err(to_pyvalue_err)
252    }
253}
254
255#[pymethods]
256#[pyo3_stub_gen::derive::gen_stub_pymethods]
257impl InstrumentClass {
258    /// The instrument class.
259    #[new]
260    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
261        let t = Self::type_object(py);
262        Self::py_from_str(&t, value)
263    }
264
265    const fn __hash__(&self) -> isize {
266        *self as isize
267    }
268
269    fn __str__(&self) -> String {
270        self.to_string()
271    }
272
273    #[getter]
274    #[must_use]
275    pub fn name(&self) -> String {
276        self.to_string()
277    }
278
279    #[getter]
280    #[must_use]
281    pub fn value(&self) -> u8 {
282        *self as u8
283    }
284
285    #[classmethod]
286    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
287        EnumIterator::new::<Self>(py)
288    }
289
290    #[classmethod]
291    #[pyo3(name = "from_str")]
292    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
293        let data_str: &str = data.extract()?;
294        let tokenized = data_str.to_uppercase();
295        Self::from_str(&tokenized).map_err(to_pyvalue_err)
296    }
297
298    /// Returns whether this instrument class has an expiration.
299    #[pyo3(name = "has_expiration")]
300    #[must_use]
301    pub const fn py_has_expiration(&self) -> bool {
302        self.has_expiration()
303    }
304
305    /// Returns whether this instrument class allows negative prices.
306    #[pyo3(name = "allows_negative_price")]
307    #[must_use]
308    pub const fn py_allows_negative_price(&self) -> bool {
309        self.allows_negative_price()
310    }
311
312    /// Returns the canonical parent-symbol suffix for this class, if one exists.
313    ///
314    /// Always emits the short form (`FUT`, `OPT`) so that adapters constructing
315    /// parent ids produce a single canonical string per class.
316    #[pyo3(name = "parent_suffix")]
317    #[must_use]
318    pub const fn py_parent_suffix(&self) -> Option<&'static str> {
319        self.parent_suffix()
320    }
321
322    /// Returns the `InstrumentClass` for the parent-symbol suffix, if recognised.
323    ///
324    /// Matches strict uppercase forms only. Both Databento-style abbreviations
325    /// (`FUT`, `OPT`) and long forms (`FUTURE`, `OPTION`) are accepted.
326    #[classmethod]
327    #[pyo3(name = "try_from_parent_suffix")]
328    #[must_use]
329    pub fn py_try_from_parent_suffix(_: &Bound<'_, PyType>, suffix: &str) -> Option<Self> {
330        Self::try_from_parent_suffix(suffix)
331    }
332}
333
334#[pymethods]
335#[pyo3_stub_gen::derive::gen_stub_pymethods]
336impl BarAggregation {
337    /// The aggregation method through which a bar is generated and closed.
338    #[new]
339    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
340        let t = Self::type_object(py);
341        Self::py_from_str(&t, value)
342    }
343
344    const fn __hash__(&self) -> isize {
345        *self as isize
346    }
347
348    fn __str__(&self) -> String {
349        self.to_string()
350    }
351
352    #[getter]
353    #[must_use]
354    pub fn name(&self) -> String {
355        self.to_string()
356    }
357
358    #[getter]
359    #[must_use]
360    pub fn value(&self) -> u8 {
361        *self as u8
362    }
363
364    #[classmethod]
365    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
366        EnumIterator::new::<Self>(py)
367    }
368
369    #[classmethod]
370    #[pyo3(name = "from_str")]
371    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
372        let data_str: &str = data.extract()?;
373        let tokenized = data_str.to_uppercase();
374        Self::from_str(&tokenized).map_err(to_pyvalue_err)
375    }
376}
377
378#[pymethods]
379#[pyo3_stub_gen::derive::gen_stub_pymethods]
380impl BarIntervalType {
381    const fn __hash__(&self) -> isize {
382        *self as isize
383    }
384}
385
386#[pymethods]
387#[pyo3_stub_gen::derive::gen_stub_pymethods]
388impl BetSide {
389    /// Represents the side of a bet in a betting market.
390    #[new]
391    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
392        let t = Self::type_object(py);
393        Self::py_from_str(&t, value)
394    }
395
396    const fn __hash__(&self) -> isize {
397        *self as isize
398    }
399
400    fn __str__(&self) -> String {
401        self.to_string()
402    }
403
404    #[getter]
405    #[must_use]
406    pub fn name(&self) -> String {
407        self.to_string()
408    }
409
410    #[getter]
411    #[must_use]
412    pub fn value(&self) -> u8 {
413        *self as u8
414    }
415
416    #[classmethod]
417    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
418        EnumIterator::new::<Self>(py)
419    }
420
421    #[classmethod]
422    #[pyo3(name = "from_str")]
423    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
424        let data_str: &str = data.extract()?;
425        let tokenized = data_str.to_uppercase();
426        Self::from_str(&tokenized).map_err(to_pyvalue_err)
427    }
428
429    #[classmethod]
430    #[pyo3(name = "from_order_side")]
431    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
432        order_side.into()
433    }
434
435    /// Returns the opposite betting side.
436    #[pyo3(name = "opposite")]
437    fn py_opposite(&self) -> Self {
438        self.opposite()
439    }
440}
441
442#[pymethods]
443#[pyo3_stub_gen::derive::gen_stub_pymethods]
444impl BookAction {
445    /// The type of order book action for an order book event.
446    #[new]
447    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
448        let t = Self::type_object(py);
449        Self::py_from_str(&t, value)
450    }
451
452    const fn __hash__(&self) -> isize {
453        *self as isize
454    }
455
456    fn __str__(&self) -> String {
457        self.to_string()
458    }
459
460    #[getter]
461    #[must_use]
462    pub fn name(&self) -> String {
463        self.to_string()
464    }
465
466    #[getter]
467    #[must_use]
468    pub fn value(&self) -> u8 {
469        *self as u8
470    }
471
472    #[classmethod]
473    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
474        EnumIterator::new::<Self>(py)
475    }
476
477    #[classmethod]
478    #[pyo3(name = "from_str")]
479    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
480        let data_str: &str = data.extract()?;
481        let tokenized = data_str.to_uppercase();
482        Self::from_str(&tokenized).map_err(to_pyvalue_err)
483    }
484}
485
486#[pymethods]
487#[pyo3_stub_gen::derive::gen_stub_pymethods]
488impl ContingencyType {
489    /// The order contingency type which specifies the behavior of linked orders.
490    ///
491    /// [FIX 5.0 SP2 : ContingencyType <1385> field](https://www.onixs.biz/fix-dictionary/5.0.sp2/tagnum_1385.html).
492    #[new]
493    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
494        let t = Self::type_object(py);
495        Self::py_from_str(&t, value)
496    }
497
498    const fn __hash__(&self) -> isize {
499        *self as isize
500    }
501
502    fn __str__(&self) -> String {
503        self.to_string()
504    }
505
506    #[getter]
507    #[must_use]
508    pub fn name(&self) -> String {
509        self.to_string()
510    }
511
512    #[getter]
513    #[must_use]
514    pub fn value(&self) -> u8 {
515        *self as u8
516    }
517
518    #[classmethod]
519    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
520        EnumIterator::new::<Self>(py)
521    }
522
523    #[classmethod]
524    #[pyo3(name = "from_str")]
525    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
526        let data_str: &str = data.extract()?;
527        let tokenized = data_str.to_uppercase();
528        Self::from_str(&tokenized).map_err(to_pyvalue_err)
529    }
530}
531
532#[pymethods]
533#[pyo3_stub_gen::derive::gen_stub_pymethods]
534impl ContinuousFutureAdjustmentType {
535    /// The price-adjustment scheme applied when stitching segment contracts into a
536    /// continuous future series.
537    ///
538    /// The direction (backward vs. forward) selects the anchor contract:
539    /// - Backward modes anchor on the most recent contract; prices in older
540    ///   segments are shifted into the latest contract's frame.
541    /// - Forward modes anchor on the first contract; prices in later segments
542    ///   are shifted into the first contract's frame.
543    ///
544    /// The kind (spread vs. ratio) selects how each transition's offset is combined:
545    /// - Spread modes accumulate additive offsets (`post_price - pre_price`).
546    /// - Ratio modes accumulate multiplicative factors (`post_price / pre_price`)
547    ///   and require strictly positive prices.
548    #[new]
549    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
550        let t = Self::type_object(py);
551        Self::py_from_str(&t, value)
552    }
553
554    const fn __hash__(&self) -> isize {
555        *self as isize
556    }
557
558    fn __str__(&self) -> String {
559        self.to_string()
560    }
561
562    #[getter]
563    #[must_use]
564    pub fn name(&self) -> String {
565        self.to_string()
566    }
567
568    #[getter]
569    #[must_use]
570    pub fn value(&self) -> u8 {
571        *self as u8
572    }
573
574    /// Returns whether this mode accumulates multiplicative factors.
575    #[getter(is_ratio)]
576    #[must_use]
577    pub const fn py_is_ratio(&self) -> bool {
578        self.is_ratio()
579    }
580
581    /// Returns whether this mode anchors on the most recent contract.
582    #[getter(is_backward)]
583    #[must_use]
584    pub const fn py_is_backward(&self) -> bool {
585        self.is_backward()
586    }
587
588    #[classmethod]
589    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
590        EnumIterator::new::<Self>(py)
591    }
592
593    #[classmethod]
594    #[pyo3(name = "from_str")]
595    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
596        let data_str: &str = data.extract()?;
597        let tokenized = data_str.to_uppercase();
598        Self::from_str(&tokenized).map_err(to_pyvalue_err)
599    }
600}
601
602#[pymethods]
603#[pyo3_stub_gen::derive::gen_stub_pymethods]
604impl CurrencyType {
605    /// The broad currency type.
606    #[new]
607    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
608        let t = Self::type_object(py);
609        Self::py_from_str(&t, value)
610    }
611
612    const fn __hash__(&self) -> isize {
613        *self as isize
614    }
615
616    fn __str__(&self) -> String {
617        self.to_string()
618    }
619
620    #[getter]
621    #[must_use]
622    pub fn name(&self) -> String {
623        self.to_string()
624    }
625
626    #[getter]
627    #[must_use]
628    pub fn value(&self) -> u8 {
629        *self as u8
630    }
631
632    #[classmethod]
633    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
634        EnumIterator::new::<Self>(py)
635    }
636
637    #[classmethod]
638    #[pyo3(name = "from_str")]
639    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
640        let data_str: &str = data.extract()?;
641        let tokenized = data_str.to_uppercase();
642        Self::from_str(&tokenized).map_err(to_pyvalue_err)
643    }
644}
645
646#[pymethods]
647#[pyo3_stub_gen::derive::gen_stub_pymethods]
648impl InstrumentCloseType {
649    /// The type of event for an instrument close.
650    #[new]
651    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
652        let t = Self::type_object(py);
653        Self::py_from_str(&t, value)
654    }
655
656    const fn __hash__(&self) -> isize {
657        *self as isize
658    }
659
660    fn __str__(&self) -> String {
661        self.to_string()
662    }
663
664    #[getter]
665    #[must_use]
666    pub fn name(&self) -> String {
667        self.to_string()
668    }
669
670    #[getter]
671    #[must_use]
672    pub fn value(&self) -> u8 {
673        *self as u8
674    }
675
676    #[classmethod]
677    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
678        EnumIterator::new::<Self>(py)
679    }
680
681    #[classmethod]
682    #[pyo3(name = "from_str")]
683    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
684        let data_str: &str = data.extract()?;
685        let tokenized = data_str.to_uppercase();
686        Self::from_str(&tokenized).map_err(to_pyvalue_err)
687    }
688}
689
690#[pymethods]
691#[pyo3_stub_gen::derive::gen_stub_pymethods]
692impl LiquiditySide {
693    /// The liquidity side for a trade.
694    #[new]
695    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
696        let t = Self::type_object(py);
697        Self::py_from_str(&t, value)
698    }
699
700    const fn __hash__(&self) -> isize {
701        *self as isize
702    }
703
704    fn __str__(&self) -> String {
705        self.to_string()
706    }
707
708    #[getter]
709    #[must_use]
710    pub fn name(&self) -> String {
711        self.to_string()
712    }
713
714    #[getter]
715    #[must_use]
716    pub fn value(&self) -> u8 {
717        *self as u8
718    }
719
720    #[classmethod]
721    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
722        EnumIterator::new::<Self>(py)
723    }
724
725    #[classmethod]
726    #[pyo3(name = "from_str")]
727    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
728        let data_str: &str = data.extract()?;
729        let tokenized = data_str.to_uppercase();
730        Self::from_str(&tokenized).map_err(to_pyvalue_err)
731    }
732}
733
734#[pymethods]
735#[pyo3_stub_gen::derive::gen_stub_pymethods]
736impl MarketStatus {
737    /// The status of an individual market on a trading venue.
738    #[new]
739    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
740        let t = Self::type_object(py);
741        Self::py_from_str(&t, value)
742    }
743
744    const fn __hash__(&self) -> isize {
745        *self as isize
746    }
747
748    fn __str__(&self) -> String {
749        self.to_string()
750    }
751
752    #[getter]
753    #[must_use]
754    pub fn name(&self) -> String {
755        self.to_string()
756    }
757
758    #[getter]
759    #[must_use]
760    pub fn value(&self) -> u8 {
761        *self as u8
762    }
763
764    #[classmethod]
765    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
766        EnumIterator::new::<Self>(py)
767    }
768
769    #[classmethod]
770    #[pyo3(name = "from_str")]
771    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
772        let data_str: &str = data.extract()?;
773        let tokenized = data_str.to_uppercase();
774        Self::from_str(&tokenized).map_err(to_pyvalue_err)
775    }
776}
777
778#[pymethods]
779#[pyo3_stub_gen::derive::gen_stub_pymethods]
780impl MarketStatusAction {
781    /// An action affecting the status of an individual market on a trading venue.
782    #[new]
783    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
784        let t = Self::type_object(py);
785        Self::py_from_str(&t, value)
786    }
787
788    const fn __hash__(&self) -> isize {
789        *self as isize
790    }
791
792    fn __str__(&self) -> String {
793        self.to_string()
794    }
795
796    #[getter]
797    #[must_use]
798    pub fn name(&self) -> String {
799        self.to_string()
800    }
801
802    #[getter]
803    #[must_use]
804    pub fn value(&self) -> u8 {
805        *self as u8
806    }
807
808    #[classmethod]
809    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
810        EnumIterator::new::<Self>(py)
811    }
812
813    #[classmethod]
814    #[pyo3(name = "from_str")]
815    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
816        let data_str: &str = data.extract()?;
817        let tokenized = data_str.to_uppercase();
818        Self::from_str(&tokenized).map_err(to_pyvalue_err)
819    }
820}
821
822#[pymethods]
823#[pyo3_stub_gen::derive::gen_stub_pymethods]
824impl OmsType {
825    /// The order management system (OMS) type for a trading venue or trading strategy.
826    #[new]
827    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
828        let t = Self::type_object(py);
829        Self::py_from_str(&t, value)
830    }
831
832    const fn __hash__(&self) -> isize {
833        *self as isize
834    }
835
836    fn __str__(&self) -> String {
837        self.to_string()
838    }
839
840    #[getter]
841    #[must_use]
842    pub fn name(&self) -> String {
843        self.to_string()
844    }
845
846    #[getter]
847    #[must_use]
848    pub fn value(&self) -> u8 {
849        *self as u8
850    }
851
852    #[classmethod]
853    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
854        EnumIterator::new::<Self>(py)
855    }
856
857    #[classmethod]
858    #[pyo3(name = "from_str")]
859    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
860        let data_str: &str = data.extract()?;
861        let tokenized = data_str.to_uppercase();
862        Self::from_str(&tokenized).map_err(to_pyvalue_err)
863    }
864}
865
866#[pymethods]
867#[pyo3_stub_gen::derive::gen_stub_pymethods]
868impl OptionKind {
869    /// The kind of option contract.
870    #[new]
871    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
872        let t = Self::type_object(py);
873        Self::py_from_str(&t, value)
874    }
875
876    const fn __hash__(&self) -> isize {
877        *self as isize
878    }
879
880    fn __str__(&self) -> String {
881        self.to_string()
882    }
883
884    #[getter]
885    #[must_use]
886    pub fn name(&self) -> String {
887        self.to_string()
888    }
889
890    #[getter]
891    #[must_use]
892    pub fn value(&self) -> u8 {
893        *self as u8
894    }
895
896    #[classmethod]
897    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
898        EnumIterator::new::<Self>(py)
899    }
900
901    #[classmethod]
902    #[pyo3(name = "from_str")]
903    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
904        let data_str: &str = data.extract()?;
905        let tokenized = data_str.to_uppercase();
906        Self::from_str(&tokenized).map_err(to_pyvalue_err)
907    }
908}
909
910#[pymethods]
911#[pyo3_stub_gen::derive::gen_stub_pymethods]
912impl GreeksConvention {
913    /// The numeraire convention for option greeks published by a venue.
914    ///
915    /// Crypto option venues commonly publish two parallel greek sets for the same
916    /// instrument: Black-Scholes greeks in USD, and price-adjusted greeks denominated
917    /// in the underlying/coin units. Deribit and OKX both expose the distinction;
918    /// see the OKX reference for the canonical definition:
919    /// <https://www.okx.com/docs-v5/en/#public-data-websocket-option-market-data>.
920    ///
921    /// This is orthogonal to the percent-greeks transformation in the internal
922    /// `GreeksCalculator`,
923    /// which rescales the delta/gamma input step rather than the numeraire.
924    #[new]
925    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
926        let t = Self::type_object(py);
927        Self::py_from_str(&t, value)
928    }
929
930    const fn __hash__(&self) -> isize {
931        *self as isize
932    }
933
934    fn __str__(&self) -> String {
935        self.to_string()
936    }
937
938    #[getter]
939    #[must_use]
940    pub fn name(&self) -> String {
941        self.to_string()
942    }
943
944    #[getter]
945    #[must_use]
946    pub fn value(&self) -> u8 {
947        *self as u8
948    }
949
950    #[classmethod]
951    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
952        EnumIterator::new::<Self>(py)
953    }
954
955    #[classmethod]
956    #[pyo3(name = "from_str")]
957    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
958        let data_str: &str = data.extract()?;
959        let tokenized = data_str.to_uppercase();
960        Self::from_str(&tokenized).map_err(to_pyvalue_err)
961    }
962}
963
964#[pymethods]
965#[pyo3_stub_gen::derive::gen_stub_pymethods]
966impl OtoTriggerMode {
967    /// Defines when OTO (One-Triggers-Other) child orders are released.
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    const fn __hash__(&self) -> isize {
975        *self as isize
976    }
977
978    fn __str__(&self) -> String {
979        self.to_string()
980    }
981
982    #[getter]
983    #[must_use]
984    pub fn name(&self) -> String {
985        self.to_string()
986    }
987
988    #[getter]
989    #[must_use]
990    pub fn value(&self) -> u8 {
991        *self as u8
992    }
993
994    #[classmethod]
995    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
996        EnumIterator::new::<Self>(py)
997    }
998
999    #[classmethod]
1000    #[pyo3(name = "from_str")]
1001    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1002        let data_str: &str = data.extract()?;
1003        let tokenized = data_str.to_uppercase();
1004        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1005    }
1006}
1007
1008#[pymethods]
1009#[pyo3_stub_gen::derive::gen_stub_pymethods]
1010impl OrderSide {
1011    /// The order side for a specific order, or action related to orders.
1012    #[new]
1013    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1014        let t = Self::type_object(py);
1015        Self::py_from_str(&t, value)
1016    }
1017
1018    const fn __hash__(&self) -> isize {
1019        *self as isize
1020    }
1021
1022    fn __str__(&self) -> String {
1023        self.to_string()
1024    }
1025
1026    #[getter]
1027    #[must_use]
1028    pub fn name(&self) -> String {
1029        self.to_string()
1030    }
1031
1032    #[getter]
1033    #[must_use]
1034    pub fn value(&self) -> u8 {
1035        *self as u8
1036    }
1037
1038    #[classmethod]
1039    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1040        EnumIterator::new::<Self>(py)
1041    }
1042
1043    #[classmethod]
1044    #[pyo3(name = "from_str")]
1045    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1046        let data_str: &str = data.extract()?;
1047        let tokenized = data_str.to_uppercase();
1048        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1049    }
1050}
1051
1052#[pymethods]
1053#[pyo3_stub_gen::derive::gen_stub_pymethods]
1054impl OrderStatus {
1055    /// The status for a specific order.
1056    ///
1057    /// An order is considered _open_ for the following status:
1058    ///  - `ACCEPTED`
1059    ///  - `TRIGGERED`
1060    ///  - `PENDING_UPDATE`
1061    ///  - `PENDING_CANCEL`
1062    ///  - `PARTIALLY_FILLED`
1063    ///
1064    /// An order is considered _in-flight_ for the following status:
1065    ///  - `SUBMITTED`
1066    ///  - `PENDING_UPDATE`
1067    ///  - `PENDING_CANCEL`
1068    ///
1069    /// An order is considered _closed_ for the following status:
1070    ///  - `DENIED`
1071    ///  - `REJECTED`
1072    ///  - `CANCELED`
1073    ///  - `EXPIRED`
1074    ///  - `FILLED`
1075    #[new]
1076    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1077        let t = Self::type_object(py);
1078        Self::py_from_str(&t, value)
1079    }
1080
1081    const fn __hash__(&self) -> isize {
1082        *self as isize
1083    }
1084
1085    fn __str__(&self) -> String {
1086        self.to_string()
1087    }
1088
1089    #[getter]
1090    #[must_use]
1091    pub fn name(&self) -> String {
1092        self.to_string()
1093    }
1094
1095    #[getter]
1096    #[must_use]
1097    pub fn value(&self) -> u8 {
1098        *self as u8
1099    }
1100
1101    #[classmethod]
1102    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1103        EnumIterator::new::<Self>(py)
1104    }
1105
1106    #[classmethod]
1107    #[pyo3(name = "from_str")]
1108    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1109        let data_str: &str = data.extract()?;
1110        let tokenized = data_str.to_uppercase();
1111        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1112    }
1113}
1114
1115#[pymethods]
1116#[pyo3_stub_gen::derive::gen_stub_pymethods]
1117impl OrderType {
1118    /// The type of order.
1119    #[new]
1120    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1121        let t = Self::type_object(py);
1122        Self::py_from_str(&t, value)
1123    }
1124
1125    const fn __hash__(&self) -> isize {
1126        *self as isize
1127    }
1128
1129    fn __str__(&self) -> String {
1130        self.to_string()
1131    }
1132
1133    #[getter]
1134    #[must_use]
1135    pub fn name(&self) -> String {
1136        self.to_string()
1137    }
1138
1139    #[getter]
1140    #[must_use]
1141    pub fn value(&self) -> u8 {
1142        *self as u8
1143    }
1144
1145    #[classmethod]
1146    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1147        EnumIterator::new::<Self>(py)
1148    }
1149
1150    #[classmethod]
1151    #[pyo3(name = "from_str")]
1152    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1153        let data_str: &str = data.extract()?;
1154        let tokenized = data_str.to_uppercase();
1155        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1156    }
1157}
1158
1159#[pymethods]
1160#[pyo3_stub_gen::derive::gen_stub_pymethods]
1161impl PositionSide {
1162    /// The market side for a specific position, or action related to positions.
1163    #[new]
1164    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1165        let t = Self::type_object(py);
1166        Self::py_from_str(&t, value)
1167    }
1168
1169    const fn __hash__(&self) -> isize {
1170        *self as isize
1171    }
1172
1173    fn __str__(&self) -> String {
1174        self.to_string()
1175    }
1176
1177    #[getter]
1178    #[must_use]
1179    pub fn name(&self) -> String {
1180        self.to_string()
1181    }
1182
1183    #[getter]
1184    #[must_use]
1185    pub fn value(&self) -> u8 {
1186        *self as u8
1187    }
1188
1189    #[classmethod]
1190    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1191        EnumIterator::new::<Self>(py)
1192    }
1193
1194    #[classmethod]
1195    #[pyo3(name = "from_str")]
1196    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1197        let data_str: &str = data.extract()?;
1198        let tokenized = data_str.to_uppercase();
1199        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1200    }
1201}
1202
1203#[pymethods]
1204#[pyo3_stub_gen::derive::gen_stub_pymethods]
1205impl PriceType {
1206    /// The type of price for an instrument in a market.
1207    #[new]
1208    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1209        let t = Self::type_object(py);
1210        Self::py_from_str(&t, value)
1211    }
1212
1213    const fn __hash__(&self) -> isize {
1214        *self as isize
1215    }
1216
1217    fn __str__(&self) -> String {
1218        self.to_string()
1219    }
1220
1221    #[getter]
1222    #[must_use]
1223    pub fn name(&self) -> String {
1224        self.to_string()
1225    }
1226
1227    #[getter]
1228    #[must_use]
1229    pub fn value(&self) -> u8 {
1230        *self as u8
1231    }
1232
1233    #[classmethod]
1234    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1235        EnumIterator::new::<Self>(py)
1236    }
1237
1238    #[classmethod]
1239    #[pyo3(name = "from_str")]
1240    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1241        let data_str: &str = data.extract()?;
1242        let tokenized = data_str.to_uppercase();
1243        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1244    }
1245
1246    #[classmethod]
1247    #[pyo3(name = "from_int")]
1248    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1249        Self::from_repr(value as usize)
1250            .ok_or_else(|| to_pyvalue_err(format!("Invalid PriceType value: {value}")))
1251    }
1252}
1253
1254#[pymethods]
1255#[pyo3_stub_gen::derive::gen_stub_pymethods]
1256impl RecordFlag {
1257    /// A record flag bit field, indicating event end and data information.
1258    #[new]
1259    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1260        let t = Self::type_object(py);
1261        Self::py_from_str(&t, value)
1262    }
1263
1264    const fn __hash__(&self) -> isize {
1265        *self as isize
1266    }
1267
1268    fn __str__(&self) -> String {
1269        self.to_string()
1270    }
1271
1272    #[getter]
1273    #[must_use]
1274    pub fn name(&self) -> String {
1275        self.to_string()
1276    }
1277
1278    #[getter]
1279    #[must_use]
1280    pub fn value(&self) -> u8 {
1281        *self as u8
1282    }
1283
1284    #[classmethod]
1285    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1286        EnumIterator::new::<Self>(py)
1287    }
1288
1289    #[classmethod]
1290    #[pyo3(name = "from_str")]
1291    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1292        let data_str: &str = data.extract()?;
1293        let tokenized = data_str.to_uppercase();
1294        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1295    }
1296
1297    /// Checks if the flag matches a given value.
1298    #[pyo3(name = "matches")]
1299    fn py_matches(&self, value: u8) -> bool {
1300        self.matches(value)
1301    }
1302}
1303
1304#[pymethods]
1305#[pyo3_stub_gen::derive::gen_stub_pymethods]
1306impl TimeInForce {
1307    /// The 'Time in Force' instruction for an order.
1308    #[new]
1309    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1310        let t = Self::type_object(py);
1311        Self::py_from_str(&t, value)
1312    }
1313
1314    const fn __hash__(&self) -> isize {
1315        *self as isize
1316    }
1317
1318    fn __str__(&self) -> String {
1319        self.to_string()
1320    }
1321
1322    #[getter]
1323    #[must_use]
1324    pub fn name(&self) -> String {
1325        self.to_string()
1326    }
1327
1328    #[getter]
1329    #[must_use]
1330    pub fn value(&self) -> u8 {
1331        *self as u8
1332    }
1333
1334    #[classmethod]
1335    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1336        EnumIterator::new::<Self>(py)
1337    }
1338
1339    #[classmethod]
1340    #[pyo3(name = "from_str")]
1341    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1342        let data_str: &str = data.extract()?;
1343        let tokenized = data_str.to_uppercase();
1344        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1345    }
1346}
1347
1348#[pymethods]
1349#[pyo3_stub_gen::derive::gen_stub_pymethods]
1350impl TrailingOffsetType {
1351    /// The trailing offset type for an order type which specifies a trailing stop/trigger or limit price.
1352    #[new]
1353    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1354        let t = Self::type_object(py);
1355        Self::py_from_str(&t, value)
1356    }
1357
1358    const fn __hash__(&self) -> isize {
1359        *self as isize
1360    }
1361
1362    fn __str__(&self) -> String {
1363        self.to_string()
1364    }
1365
1366    #[getter]
1367    #[must_use]
1368    pub fn name(&self) -> String {
1369        self.to_string()
1370    }
1371
1372    #[getter]
1373    #[must_use]
1374    pub fn value(&self) -> u8 {
1375        *self as u8
1376    }
1377
1378    #[classmethod]
1379    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1380        EnumIterator::new::<Self>(py)
1381    }
1382
1383    #[classmethod]
1384    #[pyo3(name = "from_str")]
1385    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1386        let data_str: &str = data.extract()?;
1387        let tokenized = data_str.to_uppercase();
1388        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1389    }
1390}
1391
1392#[pymethods]
1393#[pyo3_stub_gen::derive::gen_stub_pymethods]
1394impl TriggerType {
1395    /// The trigger type for the stop/trigger price of an order.
1396    #[new]
1397    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1398        let t = Self::type_object(py);
1399        Self::py_from_str(&t, value)
1400    }
1401
1402    const fn __hash__(&self) -> isize {
1403        *self as isize
1404    }
1405
1406    fn __str__(&self) -> String {
1407        self.to_string()
1408    }
1409
1410    #[getter]
1411    #[must_use]
1412    pub fn name(&self) -> String {
1413        self.to_string()
1414    }
1415
1416    #[getter]
1417    #[must_use]
1418    pub fn value(&self) -> u8 {
1419        *self as u8
1420    }
1421
1422    #[classmethod]
1423    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1424        EnumIterator::new::<Self>(py)
1425    }
1426
1427    #[classmethod]
1428    #[pyo3(name = "from_str")]
1429    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1430        let data_str: &str = data.extract()?;
1431        let tokenized = data_str.to_uppercase();
1432        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1433    }
1434}
1435
1436#[pymethods]
1437#[pyo3_stub_gen::derive::gen_stub_pymethods]
1438impl BookType {
1439    /// The order book type, representing the type of levels granularity and delta updating heuristics.
1440    #[new]
1441    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1442        let t = Self::type_object(py);
1443        Self::py_from_str(&t, value)
1444    }
1445
1446    const fn __hash__(&self) -> isize {
1447        *self as isize
1448    }
1449
1450    fn __str__(&self) -> String {
1451        self.to_string()
1452    }
1453
1454    #[getter]
1455    #[must_use]
1456    pub fn name(&self) -> String {
1457        self.to_string()
1458    }
1459
1460    #[getter]
1461    #[must_use]
1462    pub fn value(&self) -> u8 {
1463        *self as u8
1464    }
1465
1466    #[classmethod]
1467    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1468        EnumIterator::new::<Self>(py)
1469    }
1470
1471    #[classmethod]
1472    #[pyo3(name = "from_str")]
1473    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1474        let data_str: &str = data.extract()?;
1475        let tokenized = data_str.to_uppercase();
1476        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1477    }
1478}
1479
1480#[pymethods]
1481#[pyo3_stub_gen::derive::gen_stub_pymethods]
1482impl TradingState {
1483    /// The trading state for a node.
1484    #[new]
1485    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1486        let t = Self::type_object(py);
1487        Self::py_from_str(&t, value)
1488    }
1489
1490    const fn __hash__(&self) -> isize {
1491        *self as isize
1492    }
1493
1494    fn __str__(&self) -> String {
1495        self.to_string()
1496    }
1497
1498    #[getter]
1499    #[must_use]
1500    pub fn name(&self) -> String {
1501        self.to_string()
1502    }
1503
1504    #[getter]
1505    #[must_use]
1506    pub fn value(&self) -> u8 {
1507        *self as u8
1508    }
1509
1510    #[classmethod]
1511    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1512        EnumIterator::new::<Self>(py)
1513    }
1514
1515    #[classmethod]
1516    #[pyo3(name = "from_str")]
1517    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1518        let data_str: &str = data.extract()?;
1519        let tokenized = data_str.to_uppercase();
1520        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1521    }
1522}