Skip to main content

nautilus_model/python/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Enumerations for the trading domain model.
17
18use std::str::FromStr;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyTypeInfo, prelude::*, types::PyType};
22
23use crate::{
24    enums::{
25        AccountType, AggregationSource, AggressorSide, AssetClass, BarAggregation, BarIntervalType,
26        BetSide, BookAction, BookType, ContingencyType, CurrencyType, GreeksConvention,
27        InstrumentClass, InstrumentCloseType, LiquiditySide, MarketStatus, MarketStatusAction,
28        OmsType, OptionKind, OrderSide, OrderStatus, OrderType, OtoTriggerMode,
29        PositionAdjustmentType, PositionSide, PriceType, RecordFlag, TimeInForce, TradingState,
30        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
299#[pymethods]
300#[pyo3_stub_gen::derive::gen_stub_pymethods]
301impl BarAggregation {
302    /// The aggregation method through which a bar is generated and closed.
303    #[new]
304    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
305        let t = Self::type_object(py);
306        Self::py_from_str(&t, value)
307    }
308
309    const fn __hash__(&self) -> isize {
310        *self as isize
311    }
312
313    fn __str__(&self) -> String {
314        self.to_string()
315    }
316
317    #[getter]
318    #[must_use]
319    pub fn name(&self) -> String {
320        self.to_string()
321    }
322
323    #[getter]
324    #[must_use]
325    pub fn value(&self) -> u8 {
326        *self as u8
327    }
328
329    #[classmethod]
330    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
331        EnumIterator::new::<Self>(py)
332    }
333
334    #[classmethod]
335    #[pyo3(name = "from_str")]
336    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
337        let data_str: &str = data.extract()?;
338        let tokenized = data_str.to_uppercase();
339        Self::from_str(&tokenized).map_err(to_pyvalue_err)
340    }
341}
342
343#[pymethods]
344#[pyo3_stub_gen::derive::gen_stub_pymethods]
345impl BarIntervalType {
346    const fn __hash__(&self) -> isize {
347        *self as isize
348    }
349}
350
351#[pymethods]
352#[pyo3_stub_gen::derive::gen_stub_pymethods]
353impl BetSide {
354    /// Represents the side of a bet in a betting market.
355    #[new]
356    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
357        let t = Self::type_object(py);
358        Self::py_from_str(&t, value)
359    }
360
361    const fn __hash__(&self) -> isize {
362        *self as isize
363    }
364
365    fn __str__(&self) -> String {
366        self.to_string()
367    }
368
369    #[getter]
370    #[must_use]
371    pub fn name(&self) -> String {
372        self.to_string()
373    }
374
375    #[getter]
376    #[must_use]
377    pub fn value(&self) -> u8 {
378        *self as u8
379    }
380
381    #[classmethod]
382    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
383        EnumIterator::new::<Self>(py)
384    }
385
386    #[classmethod]
387    #[pyo3(name = "from_str")]
388    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
389        let data_str: &str = data.extract()?;
390        let tokenized = data_str.to_uppercase();
391        Self::from_str(&tokenized).map_err(to_pyvalue_err)
392    }
393
394    #[classmethod]
395    #[pyo3(name = "from_order_side")]
396    fn py_from_order_side(_: &Bound<'_, PyType>, order_side: OrderSide) -> Self {
397        order_side.into()
398    }
399
400    /// Returns the opposite betting side.
401    #[pyo3(name = "opposite")]
402    fn py_opposite(&self) -> Self {
403        self.opposite()
404    }
405}
406
407#[pymethods]
408#[pyo3_stub_gen::derive::gen_stub_pymethods]
409impl BookAction {
410    /// The type of order book action for an order book event.
411    #[new]
412    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
413        let t = Self::type_object(py);
414        Self::py_from_str(&t, value)
415    }
416
417    const fn __hash__(&self) -> isize {
418        *self as isize
419    }
420
421    fn __str__(&self) -> String {
422        self.to_string()
423    }
424
425    #[getter]
426    #[must_use]
427    pub fn name(&self) -> String {
428        self.to_string()
429    }
430
431    #[getter]
432    #[must_use]
433    pub fn value(&self) -> u8 {
434        *self as u8
435    }
436
437    #[classmethod]
438    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
439        EnumIterator::new::<Self>(py)
440    }
441
442    #[classmethod]
443    #[pyo3(name = "from_str")]
444    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
445        let data_str: &str = data.extract()?;
446        let tokenized = data_str.to_uppercase();
447        Self::from_str(&tokenized).map_err(to_pyvalue_err)
448    }
449}
450
451#[pymethods]
452#[pyo3_stub_gen::derive::gen_stub_pymethods]
453impl ContingencyType {
454    /// The order contingency type which specifies the behavior of linked orders.
455    ///
456    /// [FIX 5.0 SP2 : ContingencyType <1385> field](https://www.onixs.biz/fix-dictionary/5.0.sp2/tagnum_1385.html).
457    #[new]
458    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
459        let t = Self::type_object(py);
460        Self::py_from_str(&t, value)
461    }
462
463    const fn __hash__(&self) -> isize {
464        *self as isize
465    }
466
467    fn __str__(&self) -> String {
468        self.to_string()
469    }
470
471    #[getter]
472    #[must_use]
473    pub fn name(&self) -> String {
474        self.to_string()
475    }
476
477    #[getter]
478    #[must_use]
479    pub fn value(&self) -> u8 {
480        *self as u8
481    }
482
483    #[classmethod]
484    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
485        EnumIterator::new::<Self>(py)
486    }
487
488    #[classmethod]
489    #[pyo3(name = "from_str")]
490    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
491        let data_str: &str = data.extract()?;
492        let tokenized = data_str.to_uppercase();
493        Self::from_str(&tokenized).map_err(to_pyvalue_err)
494    }
495}
496
497#[pymethods]
498#[pyo3_stub_gen::derive::gen_stub_pymethods]
499impl CurrencyType {
500    /// The broad currency type.
501    #[new]
502    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
503        let t = Self::type_object(py);
504        Self::py_from_str(&t, value)
505    }
506
507    const fn __hash__(&self) -> isize {
508        *self as isize
509    }
510
511    fn __str__(&self) -> String {
512        self.to_string()
513    }
514
515    #[getter]
516    #[must_use]
517    pub fn name(&self) -> String {
518        self.to_string()
519    }
520
521    #[getter]
522    #[must_use]
523    pub fn value(&self) -> u8 {
524        *self as u8
525    }
526
527    #[classmethod]
528    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
529        EnumIterator::new::<Self>(py)
530    }
531
532    #[classmethod]
533    #[pyo3(name = "from_str")]
534    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
535        let data_str: &str = data.extract()?;
536        let tokenized = data_str.to_uppercase();
537        Self::from_str(&tokenized).map_err(to_pyvalue_err)
538    }
539}
540
541#[pymethods]
542#[pyo3_stub_gen::derive::gen_stub_pymethods]
543impl InstrumentCloseType {
544    /// The type of event for an instrument close.
545    #[new]
546    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
547        let t = Self::type_object(py);
548        Self::py_from_str(&t, value)
549    }
550
551    const fn __hash__(&self) -> isize {
552        *self as isize
553    }
554
555    fn __str__(&self) -> String {
556        self.to_string()
557    }
558
559    #[getter]
560    #[must_use]
561    pub fn name(&self) -> String {
562        self.to_string()
563    }
564
565    #[getter]
566    #[must_use]
567    pub fn value(&self) -> u8 {
568        *self as u8
569    }
570
571    #[classmethod]
572    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
573        EnumIterator::new::<Self>(py)
574    }
575
576    #[classmethod]
577    #[pyo3(name = "from_str")]
578    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
579        let data_str: &str = data.extract()?;
580        let tokenized = data_str.to_uppercase();
581        Self::from_str(&tokenized).map_err(to_pyvalue_err)
582    }
583}
584
585#[pymethods]
586#[pyo3_stub_gen::derive::gen_stub_pymethods]
587impl LiquiditySide {
588    /// The liquidity side for a trade.
589    #[new]
590    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
591        let t = Self::type_object(py);
592        Self::py_from_str(&t, value)
593    }
594
595    const fn __hash__(&self) -> isize {
596        *self as isize
597    }
598
599    fn __str__(&self) -> String {
600        self.to_string()
601    }
602
603    #[getter]
604    #[must_use]
605    pub fn name(&self) -> String {
606        self.to_string()
607    }
608
609    #[getter]
610    #[must_use]
611    pub fn value(&self) -> u8 {
612        *self as u8
613    }
614
615    #[classmethod]
616    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
617        EnumIterator::new::<Self>(py)
618    }
619
620    #[classmethod]
621    #[pyo3(name = "from_str")]
622    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
623        let data_str: &str = data.extract()?;
624        let tokenized = data_str.to_uppercase();
625        Self::from_str(&tokenized).map_err(to_pyvalue_err)
626    }
627}
628
629#[pymethods]
630#[pyo3_stub_gen::derive::gen_stub_pymethods]
631impl MarketStatus {
632    /// The status of an individual market on a trading venue.
633    #[new]
634    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
635        let t = Self::type_object(py);
636        Self::py_from_str(&t, value)
637    }
638
639    const fn __hash__(&self) -> isize {
640        *self as isize
641    }
642
643    fn __str__(&self) -> String {
644        self.to_string()
645    }
646
647    #[getter]
648    #[must_use]
649    pub fn name(&self) -> String {
650        self.to_string()
651    }
652
653    #[getter]
654    #[must_use]
655    pub fn value(&self) -> u8 {
656        *self as u8
657    }
658
659    #[classmethod]
660    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
661        EnumIterator::new::<Self>(py)
662    }
663
664    #[classmethod]
665    #[pyo3(name = "from_str")]
666    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
667        let data_str: &str = data.extract()?;
668        let tokenized = data_str.to_uppercase();
669        Self::from_str(&tokenized).map_err(to_pyvalue_err)
670    }
671}
672
673#[pymethods]
674#[pyo3_stub_gen::derive::gen_stub_pymethods]
675impl MarketStatusAction {
676    /// An action affecting the status of an individual market on a trading venue.
677    #[new]
678    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
679        let t = Self::type_object(py);
680        Self::py_from_str(&t, value)
681    }
682
683    const fn __hash__(&self) -> isize {
684        *self as isize
685    }
686
687    fn __str__(&self) -> String {
688        self.to_string()
689    }
690
691    #[getter]
692    #[must_use]
693    pub fn name(&self) -> String {
694        self.to_string()
695    }
696
697    #[getter]
698    #[must_use]
699    pub fn value(&self) -> u8 {
700        *self as u8
701    }
702
703    #[classmethod]
704    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
705        EnumIterator::new::<Self>(py)
706    }
707
708    #[classmethod]
709    #[pyo3(name = "from_str")]
710    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
711        let data_str: &str = data.extract()?;
712        let tokenized = data_str.to_uppercase();
713        Self::from_str(&tokenized).map_err(to_pyvalue_err)
714    }
715}
716
717#[pymethods]
718#[pyo3_stub_gen::derive::gen_stub_pymethods]
719impl OmsType {
720    /// The order management system (OMS) type for a trading venue or trading strategy.
721    #[new]
722    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
723        let t = Self::type_object(py);
724        Self::py_from_str(&t, value)
725    }
726
727    const fn __hash__(&self) -> isize {
728        *self as isize
729    }
730
731    fn __str__(&self) -> String {
732        self.to_string()
733    }
734
735    #[getter]
736    #[must_use]
737    pub fn name(&self) -> String {
738        self.to_string()
739    }
740
741    #[getter]
742    #[must_use]
743    pub fn value(&self) -> u8 {
744        *self as u8
745    }
746
747    #[classmethod]
748    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
749        EnumIterator::new::<Self>(py)
750    }
751
752    #[classmethod]
753    #[pyo3(name = "from_str")]
754    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
755        let data_str: &str = data.extract()?;
756        let tokenized = data_str.to_uppercase();
757        Self::from_str(&tokenized).map_err(to_pyvalue_err)
758    }
759}
760
761#[pymethods]
762#[pyo3_stub_gen::derive::gen_stub_pymethods]
763impl OptionKind {
764    /// The kind of option contract.
765    #[new]
766    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
767        let t = Self::type_object(py);
768        Self::py_from_str(&t, value)
769    }
770
771    const fn __hash__(&self) -> isize {
772        *self as isize
773    }
774
775    fn __str__(&self) -> String {
776        self.to_string()
777    }
778
779    #[getter]
780    #[must_use]
781    pub fn name(&self) -> String {
782        self.to_string()
783    }
784
785    #[getter]
786    #[must_use]
787    pub fn value(&self) -> u8 {
788        *self as u8
789    }
790
791    #[classmethod]
792    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
793        EnumIterator::new::<Self>(py)
794    }
795
796    #[classmethod]
797    #[pyo3(name = "from_str")]
798    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
799        let data_str: &str = data.extract()?;
800        let tokenized = data_str.to_uppercase();
801        Self::from_str(&tokenized).map_err(to_pyvalue_err)
802    }
803}
804
805#[pymethods]
806#[pyo3_stub_gen::derive::gen_stub_pymethods]
807impl GreeksConvention {
808    /// The numeraire convention for option greeks published by a venue.
809    ///
810    /// Crypto option venues commonly publish two parallel greek sets for the same
811    /// instrument: Black-Scholes greeks in USD, and price-adjusted greeks denominated
812    /// in the underlying/coin units. Deribit and OKX both expose the distinction;
813    /// see the OKX reference for the canonical definition:
814    /// <https://www.okx.com/docs-v5/en/#public-data-websocket-option-market-data>.
815    ///
816    /// This is orthogonal to the percent-greeks transformation in the internal
817    /// `GreeksCalculator`,
818    /// which rescales the delta/gamma input step rather than the numeraire.
819    #[new]
820    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
821        let t = Self::type_object(py);
822        Self::py_from_str(&t, value)
823    }
824
825    const fn __hash__(&self) -> isize {
826        *self as isize
827    }
828
829    fn __str__(&self) -> String {
830        self.to_string()
831    }
832
833    #[getter]
834    #[must_use]
835    pub fn name(&self) -> String {
836        self.to_string()
837    }
838
839    #[getter]
840    #[must_use]
841    pub fn value(&self) -> u8 {
842        *self as u8
843    }
844
845    #[classmethod]
846    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
847        EnumIterator::new::<Self>(py)
848    }
849
850    #[classmethod]
851    #[pyo3(name = "from_str")]
852    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
853        let data_str: &str = data.extract()?;
854        let tokenized = data_str.to_uppercase();
855        Self::from_str(&tokenized).map_err(to_pyvalue_err)
856    }
857}
858
859#[pymethods]
860#[pyo3_stub_gen::derive::gen_stub_pymethods]
861impl OtoTriggerMode {
862    /// Defines when OTO (One-Triggers-Other) child orders are released.
863    #[new]
864    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
865        let t = Self::type_object(py);
866        Self::py_from_str(&t, value)
867    }
868
869    const fn __hash__(&self) -> isize {
870        *self as isize
871    }
872
873    fn __str__(&self) -> String {
874        self.to_string()
875    }
876
877    #[getter]
878    #[must_use]
879    pub fn name(&self) -> String {
880        self.to_string()
881    }
882
883    #[getter]
884    #[must_use]
885    pub fn value(&self) -> u8 {
886        *self as u8
887    }
888
889    #[classmethod]
890    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
891        EnumIterator::new::<Self>(py)
892    }
893
894    #[classmethod]
895    #[pyo3(name = "from_str")]
896    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
897        let data_str: &str = data.extract()?;
898        let tokenized = data_str.to_uppercase();
899        Self::from_str(&tokenized).map_err(to_pyvalue_err)
900    }
901}
902
903#[pymethods]
904#[pyo3_stub_gen::derive::gen_stub_pymethods]
905impl OrderSide {
906    /// The order side for a specific order, or action related to orders.
907    #[new]
908    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
909        let t = Self::type_object(py);
910        Self::py_from_str(&t, value)
911    }
912
913    const fn __hash__(&self) -> isize {
914        *self as isize
915    }
916
917    fn __str__(&self) -> String {
918        self.to_string()
919    }
920
921    #[getter]
922    #[must_use]
923    pub fn name(&self) -> String {
924        self.to_string()
925    }
926
927    #[getter]
928    #[must_use]
929    pub fn value(&self) -> u8 {
930        *self as u8
931    }
932
933    #[classmethod]
934    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
935        EnumIterator::new::<Self>(py)
936    }
937
938    #[classmethod]
939    #[pyo3(name = "from_str")]
940    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
941        let data_str: &str = data.extract()?;
942        let tokenized = data_str.to_uppercase();
943        Self::from_str(&tokenized).map_err(to_pyvalue_err)
944    }
945}
946
947#[pymethods]
948#[pyo3_stub_gen::derive::gen_stub_pymethods]
949impl OrderStatus {
950    /// The status for a specific order.
951    ///
952    /// An order is considered _open_ for the following status:
953    ///  - `ACCEPTED`
954    ///  - `TRIGGERED`
955    ///  - `PENDING_UPDATE`
956    ///  - `PENDING_CANCEL`
957    ///  - `PARTIALLY_FILLED`
958    ///
959    /// An order is considered _in-flight_ for the following status:
960    ///  - `SUBMITTED`
961    ///  - `PENDING_UPDATE`
962    ///  - `PENDING_CANCEL`
963    ///
964    /// An order is considered _closed_ for the following status:
965    ///  - `DENIED`
966    ///  - `REJECTED`
967    ///  - `CANCELED`
968    ///  - `EXPIRED`
969    ///  - `FILLED`
970    #[new]
971    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
972        let t = Self::type_object(py);
973        Self::py_from_str(&t, value)
974    }
975
976    const fn __hash__(&self) -> isize {
977        *self as isize
978    }
979
980    fn __str__(&self) -> String {
981        self.to_string()
982    }
983
984    #[getter]
985    #[must_use]
986    pub fn name(&self) -> String {
987        self.to_string()
988    }
989
990    #[getter]
991    #[must_use]
992    pub fn value(&self) -> u8 {
993        *self as u8
994    }
995
996    #[classmethod]
997    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
998        EnumIterator::new::<Self>(py)
999    }
1000
1001    #[classmethod]
1002    #[pyo3(name = "from_str")]
1003    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1004        let data_str: &str = data.extract()?;
1005        let tokenized = data_str.to_uppercase();
1006        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1007    }
1008}
1009
1010#[pymethods]
1011#[pyo3_stub_gen::derive::gen_stub_pymethods]
1012impl OrderType {
1013    /// The type of order.
1014    #[new]
1015    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1016        let t = Self::type_object(py);
1017        Self::py_from_str(&t, value)
1018    }
1019
1020    const fn __hash__(&self) -> isize {
1021        *self as isize
1022    }
1023
1024    fn __str__(&self) -> String {
1025        self.to_string()
1026    }
1027
1028    #[getter]
1029    #[must_use]
1030    pub fn name(&self) -> String {
1031        self.to_string()
1032    }
1033
1034    #[getter]
1035    #[must_use]
1036    pub fn value(&self) -> u8 {
1037        *self as u8
1038    }
1039
1040    #[classmethod]
1041    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1042        EnumIterator::new::<Self>(py)
1043    }
1044
1045    #[classmethod]
1046    #[pyo3(name = "from_str")]
1047    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1048        let data_str: &str = data.extract()?;
1049        let tokenized = data_str.to_uppercase();
1050        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1051    }
1052}
1053
1054#[pymethods]
1055#[pyo3_stub_gen::derive::gen_stub_pymethods]
1056impl PositionSide {
1057    /// The market side for a specific position, or action related to positions.
1058    #[new]
1059    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1060        let t = Self::type_object(py);
1061        Self::py_from_str(&t, value)
1062    }
1063
1064    const fn __hash__(&self) -> isize {
1065        *self as isize
1066    }
1067
1068    fn __str__(&self) -> String {
1069        self.to_string()
1070    }
1071
1072    #[getter]
1073    #[must_use]
1074    pub fn name(&self) -> String {
1075        self.to_string()
1076    }
1077
1078    #[getter]
1079    #[must_use]
1080    pub fn value(&self) -> u8 {
1081        *self as u8
1082    }
1083
1084    #[classmethod]
1085    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1086        EnumIterator::new::<Self>(py)
1087    }
1088
1089    #[classmethod]
1090    #[pyo3(name = "from_str")]
1091    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1092        let data_str: &str = data.extract()?;
1093        let tokenized = data_str.to_uppercase();
1094        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1095    }
1096}
1097
1098#[pymethods]
1099#[pyo3_stub_gen::derive::gen_stub_pymethods]
1100impl PriceType {
1101    /// The type of price for an instrument in a market.
1102    #[new]
1103    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1104        let t = Self::type_object(py);
1105        Self::py_from_str(&t, value)
1106    }
1107
1108    const fn __hash__(&self) -> isize {
1109        *self as isize
1110    }
1111
1112    fn __str__(&self) -> String {
1113        self.to_string()
1114    }
1115
1116    #[getter]
1117    #[must_use]
1118    pub fn name(&self) -> String {
1119        self.to_string()
1120    }
1121
1122    #[getter]
1123    #[must_use]
1124    pub fn value(&self) -> u8 {
1125        *self as u8
1126    }
1127
1128    #[classmethod]
1129    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1130        EnumIterator::new::<Self>(py)
1131    }
1132
1133    #[classmethod]
1134    #[pyo3(name = "from_str")]
1135    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1136        let data_str: &str = data.extract()?;
1137        let tokenized = data_str.to_uppercase();
1138        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1139    }
1140
1141    #[classmethod]
1142    #[pyo3(name = "from_int")]
1143    fn py_from_int(_: &Bound<'_, PyType>, value: i32) -> PyResult<Self> {
1144        Self::from_repr(value as usize)
1145            .ok_or_else(|| to_pyvalue_err(format!("Invalid PriceType value: {value}")))
1146    }
1147}
1148
1149#[pymethods]
1150#[pyo3_stub_gen::derive::gen_stub_pymethods]
1151impl RecordFlag {
1152    /// A record flag bit field, indicating event end and data information.
1153    #[new]
1154    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1155        let t = Self::type_object(py);
1156        Self::py_from_str(&t, value)
1157    }
1158
1159    const fn __hash__(&self) -> isize {
1160        *self as isize
1161    }
1162
1163    fn __str__(&self) -> String {
1164        self.to_string()
1165    }
1166
1167    #[getter]
1168    #[must_use]
1169    pub fn name(&self) -> String {
1170        self.to_string()
1171    }
1172
1173    #[getter]
1174    #[must_use]
1175    pub fn value(&self) -> u8 {
1176        *self as u8
1177    }
1178
1179    #[classmethod]
1180    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1181        EnumIterator::new::<Self>(py)
1182    }
1183
1184    #[classmethod]
1185    #[pyo3(name = "from_str")]
1186    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1187        let data_str: &str = data.extract()?;
1188        let tokenized = data_str.to_uppercase();
1189        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1190    }
1191
1192    /// Checks if the flag matches a given value.
1193    #[pyo3(name = "matches")]
1194    fn py_matches(&self, value: u8) -> bool {
1195        self.matches(value)
1196    }
1197}
1198
1199#[pymethods]
1200#[pyo3_stub_gen::derive::gen_stub_pymethods]
1201impl TimeInForce {
1202    /// The 'Time in Force' instruction for an order.
1203    #[new]
1204    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1205        let t = Self::type_object(py);
1206        Self::py_from_str(&t, value)
1207    }
1208
1209    const fn __hash__(&self) -> isize {
1210        *self as isize
1211    }
1212
1213    fn __str__(&self) -> String {
1214        self.to_string()
1215    }
1216
1217    #[getter]
1218    #[must_use]
1219    pub fn name(&self) -> String {
1220        self.to_string()
1221    }
1222
1223    #[getter]
1224    #[must_use]
1225    pub fn value(&self) -> u8 {
1226        *self as u8
1227    }
1228
1229    #[classmethod]
1230    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1231        EnumIterator::new::<Self>(py)
1232    }
1233
1234    #[classmethod]
1235    #[pyo3(name = "from_str")]
1236    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1237        let data_str: &str = data.extract()?;
1238        let tokenized = data_str.to_uppercase();
1239        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1240    }
1241}
1242
1243#[pymethods]
1244#[pyo3_stub_gen::derive::gen_stub_pymethods]
1245impl TrailingOffsetType {
1246    /// The trailing offset type for an order type which specifies a trailing stop/trigger or limit price.
1247    #[new]
1248    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1249        let t = Self::type_object(py);
1250        Self::py_from_str(&t, value)
1251    }
1252
1253    const fn __hash__(&self) -> isize {
1254        *self as isize
1255    }
1256
1257    fn __str__(&self) -> String {
1258        self.to_string()
1259    }
1260
1261    #[getter]
1262    #[must_use]
1263    pub fn name(&self) -> String {
1264        self.to_string()
1265    }
1266
1267    #[getter]
1268    #[must_use]
1269    pub fn value(&self) -> u8 {
1270        *self as u8
1271    }
1272
1273    #[classmethod]
1274    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1275        EnumIterator::new::<Self>(py)
1276    }
1277
1278    #[classmethod]
1279    #[pyo3(name = "from_str")]
1280    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1281        let data_str: &str = data.extract()?;
1282        let tokenized = data_str.to_uppercase();
1283        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1284    }
1285}
1286
1287#[pymethods]
1288#[pyo3_stub_gen::derive::gen_stub_pymethods]
1289impl TriggerType {
1290    /// The trigger type for the stop/trigger price of an order.
1291    #[new]
1292    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1293        let t = Self::type_object(py);
1294        Self::py_from_str(&t, value)
1295    }
1296
1297    const fn __hash__(&self) -> isize {
1298        *self as isize
1299    }
1300
1301    fn __str__(&self) -> String {
1302        self.to_string()
1303    }
1304
1305    #[getter]
1306    #[must_use]
1307    pub fn name(&self) -> String {
1308        self.to_string()
1309    }
1310
1311    #[getter]
1312    #[must_use]
1313    pub fn value(&self) -> u8 {
1314        *self as u8
1315    }
1316
1317    #[classmethod]
1318    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1319        EnumIterator::new::<Self>(py)
1320    }
1321
1322    #[classmethod]
1323    #[pyo3(name = "from_str")]
1324    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1325        let data_str: &str = data.extract()?;
1326        let tokenized = data_str.to_uppercase();
1327        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1328    }
1329}
1330
1331#[pymethods]
1332#[pyo3_stub_gen::derive::gen_stub_pymethods]
1333impl BookType {
1334    /// The order book type, representing the type of levels granularity and delta updating heuristics.
1335    #[new]
1336    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1337        let t = Self::type_object(py);
1338        Self::py_from_str(&t, value)
1339    }
1340
1341    const fn __hash__(&self) -> isize {
1342        *self as isize
1343    }
1344
1345    fn __str__(&self) -> String {
1346        self.to_string()
1347    }
1348
1349    #[getter]
1350    #[must_use]
1351    pub fn name(&self) -> String {
1352        self.to_string()
1353    }
1354
1355    #[getter]
1356    #[must_use]
1357    pub fn value(&self) -> u8 {
1358        *self as u8
1359    }
1360
1361    #[classmethod]
1362    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1363        EnumIterator::new::<Self>(py)
1364    }
1365
1366    #[classmethod]
1367    #[pyo3(name = "from_str")]
1368    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1369        let data_str: &str = data.extract()?;
1370        let tokenized = data_str.to_uppercase();
1371        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1372    }
1373}
1374
1375#[pymethods]
1376#[pyo3_stub_gen::derive::gen_stub_pymethods]
1377impl TradingState {
1378    /// The trading state for a node.
1379    #[new]
1380    fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
1381        let t = Self::type_object(py);
1382        Self::py_from_str(&t, value)
1383    }
1384
1385    const fn __hash__(&self) -> isize {
1386        *self as isize
1387    }
1388
1389    fn __str__(&self) -> String {
1390        self.to_string()
1391    }
1392
1393    #[getter]
1394    #[must_use]
1395    pub fn name(&self) -> String {
1396        self.to_string()
1397    }
1398
1399    #[getter]
1400    #[must_use]
1401    pub fn value(&self) -> u8 {
1402        *self as u8
1403    }
1404
1405    #[classmethod]
1406    fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
1407        EnumIterator::new::<Self>(py)
1408    }
1409
1410    #[classmethod]
1411    #[pyo3(name = "from_str")]
1412    fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
1413        let data_str: &str = data.extract()?;
1414        let tokenized = data_str.to_uppercase();
1415        Self::from_str(&tokenized).map_err(to_pyvalue_err)
1416    }
1417}