nautilus_model/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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 serde::{Deserialize, Deserializer, Serialize, Serializer};
21use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
22
23use crate::enum_strum_serde;
24
25/// Provides conversion from a `u8` value to an enum type.
26pub trait FromU8 {
27    /// Converts a `u8` value to the implementing type.
28    ///
29    /// Returns `None` if the value is not a valid representation.
30    fn from_u8(value: u8) -> Option<Self>
31    where
32        Self: Sized;
33}
34
35/// Provides conversion from a `u16` value to an enum type.
36pub trait FromU16 {
37    /// Converts a `u16` value to the implementing type.
38    ///
39    /// Returns `None` if the value is not a valid representation.
40    fn from_u16(value: u16) -> Option<Self>
41    where
42        Self: Sized;
43}
44
45/// An account type provided by a trading venue or broker.
46#[repr(C)]
47#[derive(
48    Copy,
49    Clone,
50    Debug,
51    Display,
52    Hash,
53    PartialEq,
54    Eq,
55    PartialOrd,
56    Ord,
57    AsRefStr,
58    FromRepr,
59    EnumIter,
60    EnumString,
61)]
62#[strum(ascii_case_insensitive)]
63#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
64#[cfg_attr(
65    feature = "python",
66    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
67)]
68pub enum AccountType {
69    /// An account with unleveraged cash assets only.
70    Cash = 1,
71    /// An account which facilitates trading on margin, using account assets as collateral.
72    Margin = 2,
73    /// An account specific to betting markets.
74    Betting = 3,
75}
76
77/// An aggregation source for derived data.
78#[repr(C)]
79#[derive(
80    Copy,
81    Clone,
82    Debug,
83    Display,
84    Hash,
85    PartialEq,
86    Eq,
87    PartialOrd,
88    Ord,
89    AsRefStr,
90    FromRepr,
91    EnumIter,
92    EnumString,
93)]
94#[strum(ascii_case_insensitive)]
95#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
96#[cfg_attr(
97    feature = "python",
98    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
99)]
100pub enum AggregationSource {
101    /// The data is externally aggregated (outside the Posei system boundary).
102    External = 1,
103    /// The data is internally aggregated (inside the Posei system boundary).
104    Internal = 2,
105}
106
107/// The side for the aggressing order of a trade in a market.
108#[repr(C)]
109#[derive(
110    Copy,
111    Clone,
112    Debug,
113    Default,
114    Display,
115    Hash,
116    PartialEq,
117    Eq,
118    PartialOrd,
119    Ord,
120    AsRefStr,
121    FromRepr,
122    EnumIter,
123    EnumString,
124)]
125#[strum(ascii_case_insensitive)]
126#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
127#[cfg_attr(
128    feature = "python",
129    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
130)]
131pub enum AggressorSide {
132    /// There was no specific aggressor for the trade.
133    #[default]
134    NoAggressor = 0,
135    /// The BUY order was the aggressor for the trade.
136    Buyer = 1,
137    /// The SELL order was the aggressor for the trade.
138    Seller = 2,
139}
140
141impl FromU8 for AggressorSide {
142    fn from_u8(value: u8) -> Option<Self> {
143        match value {
144            0 => Some(Self::NoAggressor),
145            1 => Some(Self::Buyer),
146            2 => Some(Self::Seller),
147            _ => None,
148        }
149    }
150}
151
152/// A broad financial market asset class.
153#[repr(C)]
154#[derive(
155    Copy,
156    Clone,
157    Debug,
158    Display,
159    Hash,
160    PartialEq,
161    Eq,
162    PartialOrd,
163    Ord,
164    AsRefStr,
165    FromRepr,
166    EnumIter,
167    EnumString,
168)]
169#[strum(ascii_case_insensitive)]
170#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
171#[cfg_attr(
172    feature = "python",
173    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
174)]
175#[allow(non_camel_case_types)]
176pub enum AssetClass {
177    /// Foreign exchange (FOREX) assets.
178    FX = 1,
179    /// Equity / stock assets.
180    Equity = 2,
181    /// Commodity assets.
182    Commodity = 3,
183    /// Debt based assets.
184    Debt = 4,
185    /// Index based assets (baskets).
186    Index = 5,
187    /// Cryptocurrency or crypto token assets.
188    Cryptocurrency = 6,
189    /// Alternative assets.
190    Alternative = 7,
191}
192
193impl FromU8 for AssetClass {
194    fn from_u8(value: u8) -> Option<Self> {
195        match value {
196            1 => Some(Self::FX),
197            2 => Some(Self::Equity),
198            3 => Some(Self::Commodity),
199            4 => Some(Self::Debt),
200            5 => Some(Self::Index),
201            6 => Some(Self::Cryptocurrency),
202            7 => Some(Self::Alternative),
203            _ => None,
204        }
205    }
206}
207
208/// The instrument class.
209#[repr(C)]
210#[derive(
211    Copy,
212    Clone,
213    Debug,
214    Display,
215    Hash,
216    PartialEq,
217    Eq,
218    PartialOrd,
219    Ord,
220    AsRefStr,
221    FromRepr,
222    EnumIter,
223    EnumString,
224)]
225#[strum(ascii_case_insensitive)]
226#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
227#[cfg_attr(
228    feature = "python",
229    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
230)]
231pub enum InstrumentClass {
232    /// A spot market instrument class. The current market price of an instrument that is bought or sold for immediate delivery and payment.
233    Spot = 1,
234    /// A swap instrument class. A derivative contract through which two parties exchange the cash flows or liabilities from two different financial instruments.
235    Swap = 2,
236    /// A futures contract instrument class. A legal agreement to buy or sell an asset at a predetermined price at a specified time in the future.
237    Future = 3,
238    /// A futures spread instrument class. A strategy involving the use of futures contracts to take advantage of price differentials between different contract months, underlying assets, or marketplaces.
239    FuturesSpread = 4,
240    /// A forward derivative instrument class. A customized contract between two parties to buy or sell an asset at a specified price on a future date.
241    Forward = 5,
242    /// A contract-for-difference (CFD) instrument class. A contract between an investor and a CFD broker to exchange the difference in the value of a financial product between the time the contract opens and closes.
243    Cfd = 6,
244    /// A bond instrument class. A type of debt investment where an investor loans money to an entity (typically corporate or governmental) which borrows the funds for a defined period of time at a variable or fixed interest rate.
245    Bond = 7,
246    /// An option contract instrument class. A type of derivative that gives the holder the right, but not the obligation, to buy or sell an underlying asset at a predetermined price before or at a certain future date.
247    Option = 8,
248    /// An option spread instrument class. A strategy involving the purchase and/or sale of multiple option contracts on the same underlying asset with different strike prices or expiration dates to hedge risk or speculate on price movements.
249    OptionSpread = 9,
250    /// A warrant instrument class. A derivative that gives the holder the right, but not the obligation, to buy or sell a security—most commonly an equity—at a certain price before expiration.
251    Warrant = 10,
252    /// A sports betting instrument class. A financialized derivative that allows wagering on the outcome of sports events using structured contracts or prediction markets.
253    SportsBetting = 11,
254    /// A binary option instrument class. A type of derivative where the payoff is either a fixed monetary amount or nothing, depending on whether the price of an underlying asset is above or below a predetermined level at expiration.
255    /// A binary option instrument class. A type of derivative where the payoff is either a fixed monetary amount or nothing, based on a yes/no proposition about an underlying event.
256    BinaryOption = 12,
257}
258
259/// The aggregation method through which a bar is generated and closed.
260#[repr(C)]
261#[derive(
262    Copy,
263    Clone,
264    Debug,
265    Display,
266    Hash,
267    PartialEq,
268    Eq,
269    PartialOrd,
270    Ord,
271    AsRefStr,
272    FromRepr,
273    EnumIter,
274    EnumString,
275)]
276#[strum(ascii_case_insensitive)]
277#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
278#[cfg_attr(
279    feature = "python",
280    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
281)]
282pub enum BarAggregation {
283    /// Based on a number of ticks.
284    Tick = 1,
285    /// Based on the buy/sell imbalance of ticks.
286    TickImbalance = 2,
287    /// Based on sequential buy/sell runs of ticks.
288    TickRuns = 3,
289    /// Based on traded volume.
290    Volume = 4,
291    /// Based on the buy/sell imbalance of traded volume.
292    VolumeImbalance = 5,
293    /// Based on sequential runs of buy/sell traded volume.
294    VolumeRuns = 6,
295    /// Based on the 'notional' value of the instrument.
296    Value = 7,
297    /// Based on the buy/sell imbalance of trading by notional value.
298    ValueImbalance = 8,
299    /// Based on sequential buy/sell runs of trading by notional value.
300    ValueRuns = 9,
301    /// Based on time intervals with millisecond granularity.
302    Millisecond = 10,
303    /// Based on time intervals with second granularity.
304    Second = 11,
305    /// Based on time intervals with minute granularity.
306    Minute = 12,
307    /// Based on time intervals with hour granularity.
308    Hour = 13,
309    /// Based on time intervals with day granularity.
310    Day = 14,
311    /// Based on time intervals with week granularity.
312    Week = 15,
313    /// Based on time intervals with month granularity.
314    Month = 16,
315}
316
317/// The interval type for bar aggregation.
318#[repr(C)]
319#[derive(
320    Copy,
321    Clone,
322    Debug,
323    Default,
324    Display,
325    Hash,
326    PartialEq,
327    Eq,
328    PartialOrd,
329    Ord,
330    AsRefStr,
331    FromRepr,
332    EnumIter,
333    EnumString,
334)]
335#[strum(ascii_case_insensitive)]
336#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
337#[cfg_attr(
338    feature = "python",
339    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
340)]
341pub enum BarIntervalType {
342    /// Left-open interval `(start, end]`: start is exclusive, end is inclusive (default).
343    #[default]
344    LeftOpen = 1,
345    /// Right-open interval `[start, end)`: start is inclusive, end is exclusive.
346    RightOpen = 2,
347}
348
349/// Represents the side of a bet in a betting market.
350#[repr(C)]
351#[derive(
352    Copy,
353    Clone,
354    Debug,
355    Display,
356    Hash,
357    PartialEq,
358    Eq,
359    PartialOrd,
360    Ord,
361    AsRefStr,
362    FromRepr,
363    EnumIter,
364    EnumString,
365)]
366#[strum(ascii_case_insensitive)]
367#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
368#[cfg_attr(
369    feature = "python",
370    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
371)]
372pub enum BetSide {
373    /// A "Back" bet signifies support for a specific outcome.
374    Back = 1,
375    /// A "Lay" bet signifies opposition to a specific outcome.
376    Lay = 2,
377}
378
379impl BetSide {
380    /// Returns the opposite betting side.
381    #[must_use]
382    pub fn opposite(&self) -> Self {
383        match self {
384            Self::Back => Self::Lay,
385            Self::Lay => Self::Back,
386        }
387    }
388}
389
390impl From<OrderSide> for BetSide {
391    /// Returns the equivalent [`BetSide`] for a given [`OrderSide`].
392    ///
393    /// # Panics
394    ///
395    /// Panics if `side` is [`OrderSide::NoOrderSide`].
396    fn from(side: OrderSide) -> Self {
397        match side {
398            OrderSide::Buy => BetSide::Back,
399            OrderSide::Sell => BetSide::Lay,
400            OrderSide::NoOrderSide => panic!("Invalid `OrderSide` for `BetSide`, was {side}"),
401        }
402    }
403}
404
405/// The type of order book action for an order book event.
406#[repr(C)]
407#[derive(
408    Copy,
409    Clone,
410    Debug,
411    Display,
412    Hash,
413    PartialEq,
414    Eq,
415    PartialOrd,
416    Ord,
417    AsRefStr,
418    FromRepr,
419    EnumIter,
420    EnumString,
421)]
422#[strum(ascii_case_insensitive)]
423#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
424#[cfg_attr(
425    feature = "python",
426    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
427)]
428pub enum BookAction {
429    /// An order is added to the book.
430    Add = 1,
431    /// An existing order in the book is updated/modified.
432    Update = 2,
433    /// An existing order in the book is deleted/canceled.
434    Delete = 3,
435    /// The state of the order book is cleared.
436    Clear = 4,
437}
438
439impl FromU8 for BookAction {
440    fn from_u8(value: u8) -> Option<Self> {
441        match value {
442            1 => Some(Self::Add),
443            2 => Some(Self::Update),
444            3 => Some(Self::Delete),
445            4 => Some(Self::Clear),
446            _ => None,
447        }
448    }
449}
450
451/// The order book type, representing the type of levels granularity and delta updating heuristics.
452#[repr(C)]
453#[derive(
454    Copy,
455    Clone,
456    Debug,
457    Display,
458    Hash,
459    PartialEq,
460    Eq,
461    PartialOrd,
462    Ord,
463    AsRefStr,
464    FromRepr,
465    EnumIter,
466    EnumString,
467)]
468#[strum(ascii_case_insensitive)]
469#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
470#[allow(non_camel_case_types)]
471#[cfg_attr(
472    feature = "python",
473    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
474)]
475pub enum BookType {
476    /// Top-of-book best bid/ask, one level per side.
477    L1_MBP = 1,
478    /// Market by price, one order per level (aggregated).
479    L2_MBP = 2,
480    /// Market by order, multiple orders per level (full granularity).
481    L3_MBO = 3,
482}
483
484impl FromU8 for BookType {
485    fn from_u8(value: u8) -> Option<Self> {
486        match value {
487            1 => Some(Self::L1_MBP),
488            2 => Some(Self::L2_MBP),
489            3 => Some(Self::L3_MBO),
490            _ => None,
491        }
492    }
493}
494
495/// The order contigency type which specifies the behavior of linked orders.
496///
497/// [FIX 5.0 SP2 : ContingencyType <1385> field](https://www.onixs.biz/fix-dictionary/5.0.sp2/tagnum_1385.html).
498#[repr(C)]
499#[derive(
500    Copy,
501    Clone,
502    Debug,
503    Default,
504    Display,
505    Hash,
506    PartialEq,
507    Eq,
508    PartialOrd,
509    Ord,
510    AsRefStr,
511    FromRepr,
512    EnumIter,
513    EnumString,
514)]
515#[strum(ascii_case_insensitive)]
516#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
517#[cfg_attr(
518    feature = "python",
519    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
520)]
521pub enum ContingencyType {
522    /// Not a contingent order.
523    #[default]
524    NoContingency = 0,
525    /// One-Cancels-the-Other.
526    Oco = 1,
527    /// One-Triggers-the-Other.
528    Oto = 2,
529    /// One-Updates-the-Other (by proportional quantity).
530    Ouo = 3,
531}
532
533/// The broad currency type.
534#[repr(C)]
535#[derive(
536    Copy,
537    Clone,
538    Debug,
539    Display,
540    Hash,
541    PartialEq,
542    Eq,
543    PartialOrd,
544    Ord,
545    AsRefStr,
546    FromRepr,
547    EnumIter,
548    EnumString,
549)]
550#[strum(ascii_case_insensitive)]
551#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
552#[cfg_attr(
553    feature = "python",
554    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
555)]
556pub enum CurrencyType {
557    /// A type of cryptocurrency or crypto token.
558    Crypto = 1,
559    /// A type of currency issued by governments which is not backed by a commodity.
560    Fiat = 2,
561    /// A type of currency that is based on the value of an underlying commodity.
562    CommodityBacked = 3,
563}
564
565/// The type of event for an instrument close.
566#[repr(C)]
567#[derive(
568    Copy,
569    Clone,
570    Debug,
571    Display,
572    Hash,
573    PartialEq,
574    Eq,
575    PartialOrd,
576    Ord,
577    AsRefStr,
578    FromRepr,
579    EnumIter,
580    EnumString,
581)]
582#[strum(ascii_case_insensitive)]
583#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
584#[cfg_attr(
585    feature = "python",
586    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
587)]
588pub enum InstrumentCloseType {
589    /// When the market session ended.
590    EndOfSession = 1,
591    /// When the instrument expiration was reached.
592    ContractExpired = 2,
593}
594
595/// Convert the given `value` to an [`InstrumentCloseType`].
596impl FromU8 for InstrumentCloseType {
597    fn from_u8(value: u8) -> Option<Self> {
598        match value {
599            1 => Some(Self::EndOfSession),
600            2 => Some(Self::ContractExpired),
601            _ => None,
602        }
603    }
604}
605
606/// The liqudity side for a trade.
607#[repr(C)]
608#[derive(
609    Copy,
610    Clone,
611    Debug,
612    Display,
613    Hash,
614    PartialEq,
615    Eq,
616    PartialOrd,
617    Ord,
618    AsRefStr,
619    FromRepr,
620    EnumIter,
621    EnumString,
622)]
623#[strum(ascii_case_insensitive)]
624#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
625#[cfg_attr(
626    feature = "python",
627    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
628)]
629#[allow(clippy::enum_variant_names)]
630pub enum LiquiditySide {
631    /// No liquidity side specified.
632    NoLiquiditySide = 0,
633    /// The order passively provided liqudity to the market to complete the trade (made a market).
634    Maker = 1,
635    /// The order aggressively took liqudity from the market to complete the trade.
636    Taker = 2,
637}
638
639/// The status of an individual market on a trading venue.
640#[repr(C)]
641#[derive(
642    Copy,
643    Clone,
644    Debug,
645    Display,
646    Hash,
647    PartialEq,
648    Eq,
649    PartialOrd,
650    Ord,
651    AsRefStr,
652    FromRepr,
653    EnumIter,
654    EnumString,
655)]
656#[strum(ascii_case_insensitive)]
657#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
658#[cfg_attr(
659    feature = "python",
660    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
661)]
662pub enum MarketStatus {
663    /// The instrument is trading.
664    Open = 1,
665    /// The instrument is in a pre-open period.
666    Closed = 2,
667    /// Trading in the instrument has been paused.
668    Paused = 3,
669    /// Trading in the instrument has been halted.
670    // Halted = 4,  # TODO: Unfortunately can't use this yet due to Cython (C enum namespacing)
671    /// Trading in the instrument has been suspended.
672    Suspended = 5,
673    /// Trading in the instrument is not available.
674    NotAvailable = 6,
675}
676
677/// An action affecting the status of an individual market on a trading venue.
678#[repr(C)]
679#[derive(
680    Copy,
681    Clone,
682    Debug,
683    Display,
684    Hash,
685    PartialEq,
686    Eq,
687    PartialOrd,
688    Ord,
689    AsRefStr,
690    FromRepr,
691    EnumIter,
692    EnumString,
693)]
694#[strum(ascii_case_insensitive)]
695#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
696#[cfg_attr(
697    feature = "python",
698    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
699)]
700pub enum MarketStatusAction {
701    /// No change.
702    None = 0,
703    /// The instrument is in a pre-open period.
704    PreOpen = 1,
705    /// The instrument is in a pre-cross period.
706    PreCross = 2,
707    /// The instrument is quoting but not trading.
708    Quoting = 3,
709    /// The instrument is in a cross/auction.
710    Cross = 4,
711    /// The instrument is being opened through a trading rotation.
712    Rotation = 5,
713    /// A new price indication is available for the instrument.
714    NewPriceIndication = 6,
715    /// The instrument is trading.
716    Trading = 7,
717    /// Trading in the instrument has been halted.
718    Halt = 8,
719    /// Trading in the instrument has been paused.
720    Pause = 9,
721    /// Trading in the instrument has been suspended.
722    Suspend = 10,
723    /// The instrument is in a pre-close period.
724    PreClose = 11,
725    /// Trading in the instrument has closed.
726    Close = 12,
727    /// The instrument is in a post-close period.
728    PostClose = 13,
729    /// A change in short-selling restrictions.
730    ShortSellRestrictionChange = 14,
731    /// The instrument is not available for trading, either trading has closed or been halted.
732    NotAvailableForTrading = 15,
733}
734
735/// Convert the given `value` to an [`OrderSide`].
736impl FromU16 for MarketStatusAction {
737    fn from_u16(value: u16) -> Option<Self> {
738        match value {
739            0 => Some(Self::None),
740            1 => Some(Self::PreOpen),
741            2 => Some(Self::PreCross),
742            3 => Some(Self::Quoting),
743            4 => Some(Self::Cross),
744            5 => Some(Self::Rotation),
745            6 => Some(Self::NewPriceIndication),
746            7 => Some(Self::Trading),
747            8 => Some(Self::Halt),
748            9 => Some(Self::Pause),
749            10 => Some(Self::Suspend),
750            11 => Some(Self::PreClose),
751            12 => Some(Self::Close),
752            13 => Some(Self::PostClose),
753            14 => Some(Self::ShortSellRestrictionChange),
754            15 => Some(Self::NotAvailableForTrading),
755            _ => None,
756        }
757    }
758}
759
760/// The order management system (OMS) type for a trading venue or trading strategy.
761#[repr(C)]
762#[derive(
763    Copy,
764    Clone,
765    Debug,
766    Default,
767    Display,
768    Hash,
769    PartialEq,
770    Eq,
771    PartialOrd,
772    Ord,
773    AsRefStr,
774    FromRepr,
775    EnumIter,
776    EnumString,
777)]
778#[strum(ascii_case_insensitive)]
779#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
780#[cfg_attr(
781    feature = "python",
782    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
783)]
784pub enum OmsType {
785    /// There is no specific type of order management specified (will defer to the venue OMS).
786    #[default]
787    Unspecified = 0,
788    /// The netting type where there is one position per instrument.
789    Netting = 1,
790    /// The hedging type where there can be multiple positions per instrument.
791    /// This can be in LONG/SHORT directions, by position/ticket ID, or tracked virtually by
792    /// Posei.
793    Hedging = 2,
794}
795
796/// The kind of option contract.
797#[repr(C)]
798#[derive(
799    Copy,
800    Clone,
801    Debug,
802    Display,
803    Hash,
804    PartialEq,
805    Eq,
806    PartialOrd,
807    Ord,
808    AsRefStr,
809    FromRepr,
810    EnumIter,
811    EnumString,
812)]
813#[strum(ascii_case_insensitive)]
814#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
815#[cfg_attr(
816    feature = "python",
817    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
818)]
819pub enum OptionKind {
820    /// A Call option gives the holder the right, but not the obligation, to buy an underlying asset at a specified strike price within a specified period of time.
821    Call = 1,
822    /// A Put option gives the holder the right, but not the obligation, to sell an underlying asset at a specified strike price within a specified period of time.
823    Put = 2,
824}
825
826/// The order side for a specific order, or action related to orders.
827#[repr(C)]
828#[derive(
829    Copy,
830    Clone,
831    Debug,
832    Default,
833    Display,
834    Hash,
835    PartialEq,
836    Eq,
837    PartialOrd,
838    Ord,
839    AsRefStr,
840    FromRepr,
841    EnumIter,
842    EnumString,
843)]
844#[strum(ascii_case_insensitive)]
845#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
846#[allow(clippy::enum_variant_names)]
847#[cfg_attr(
848    feature = "python",
849    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
850)]
851pub enum OrderSide {
852    /// No order side is specified.
853    #[default]
854    NoOrderSide = 0,
855    /// The order is a BUY.
856    Buy = 1,
857    /// The order is a SELL.
858    Sell = 2,
859}
860
861impl OrderSide {
862    /// Returns the specified [`OrderSideSpecified`] (BUY or SELL) for this side.
863    ///
864    /// # Panics
865    ///
866    /// Panics if `self` is [`OrderSide::NoOrderSide`].
867    #[must_use]
868    pub fn as_specified(&self) -> OrderSideSpecified {
869        match &self {
870            Self::Buy => OrderSideSpecified::Buy,
871            Self::Sell => OrderSideSpecified::Sell,
872            _ => panic!("Order invariant failed: side must be `Buy` or `Sell`"),
873        }
874    }
875}
876
877/// Convert the given `value` to an [`OrderSide`].
878impl FromU8 for OrderSide {
879    fn from_u8(value: u8) -> Option<Self> {
880        match value {
881            0 => Some(Self::NoOrderSide),
882            1 => Some(Self::Buy),
883            2 => Some(Self::Sell),
884            _ => None,
885        }
886    }
887}
888
889/// The specified order side (BUY or SELL).
890#[repr(C)]
891#[derive(
892    Copy,
893    Clone,
894    Debug,
895    Display,
896    Hash,
897    PartialEq,
898    Eq,
899    PartialOrd,
900    Ord,
901    AsRefStr,
902    FromRepr,
903    EnumIter,
904    EnumString,
905)]
906#[strum(ascii_case_insensitive)]
907#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
908#[allow(clippy::enum_variant_names)]
909pub enum OrderSideSpecified {
910    /// The order is a BUY.
911    Buy = 1,
912    /// The order is a SELL.
913    Sell = 2,
914}
915
916impl OrderSideSpecified {
917    /// Returns the opposite order side.
918    #[must_use]
919    pub fn opposite(&self) -> Self {
920        match &self {
921            Self::Buy => Self::Sell,
922            Self::Sell => Self::Buy,
923        }
924    }
925
926    /// Converts this specified side into an [`OrderSide`].
927    #[must_use]
928    pub fn as_order_side(&self) -> OrderSide {
929        match &self {
930            Self::Buy => OrderSide::Buy,
931            Self::Sell => OrderSide::Sell,
932        }
933    }
934}
935
936/// The status for a specific order.
937///
938/// An order is considered _open_ for the following status:
939///  - `ACCEPTED`
940///  - `TRIGGERED`
941///  - `PENDING_UPDATE`
942///  - `PENDING_CANCEL`
943///  - `PARTIALLY_FILLED`
944///
945/// An order is considered _in-flight_ for the following status:
946///  - `SUBMITTED`
947///  - `PENDING_UPDATE`
948///  - `PENDING_CANCEL`
949///
950/// An order is considered _closed_ for the following status:
951///  - `DENIED`
952///  - `REJECTED`
953///  - `CANCELED`
954///  - `EXPIRED`
955///  - `FILLED`
956#[repr(C)]
957#[derive(
958    Copy,
959    Clone,
960    Debug,
961    Display,
962    Hash,
963    PartialEq,
964    Eq,
965    PartialOrd,
966    Ord,
967    AsRefStr,
968    FromRepr,
969    EnumIter,
970    EnumString,
971)]
972#[strum(ascii_case_insensitive)]
973#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
974#[cfg_attr(
975    feature = "python",
976    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
977)]
978pub enum OrderStatus {
979    /// The order is initialized (instantiated) within the Posei system.
980    Initialized = 1,
981    /// The order was denied by the Posei system, either for being invalid, unprocessable or exceeding a risk limit.
982    Denied = 2,
983    /// The order became emulated by the Posei system in the `OrderEmulator` component.
984    Emulated = 3,
985    /// The order was released by the Posei system from the `OrderEmulator` component.
986    Released = 4,
987    /// The order was submitted by the Posei system to the external service or trading venue (awaiting acknowledgement).
988    Submitted = 5,
989    /// The order was acknowledged by the trading venue as being received and valid (may now be working).
990    Accepted = 6,
991    /// The order was rejected by the trading venue.
992    Rejected = 7,
993    /// The order was canceled (closed/done).
994    Canceled = 8,
995    /// The order reached a GTD expiration (closed/done).
996    Expired = 9,
997    /// The order STOP price was triggered on a trading venue.
998    Triggered = 10,
999    /// The order is currently pending a request to modify on a trading venue.
1000    PendingUpdate = 11,
1001    /// The order is currently pending a request to cancel on a trading venue.
1002    PendingCancel = 12,
1003    /// The order has been partially filled on a trading venue.
1004    PartiallyFilled = 13,
1005    /// The order has been completely filled on a trading venue (closed/done).
1006    Filled = 14,
1007}
1008
1009/// The type of order.
1010#[repr(C)]
1011#[derive(
1012    Copy,
1013    Clone,
1014    Debug,
1015    Display,
1016    Hash,
1017    PartialEq,
1018    Eq,
1019    PartialOrd,
1020    Ord,
1021    AsRefStr,
1022    FromRepr,
1023    EnumIter,
1024    EnumString,
1025)]
1026#[strum(ascii_case_insensitive)]
1027#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1028#[cfg_attr(
1029    feature = "python",
1030    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1031)]
1032pub enum OrderType {
1033    /// A market order to buy or sell at the best available price in the current market.
1034    Market = 1,
1035    /// A limit order to buy or sell at a specific price or better.
1036    Limit = 2,
1037    /// A stop market order to buy or sell once the price reaches the specified stop/trigger price. When the stop price is reached, the order effectively becomes a market order.
1038    StopMarket = 3,
1039    /// A stop limit order to buy or sell which combines the features of a stop order and a limit order. Once the stop/trigger price is reached, a stop-limit order effectively becomes a limit order.
1040    StopLimit = 4,
1041    /// A market-to-limit order is a market order that is to be executed as a limit order at the current best market price after reaching the market.
1042    MarketToLimit = 5,
1043    /// A market-if-touched order effectively becomes a market order when the specified trigger price is reached.
1044    MarketIfTouched = 6,
1045    /// A limit-if-touched order effectively becomes a limit order when the specified trigger price is reached.
1046    LimitIfTouched = 7,
1047    /// A trailing stop market order sets the stop/trigger price at a fixed "trailing offset" amount from the market.
1048    TrailingStopMarket = 8,
1049    /// A trailing stop limit order combines the features of a trailing stop order with those of a limit order.
1050    TrailingStopLimit = 9,
1051}
1052
1053/// The market side for a specific position, or action related to positions.
1054#[repr(C)]
1055#[derive(
1056    Copy,
1057    Clone,
1058    Debug,
1059    Default,
1060    Display,
1061    Hash,
1062    PartialEq,
1063    Eq,
1064    PartialOrd,
1065    Ord,
1066    AsRefStr,
1067    FromRepr,
1068    EnumIter,
1069    EnumString,
1070)]
1071#[strum(ascii_case_insensitive)]
1072#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1073#[allow(clippy::enum_variant_names)]
1074#[cfg_attr(
1075    feature = "python",
1076    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1077)]
1078pub enum PositionSide {
1079    /// No position side is specified (only valid in the context of a filter for actions involving positions).
1080    #[default]
1081    NoPositionSide = 0,
1082    /// A neural/flat position, where no position is currently held in the market.
1083    Flat = 1,
1084    /// A long position in the market, typically acquired through one or many BUY orders.
1085    Long = 2,
1086    /// A short position in the market, typically acquired through one or many SELL orders.
1087    Short = 3,
1088}
1089
1090/// The type of price for an instrument in a market.
1091#[repr(C)]
1092#[derive(
1093    Copy,
1094    Clone,
1095    Debug,
1096    Display,
1097    Hash,
1098    PartialEq,
1099    Eq,
1100    PartialOrd,
1101    Ord,
1102    AsRefStr,
1103    FromRepr,
1104    EnumIter,
1105    EnumString,
1106)]
1107#[strum(ascii_case_insensitive)]
1108#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1109#[cfg_attr(
1110    feature = "python",
1111    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1112)]
1113pub enum PriceType {
1114    /// The best quoted price at which buyers are willing to buy a quantity of an instrument.
1115    /// Often considered the best bid in the order book.
1116    Bid = 1,
1117    /// The best quoted price at which sellers are willing to sell a quantity of an instrument.
1118    /// Often considered the best ask in the order book.
1119    Ask = 2,
1120    /// The arithmetic midpoint between the best bid and ask quotes.
1121    Mid = 3,
1122    /// The price at which the last trade of an instrument was executed.
1123    Last = 4,
1124    /// A reference price reflecting an instrument's fair value, often used for portfolio
1125    /// calculations and risk management.
1126    Mark = 5,
1127}
1128
1129/// A record flag bit field, indicating event end and data information.
1130#[repr(C)]
1131#[derive(
1132    Copy,
1133    Clone,
1134    Debug,
1135    Display,
1136    Hash,
1137    PartialEq,
1138    Eq,
1139    PartialOrd,
1140    Ord,
1141    AsRefStr,
1142    FromRepr,
1143    EnumIter,
1144    EnumString,
1145)]
1146#[strum(ascii_case_insensitive)]
1147#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1148#[cfg_attr(
1149    feature = "python",
1150    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1151)]
1152#[allow(non_camel_case_types)]
1153pub enum RecordFlag {
1154    /// Last message in the book event or packet from the venue for a given `instrument_id`.
1155    F_LAST = 1 << 7, // 128
1156    /// Top-of-book message, not an individual order.
1157    F_TOB = 1 << 6, // 64
1158    /// Message sourced from a replay, such as a snapshot server.
1159    F_SNAPSHOT = 1 << 5, // 32
1160    /// Aggregated price level message, not an individual order.
1161    F_MBP = 1 << 4, // 16
1162    /// Reserved for future use.
1163    RESERVED_2 = 1 << 3, // 8
1164    /// Reserved for future use.
1165    RESERVED_1 = 1 << 2, // 4
1166}
1167
1168impl RecordFlag {
1169    /// Checks if the flag matches a given value.
1170    #[must_use]
1171    pub fn matches(self, value: u8) -> bool {
1172        (self as u8) & value != 0
1173    }
1174}
1175
1176/// The 'Time in Force' instruction for an order.
1177#[repr(C)]
1178#[derive(
1179    Copy,
1180    Clone,
1181    Debug,
1182    Display,
1183    Hash,
1184    PartialEq,
1185    Eq,
1186    PartialOrd,
1187    Ord,
1188    AsRefStr,
1189    FromRepr,
1190    EnumIter,
1191    EnumString,
1192)]
1193#[strum(ascii_case_insensitive)]
1194#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1195#[cfg_attr(
1196    feature = "python",
1197    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1198)]
1199pub enum TimeInForce {
1200    /// Good Till Cancel (GTC) - Remains active until canceled.
1201    Gtc = 1,
1202    /// Immediate or Cancel (IOC) - Executes immediately to the extent possible, with any unfilled portion canceled.
1203    Ioc = 2,
1204    /// Fill or Kill (FOK) - Executes in its entirety immediately or is canceled if full execution is not possible.
1205    Fok = 3,
1206    /// Good Till Date (GTD) - Remains active until the specified expiration date or time is reached.
1207    Gtd = 4,
1208    /// Day - Remains active until the close of the current trading session.
1209    Day = 5,
1210    /// At the Opening (ATO) - Executes at the market opening or expires if not filled.
1211    AtTheOpen = 6,
1212    /// At the Closing (ATC) - Executes at the market close or expires if not filled.
1213    AtTheClose = 7,
1214}
1215
1216/// The trading state for a node.
1217#[repr(C)]
1218#[derive(
1219    Copy,
1220    Clone,
1221    Debug,
1222    Display,
1223    Hash,
1224    PartialEq,
1225    Eq,
1226    PartialOrd,
1227    Ord,
1228    AsRefStr,
1229    FromRepr,
1230    EnumIter,
1231    EnumString,
1232)]
1233#[strum(ascii_case_insensitive)]
1234#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1235#[cfg_attr(
1236    feature = "python",
1237    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1238)]
1239pub enum TradingState {
1240    /// Normal trading operations.
1241    Active = 1,
1242    /// Trading is completely halted, no new order commands will be emitted.
1243    Halted = 2,
1244    /// Only order commands which would cancel order, or reduce position sizes are permitted.
1245    Reducing = 3,
1246}
1247
1248/// The trailing offset type for an order type which specifies a trailing stop/trigger or limit price.
1249#[repr(C)]
1250#[derive(
1251    Copy,
1252    Clone,
1253    Debug,
1254    Default,
1255    Display,
1256    Hash,
1257    PartialEq,
1258    Eq,
1259    PartialOrd,
1260    Ord,
1261    AsRefStr,
1262    FromRepr,
1263    EnumIter,
1264    EnumString,
1265)]
1266#[strum(ascii_case_insensitive)]
1267#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1268#[cfg_attr(
1269    feature = "python",
1270    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1271)]
1272pub enum TrailingOffsetType {
1273    /// No trailing offset type is specified (invalid for trailing type orders).
1274    #[default]
1275    NoTrailingOffset = 0,
1276    /// The trailing offset is based on a market price.
1277    Price = 1,
1278    /// The trailing offset is based on a percentage represented in basis points, of a market price.
1279    BasisPoints = 2,
1280    /// The trailing offset is based on the number of ticks from a market price.
1281    Ticks = 3,
1282    /// The trailing offset is based on a price tier set by a specific trading venue.
1283    PriceTier = 4,
1284}
1285
1286/// The trigger type for the stop/trigger price of an order.
1287#[repr(C)]
1288#[derive(
1289    Copy,
1290    Clone,
1291    Debug,
1292    Default,
1293    Display,
1294    Hash,
1295    PartialEq,
1296    Eq,
1297    PartialOrd,
1298    Ord,
1299    AsRefStr,
1300    FromRepr,
1301    EnumIter,
1302    EnumString,
1303)]
1304#[strum(ascii_case_insensitive)]
1305#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1306#[cfg_attr(
1307    feature = "python",
1308    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.model.enums")
1309)]
1310pub enum TriggerType {
1311    /// No trigger type is specified (invalid for orders with a trigger).
1312    #[default]
1313    NoTrigger = 0,
1314    /// The default trigger type set by the trading venue.
1315    Default = 1,
1316    /// Based on the last traded price for the instrument.
1317    LastPrice = 2,
1318    /// Based on the mark price for the instrument.
1319    MarkPrice = 3,
1320    /// Based on the index price for the instrument.
1321    IndexPrice = 4,
1322    /// Based on the top-of-book quoted prices for the instrument.
1323    BidAsk = 5,
1324    /// Based on a 'double match' of the last traded price for the instrument
1325    DoubleLast = 6,
1326    /// Based on a 'double match' of the bid/ask price for the instrument
1327    DoubleBidAsk = 7,
1328    /// Based on both the [`TriggerType::LastPrice`] and [`TriggerType::BidAsk`].
1329    LastOrBidAsk = 8,
1330    /// Based on the mid-point of the [`TriggerType::BidAsk`].
1331    MidPoint = 9,
1332}
1333
1334enum_strum_serde!(AccountType);
1335enum_strum_serde!(AggregationSource);
1336enum_strum_serde!(AggressorSide);
1337enum_strum_serde!(AssetClass);
1338enum_strum_serde!(InstrumentClass);
1339enum_strum_serde!(BarAggregation);
1340enum_strum_serde!(BarIntervalType);
1341enum_strum_serde!(BookAction);
1342enum_strum_serde!(BookType);
1343enum_strum_serde!(ContingencyType);
1344enum_strum_serde!(CurrencyType);
1345enum_strum_serde!(InstrumentCloseType);
1346enum_strum_serde!(LiquiditySide);
1347enum_strum_serde!(MarketStatus);
1348enum_strum_serde!(MarketStatusAction);
1349enum_strum_serde!(OmsType);
1350enum_strum_serde!(OptionKind);
1351enum_strum_serde!(OrderSide);
1352enum_strum_serde!(OrderSideSpecified);
1353enum_strum_serde!(OrderStatus);
1354enum_strum_serde!(OrderType);
1355enum_strum_serde!(PositionSide);
1356enum_strum_serde!(PriceType);
1357enum_strum_serde!(RecordFlag);
1358enum_strum_serde!(TimeInForce);
1359enum_strum_serde!(TradingState);
1360enum_strum_serde!(TrailingOffsetType);
1361enum_strum_serde!(TriggerType);