1use std::{str::FromStr, sync::OnceLock};
19
20use ahash::AHashSet;
21use serde::{Deserialize, Deserializer, Serialize, Serializer};
22use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
23
24use crate::enum_strum_serde;
25
26pub trait FromU8 {
28 fn from_u8(value: u8) -> Option<Self>
32 where
33 Self: Sized;
34}
35
36pub trait FromU16 {
38 fn from_u16(value: u16) -> Option<Self>
42 where
43 Self: Sized;
44}
45
46#[repr(C)]
48#[derive(
49 Copy,
50 Clone,
51 Debug,
52 Display,
53 Hash,
54 PartialEq,
55 Eq,
56 PartialOrd,
57 Ord,
58 AsRefStr,
59 FromRepr,
60 EnumIter,
61 EnumString,
62)]
63#[strum(ascii_case_insensitive)]
64#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
65#[cfg_attr(
66 feature = "python",
67 pyo3::pyclass(
68 frozen,
69 eq,
70 eq_int,
71 hash,
72 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
73 )
74)]
75pub enum AccountType {
76 Cash = 1,
78 Margin = 2,
80 Betting = 3,
82 Wallet = 4,
84}
85
86#[repr(C)]
88#[derive(
89 Copy,
90 Clone,
91 Debug,
92 Display,
93 Hash,
94 PartialEq,
95 Eq,
96 PartialOrd,
97 Ord,
98 AsRefStr,
99 FromRepr,
100 EnumIter,
101 EnumString,
102)]
103#[strum(ascii_case_insensitive)]
104#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
105#[cfg_attr(
106 feature = "python",
107 pyo3::pyclass(
108 frozen,
109 eq,
110 eq_int,
111 hash,
112 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
113 )
114)]
115pub enum AggregationSource {
116 External = 1,
118 Internal = 2,
120}
121
122#[repr(C)]
124#[derive(
125 Copy,
126 Clone,
127 Debug,
128 Default,
129 Display,
130 Hash,
131 PartialEq,
132 Eq,
133 PartialOrd,
134 Ord,
135 AsRefStr,
136 FromRepr,
137 EnumIter,
138 EnumString,
139)]
140#[strum(ascii_case_insensitive)]
141#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
142#[cfg_attr(
143 feature = "python",
144 pyo3::pyclass(
145 frozen,
146 eq,
147 eq_int,
148 hash,
149 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
150 )
151)]
152pub enum AggressorSide {
153 #[default]
155 NoAggressor = 0,
156 Buyer = 1,
158 Seller = 2,
160}
161
162impl FromU8 for AggressorSide {
163 fn from_u8(value: u8) -> Option<Self> {
164 match value {
165 0 => Some(Self::NoAggressor),
166 1 => Some(Self::Buyer),
167 2 => Some(Self::Seller),
168 _ => None,
169 }
170 }
171}
172
173#[repr(C)]
175#[derive(
176 Copy,
177 Clone,
178 Debug,
179 Display,
180 Hash,
181 PartialEq,
182 Eq,
183 PartialOrd,
184 Ord,
185 AsRefStr,
186 FromRepr,
187 EnumIter,
188 EnumString,
189)]
190#[strum(ascii_case_insensitive)]
191#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
192#[cfg_attr(
193 feature = "python",
194 pyo3::pyclass(
195 frozen,
196 eq,
197 eq_int,
198 hash,
199 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
200 )
201)]
202#[allow(non_camel_case_types)]
203pub enum AssetClass {
204 FX = 1,
206 Equity = 2,
208 Commodity = 3,
210 Debt = 4,
212 Index = 5,
214 Cryptocurrency = 6,
216 Alternative = 7,
218}
219
220impl FromU8 for AssetClass {
221 fn from_u8(value: u8) -> Option<Self> {
222 match value {
223 1 => Some(Self::FX),
224 2 => Some(Self::Equity),
225 3 => Some(Self::Commodity),
226 4 => Some(Self::Debt),
227 5 => Some(Self::Index),
228 6 => Some(Self::Cryptocurrency),
229 7 => Some(Self::Alternative),
230 _ => None,
231 }
232 }
233}
234
235#[repr(C)]
237#[derive(
238 Copy,
239 Clone,
240 Debug,
241 Display,
242 Hash,
243 PartialEq,
244 Eq,
245 PartialOrd,
246 Ord,
247 AsRefStr,
248 FromRepr,
249 EnumIter,
250 EnumString,
251)]
252#[strum(ascii_case_insensitive)]
253#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
254#[cfg_attr(
255 feature = "python",
256 pyo3::pyclass(
257 frozen,
258 eq,
259 eq_int,
260 hash,
261 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
262 )
263)]
264pub enum BarAggregation {
265 Tick = 1,
267 TickImbalance = 2,
269 TickRuns = 3,
271 Volume = 4,
273 VolumeImbalance = 5,
275 VolumeRuns = 6,
277 Value = 7,
279 ValueImbalance = 8,
281 ValueRuns = 9,
283 Millisecond = 10,
285 Second = 11,
287 Minute = 12,
289 Hour = 13,
291 Day = 14,
293 Week = 15,
295 Month = 16,
297 Year = 17,
299 Renko = 18,
301}
302
303#[repr(C)]
305#[derive(
306 Copy,
307 Clone,
308 Debug,
309 Default,
310 Display,
311 Hash,
312 PartialEq,
313 Eq,
314 PartialOrd,
315 Ord,
316 AsRefStr,
317 FromRepr,
318 EnumIter,
319 EnumString,
320)]
321#[strum(ascii_case_insensitive)]
322#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
323#[cfg_attr(
324 feature = "python",
325 pyo3::pyclass(
326 frozen,
327 eq,
328 eq_int,
329 hash,
330 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
331 )
332)]
333pub enum BarIntervalType {
334 #[default]
336 LeftOpen = 1,
337 RightOpen = 2,
339}
340
341#[repr(C)]
343#[derive(
344 Copy,
345 Clone,
346 Debug,
347 Display,
348 Hash,
349 PartialEq,
350 Eq,
351 PartialOrd,
352 Ord,
353 AsRefStr,
354 FromRepr,
355 EnumIter,
356 EnumString,
357)]
358#[strum(ascii_case_insensitive)]
359#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
360#[cfg_attr(
361 feature = "python",
362 pyo3::pyclass(
363 frozen,
364 eq,
365 eq_int,
366 hash,
367 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
368 )
369)]
370pub enum BetSide {
371 Back = 1,
373 Lay = 2,
375}
376
377impl BetSide {
378 #[must_use]
380 pub fn opposite(&self) -> Self {
381 match self {
382 Self::Back => Self::Lay,
383 Self::Lay => Self::Back,
384 }
385 }
386}
387
388impl From<OrderSide> for BetSide {
389 fn from(side: OrderSide) -> Self {
395 match side {
396 OrderSide::Buy => Self::Back,
397 OrderSide::Sell => Self::Lay,
398 OrderSide::NoOrderSide => panic!("Invalid `OrderSide` for `BetSide`, was {side}"),
399 }
400 }
401}
402
403#[repr(C)]
405#[derive(
406 Copy,
407 Clone,
408 Debug,
409 Display,
410 Hash,
411 PartialEq,
412 Eq,
413 PartialOrd,
414 Ord,
415 AsRefStr,
416 FromRepr,
417 EnumIter,
418 EnumString,
419)]
420#[strum(ascii_case_insensitive)]
421#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
422#[cfg_attr(
423 feature = "python",
424 pyo3::pyclass(
425 frozen,
426 eq,
427 eq_int,
428 hash,
429 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
430 )
431)]
432pub enum BookAction {
433 Add = 1,
435 Update = 2,
437 Delete = 3,
439 Clear = 4,
441}
442
443impl FromU8 for BookAction {
444 fn from_u8(value: u8) -> Option<Self> {
445 match value {
446 1 => Some(Self::Add),
447 2 => Some(Self::Update),
448 3 => Some(Self::Delete),
449 4 => Some(Self::Clear),
450 _ => None,
451 }
452 }
453}
454
455#[repr(C)]
457#[derive(
458 Copy,
459 Clone,
460 Debug,
461 Display,
462 Hash,
463 PartialEq,
464 Eq,
465 PartialOrd,
466 Ord,
467 AsRefStr,
468 FromRepr,
469 EnumIter,
470 EnumString,
471)]
472#[strum(ascii_case_insensitive)]
473#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
474#[allow(non_camel_case_types)]
475#[cfg_attr(
476 feature = "python",
477 pyo3::pyclass(
478 frozen,
479 eq,
480 eq_int,
481 hash,
482 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
483 )
484)]
485pub enum BookType {
486 L1_MBP = 1,
488 L2_MBP = 2,
490 L3_MBO = 3,
492}
493
494impl FromU8 for BookType {
495 fn from_u8(value: u8) -> Option<Self> {
496 match value {
497 1 => Some(Self::L1_MBP),
498 2 => Some(Self::L2_MBP),
499 3 => Some(Self::L3_MBO),
500 _ => None,
501 }
502 }
503}
504
505#[repr(C)]
509#[derive(
510 Copy,
511 Clone,
512 Debug,
513 Default,
514 Display,
515 Hash,
516 PartialEq,
517 Eq,
518 PartialOrd,
519 Ord,
520 AsRefStr,
521 FromRepr,
522 EnumIter,
523 EnumString,
524)]
525#[strum(ascii_case_insensitive)]
526#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
527#[cfg_attr(
528 feature = "python",
529 pyo3::pyclass(
530 frozen,
531 eq,
532 eq_int,
533 hash,
534 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
535 )
536)]
537pub enum ContingencyType {
538 #[default]
540 NoContingency = 0,
541 Oco = 1,
543 Oto = 2,
545 Ouo = 3,
547}
548
549#[repr(C)]
551#[derive(
552 Copy,
553 Clone,
554 Debug,
555 Display,
556 Hash,
557 PartialEq,
558 Eq,
559 PartialOrd,
560 Ord,
561 AsRefStr,
562 FromRepr,
563 EnumIter,
564 EnumString,
565)]
566#[strum(ascii_case_insensitive)]
567#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
568#[cfg_attr(
569 feature = "python",
570 pyo3::pyclass(
571 frozen,
572 eq,
573 eq_int,
574 hash,
575 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
576 )
577)]
578pub enum CurrencyType {
579 Crypto = 1,
581 Fiat = 2,
583 CommodityBacked = 3,
585}
586
587#[repr(C)]
589#[derive(
590 Copy,
591 Clone,
592 Debug,
593 Display,
594 Hash,
595 PartialEq,
596 Eq,
597 PartialOrd,
598 Ord,
599 AsRefStr,
600 FromRepr,
601 EnumIter,
602 EnumString,
603)]
604#[strum(ascii_case_insensitive)]
605#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
606#[cfg_attr(
607 feature = "python",
608 pyo3::pyclass(
609 frozen,
610 eq,
611 eq_int,
612 hash,
613 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
614 )
615)]
616pub enum InstrumentClass {
617 Spot = 1,
619 Swap = 2,
621 Future = 3,
623 FuturesSpread = 4,
625 Forward = 5,
627 Cfd = 6,
629 Bond = 7,
631 Option = 8,
633 OptionSpread = 9,
635 Warrant = 10,
637 SportsBetting = 11,
639 BinaryOption = 12,
641}
642
643#[repr(C)]
645#[derive(
646 Copy,
647 Clone,
648 Debug,
649 Display,
650 Hash,
651 PartialEq,
652 Eq,
653 PartialOrd,
654 Ord,
655 AsRefStr,
656 FromRepr,
657 EnumIter,
658 EnumString,
659)]
660#[strum(ascii_case_insensitive)]
661#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
662#[cfg_attr(
663 feature = "python",
664 pyo3::pyclass(
665 frozen,
666 eq,
667 eq_int,
668 hash,
669 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
670 )
671)]
672pub enum InstrumentCloseType {
673 EndOfSession = 1,
675 ContractExpired = 2,
677}
678
679impl FromU8 for InstrumentCloseType {
681 fn from_u8(value: u8) -> Option<Self> {
682 match value {
683 1 => Some(Self::EndOfSession),
684 2 => Some(Self::ContractExpired),
685 _ => None,
686 }
687 }
688}
689
690#[repr(C)]
692#[derive(
693 Copy,
694 Clone,
695 Debug,
696 Display,
697 Hash,
698 PartialEq,
699 Eq,
700 PartialOrd,
701 Ord,
702 AsRefStr,
703 FromRepr,
704 EnumIter,
705 EnumString,
706)]
707#[strum(ascii_case_insensitive)]
708#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
709#[cfg_attr(
710 feature = "python",
711 pyo3::pyclass(
712 frozen,
713 eq,
714 eq_int,
715 hash,
716 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
717 )
718)]
719#[allow(clippy::enum_variant_names)]
720pub enum LiquiditySide {
721 NoLiquiditySide = 0,
723 Maker = 1,
725 Taker = 2,
727}
728
729#[repr(C)]
731#[derive(
732 Copy,
733 Clone,
734 Debug,
735 Display,
736 Hash,
737 PartialEq,
738 Eq,
739 PartialOrd,
740 Ord,
741 AsRefStr,
742 FromRepr,
743 EnumIter,
744 EnumString,
745)]
746#[strum(ascii_case_insensitive)]
747#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
748#[cfg_attr(
749 feature = "python",
750 pyo3::pyclass(
751 frozen,
752 eq,
753 eq_int,
754 hash,
755 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
756 )
757)]
758pub enum MarketStatus {
759 Open = 1,
761 Closed = 2,
763 Paused = 3,
765 Suspended = 5,
769 NotAvailable = 6,
771}
772
773#[repr(C)]
775#[derive(
776 Copy,
777 Clone,
778 Debug,
779 Display,
780 Hash,
781 PartialEq,
782 Eq,
783 PartialOrd,
784 Ord,
785 AsRefStr,
786 FromRepr,
787 EnumIter,
788 EnumString,
789)]
790#[strum(ascii_case_insensitive)]
791#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
792#[cfg_attr(
793 feature = "python",
794 pyo3::pyclass(
795 frozen,
796 eq,
797 eq_int,
798 hash,
799 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
800 )
801)]
802pub enum MarketStatusAction {
803 None = 0,
805 PreOpen = 1,
807 PreCross = 2,
809 Quoting = 3,
811 Cross = 4,
813 Rotation = 5,
815 NewPriceIndication = 6,
817 Trading = 7,
819 Halt = 8,
821 Pause = 9,
823 Suspend = 10,
825 PreClose = 11,
827 Close = 12,
829 PostClose = 13,
831 ShortSellRestrictionChange = 14,
833 NotAvailableForTrading = 15,
835}
836
837impl FromU16 for MarketStatusAction {
839 fn from_u16(value: u16) -> Option<Self> {
840 match value {
841 0 => Some(Self::None),
842 1 => Some(Self::PreOpen),
843 2 => Some(Self::PreCross),
844 3 => Some(Self::Quoting),
845 4 => Some(Self::Cross),
846 5 => Some(Self::Rotation),
847 6 => Some(Self::NewPriceIndication),
848 7 => Some(Self::Trading),
849 8 => Some(Self::Halt),
850 9 => Some(Self::Pause),
851 10 => Some(Self::Suspend),
852 11 => Some(Self::PreClose),
853 12 => Some(Self::Close),
854 13 => Some(Self::PostClose),
855 14 => Some(Self::ShortSellRestrictionChange),
856 15 => Some(Self::NotAvailableForTrading),
857 _ => None,
858 }
859 }
860}
861
862#[repr(C)]
864#[derive(
865 Copy,
866 Clone,
867 Debug,
868 Default,
869 Display,
870 Hash,
871 PartialEq,
872 Eq,
873 PartialOrd,
874 Ord,
875 AsRefStr,
876 FromRepr,
877 EnumIter,
878 EnumString,
879)]
880#[strum(ascii_case_insensitive)]
881#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
882#[cfg_attr(
883 feature = "python",
884 pyo3::pyclass(
885 frozen,
886 eq,
887 eq_int,
888 hash,
889 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
890 )
891)]
892pub enum OmsType {
893 #[default]
895 Unspecified = 0,
896 Netting = 1,
898 Hedging = 2,
902}
903
904#[repr(C)]
906#[derive(
907 Copy,
908 Clone,
909 Debug,
910 Display,
911 Hash,
912 PartialEq,
913 Eq,
914 PartialOrd,
915 Ord,
916 AsRefStr,
917 FromRepr,
918 EnumIter,
919 EnumString,
920)]
921#[strum(ascii_case_insensitive)]
922#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
923#[cfg_attr(
924 feature = "python",
925 pyo3::pyclass(
926 frozen,
927 eq,
928 eq_int,
929 hash,
930 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
931 )
932)]
933pub enum OptionKind {
934 Call = 1,
936 Put = 2,
938}
939
940#[repr(C)]
942#[derive(
943 Copy,
944 Clone,
945 Debug,
946 Default,
947 Display,
948 Hash,
949 PartialEq,
950 Eq,
951 PartialOrd,
952 Ord,
953 AsRefStr,
954 FromRepr,
955 EnumIter,
956 EnumString,
957)]
958#[strum(ascii_case_insensitive)]
959#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
960#[allow(clippy::enum_variant_names)]
961#[cfg_attr(
962 feature = "python",
963 pyo3::pyclass(
964 frozen,
965 eq,
966 eq_int,
967 hash,
968 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
969 )
970)]
971pub enum OrderSide {
972 #[default]
974 NoOrderSide = 0,
975 Buy = 1,
977 Sell = 2,
979}
980
981impl OrderSide {
982 #[must_use]
988 pub fn as_specified(&self) -> OrderSideSpecified {
989 match &self {
990 Self::Buy => OrderSideSpecified::Buy,
991 Self::Sell => OrderSideSpecified::Sell,
992 _ => panic!("Order invariant failed: side must be `Buy` or `Sell`"),
993 }
994 }
995}
996
997impl FromU8 for OrderSide {
999 fn from_u8(value: u8) -> Option<Self> {
1000 match value {
1001 0 => Some(Self::NoOrderSide),
1002 1 => Some(Self::Buy),
1003 2 => Some(Self::Sell),
1004 _ => None,
1005 }
1006 }
1007}
1008
1009#[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#[allow(clippy::enum_variant_names)]
1029pub enum OrderSideSpecified {
1030 Buy = 1,
1032 Sell = 2,
1034}
1035
1036impl OrderSideSpecified {
1037 #[must_use]
1039 pub fn opposite(&self) -> Self {
1040 match &self {
1041 Self::Buy => Self::Sell,
1042 Self::Sell => Self::Buy,
1043 }
1044 }
1045
1046 #[must_use]
1048 pub fn as_order_side(&self) -> OrderSide {
1049 match &self {
1050 Self::Buy => OrderSide::Buy,
1051 Self::Sell => OrderSide::Sell,
1052 }
1053 }
1054}
1055
1056#[repr(C)]
1077#[derive(
1078 Copy,
1079 Clone,
1080 Debug,
1081 Display,
1082 Hash,
1083 PartialEq,
1084 Eq,
1085 PartialOrd,
1086 Ord,
1087 AsRefStr,
1088 FromRepr,
1089 EnumIter,
1090 EnumString,
1091)]
1092#[strum(ascii_case_insensitive)]
1093#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1094#[cfg_attr(
1095 feature = "python",
1096 pyo3::pyclass(
1097 frozen,
1098 eq,
1099 eq_int,
1100 hash,
1101 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1102 )
1103)]
1104pub enum OrderStatus {
1105 Initialized = 1,
1107 Denied = 2,
1109 Emulated = 3,
1111 Released = 4,
1113 Submitted = 5,
1115 Accepted = 6,
1117 Rejected = 7,
1119 Canceled = 8,
1121 Expired = 9,
1123 Triggered = 10,
1125 PendingUpdate = 11,
1127 PendingCancel = 12,
1129 PartiallyFilled = 13,
1131 Filled = 14,
1133}
1134
1135impl OrderStatus {
1136 #[must_use]
1151 pub fn cancellable_statuses_set() -> &'static AHashSet<Self> {
1152 static CANCELLABLE_SET: OnceLock<AHashSet<OrderStatus>> = OnceLock::new();
1153 CANCELLABLE_SET.get_or_init(|| {
1154 AHashSet::from_iter([
1155 Self::Accepted,
1156 Self::Triggered,
1157 Self::PendingUpdate,
1158 Self::PartiallyFilled,
1159 ])
1160 })
1161 }
1162}
1163
1164#[repr(C)]
1166#[derive(
1167 Copy,
1168 Clone,
1169 Debug,
1170 Display,
1171 Hash,
1172 PartialEq,
1173 Eq,
1174 PartialOrd,
1175 Ord,
1176 AsRefStr,
1177 FromRepr,
1178 EnumIter,
1179 EnumString,
1180)]
1181#[strum(ascii_case_insensitive)]
1182#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1183#[cfg_attr(
1184 feature = "python",
1185 pyo3::pyclass(
1186 frozen,
1187 eq,
1188 eq_int,
1189 hash,
1190 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1191 )
1192)]
1193pub enum OrderType {
1194 Market = 1,
1196 Limit = 2,
1198 StopMarket = 3,
1200 StopLimit = 4,
1202 MarketToLimit = 5,
1204 MarketIfTouched = 6,
1206 LimitIfTouched = 7,
1208 TrailingStopMarket = 8,
1210 TrailingStopLimit = 9,
1212}
1213
1214#[repr(C)]
1216#[derive(
1217 Copy,
1218 Clone,
1219 Debug,
1220 Display,
1221 Hash,
1222 PartialEq,
1223 Eq,
1224 PartialOrd,
1225 Ord,
1226 AsRefStr,
1227 FromRepr,
1228 EnumIter,
1229 EnumString,
1230)]
1231#[strum(ascii_case_insensitive)]
1232#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1233#[cfg_attr(
1234 feature = "python",
1235 pyo3::pyclass(eq, eq_int, module = "nautilus_trader.core.nautilus_pyo3.model.enums")
1236)]
1237pub enum PositionAdjustmentType {
1238 Commission = 1,
1240 Funding = 2,
1242}
1243
1244impl FromU8 for PositionAdjustmentType {
1245 fn from_u8(value: u8) -> Option<Self> {
1246 match value {
1247 1 => Some(Self::Commission),
1248 2 => Some(Self::Funding),
1249 _ => None,
1250 }
1251 }
1252}
1253
1254#[repr(C)]
1256#[derive(
1257 Copy,
1258 Clone,
1259 Debug,
1260 Default,
1261 Display,
1262 Hash,
1263 PartialEq,
1264 Eq,
1265 PartialOrd,
1266 Ord,
1267 AsRefStr,
1268 FromRepr,
1269 EnumIter,
1270 EnumString,
1271)]
1272#[strum(ascii_case_insensitive)]
1273#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1274#[allow(clippy::enum_variant_names)]
1275#[cfg_attr(
1276 feature = "python",
1277 pyo3::pyclass(
1278 frozen,
1279 eq,
1280 eq_int,
1281 hash,
1282 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1283 )
1284)]
1285pub enum PositionSide {
1286 #[default]
1288 NoPositionSide = 0,
1289 Flat = 1,
1291 Long = 2,
1293 Short = 3,
1295}
1296
1297impl PositionSide {
1298 #[must_use]
1304 pub fn as_specified(&self) -> PositionSideSpecified {
1305 match &self {
1306 Self::Long => PositionSideSpecified::Long,
1307 Self::Short => PositionSideSpecified::Short,
1308 Self::Flat => PositionSideSpecified::Flat,
1309 _ => panic!("Position invariant failed: side must be `Long`, `Short`, or `Flat`"),
1310 }
1311 }
1312}
1313
1314#[repr(C)]
1316#[derive(
1317 Copy,
1318 Clone,
1319 Debug,
1320 Display,
1321 Hash,
1322 PartialEq,
1323 Eq,
1324 PartialOrd,
1325 Ord,
1326 AsRefStr,
1327 FromRepr,
1328 EnumIter,
1329 EnumString,
1330)]
1331#[strum(ascii_case_insensitive)]
1332#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1333#[allow(clippy::enum_variant_names)]
1334#[cfg_attr(
1335 feature = "python",
1336 pyo3::pyclass(
1337 frozen,
1338 eq,
1339 eq_int,
1340 hash,
1341 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1342 )
1343)]
1344pub enum PositionSideSpecified {
1345 Flat = 1,
1347 Long = 2,
1349 Short = 3,
1351}
1352
1353impl PositionSideSpecified {
1354 #[must_use]
1356 pub fn as_position_side(&self) -> PositionSide {
1357 match &self {
1358 Self::Long => PositionSide::Long,
1359 Self::Short => PositionSide::Short,
1360 Self::Flat => PositionSide::Flat,
1361 }
1362 }
1363}
1364
1365#[repr(C)]
1367#[derive(
1368 Copy,
1369 Clone,
1370 Debug,
1371 Display,
1372 Hash,
1373 PartialEq,
1374 Eq,
1375 PartialOrd,
1376 Ord,
1377 AsRefStr,
1378 FromRepr,
1379 EnumIter,
1380 EnumString,
1381)]
1382#[strum(ascii_case_insensitive)]
1383#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1384#[cfg_attr(
1385 feature = "python",
1386 pyo3::pyclass(
1387 frozen,
1388 eq,
1389 eq_int,
1390 hash,
1391 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1392 )
1393)]
1394pub enum PriceType {
1395 Bid = 1,
1398 Ask = 2,
1401 Mid = 3,
1403 Last = 4,
1405 Mark = 5,
1408}
1409
1410#[repr(C)]
1412#[derive(
1413 Copy,
1414 Clone,
1415 Debug,
1416 Display,
1417 Hash,
1418 PartialEq,
1419 Eq,
1420 PartialOrd,
1421 Ord,
1422 AsRefStr,
1423 FromRepr,
1424 EnumIter,
1425 EnumString,
1426)]
1427#[strum(ascii_case_insensitive)]
1428#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1429#[cfg_attr(
1430 feature = "python",
1431 pyo3::pyclass(
1432 frozen,
1433 eq,
1434 eq_int,
1435 hash,
1436 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1437 )
1438)]
1439#[allow(non_camel_case_types)]
1440pub enum RecordFlag {
1441 F_LAST = 1 << 7, F_TOB = 1 << 6, F_SNAPSHOT = 1 << 5, F_MBP = 1 << 4, RESERVED_2 = 1 << 3, RESERVED_1 = 1 << 2, }
1454
1455impl RecordFlag {
1456 #[must_use]
1458 pub fn matches(self, value: u8) -> bool {
1459 (self as u8) & value != 0
1460 }
1461}
1462
1463#[repr(C)]
1465#[derive(
1466 Copy,
1467 Clone,
1468 Debug,
1469 Display,
1470 Hash,
1471 PartialEq,
1472 Eq,
1473 PartialOrd,
1474 Ord,
1475 AsRefStr,
1476 FromRepr,
1477 EnumIter,
1478 EnumString,
1479)]
1480#[strum(ascii_case_insensitive)]
1481#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1482#[cfg_attr(
1483 feature = "python",
1484 pyo3::pyclass(
1485 frozen,
1486 eq,
1487 eq_int,
1488 hash,
1489 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1490 )
1491)]
1492pub enum TimeInForce {
1493 Gtc = 1,
1495 Ioc = 2,
1497 Fok = 3,
1499 Gtd = 4,
1501 Day = 5,
1503 AtTheOpen = 6,
1505 AtTheClose = 7,
1507}
1508
1509#[repr(C)]
1511#[derive(
1512 Copy,
1513 Clone,
1514 Debug,
1515 Display,
1516 Hash,
1517 PartialEq,
1518 Eq,
1519 PartialOrd,
1520 Ord,
1521 AsRefStr,
1522 FromRepr,
1523 EnumIter,
1524 EnumString,
1525)]
1526#[strum(ascii_case_insensitive)]
1527#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1528#[cfg_attr(
1529 feature = "python",
1530 pyo3::pyclass(
1531 frozen,
1532 eq,
1533 eq_int,
1534 hash,
1535 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1536 )
1537)]
1538pub enum TradingState {
1539 Active = 1,
1541 Halted = 2,
1543 Reducing = 3,
1545}
1546
1547#[repr(C)]
1549#[derive(
1550 Copy,
1551 Clone,
1552 Debug,
1553 Default,
1554 Display,
1555 Hash,
1556 PartialEq,
1557 Eq,
1558 PartialOrd,
1559 Ord,
1560 AsRefStr,
1561 FromRepr,
1562 EnumIter,
1563 EnumString,
1564)]
1565#[strum(ascii_case_insensitive)]
1566#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1567#[cfg_attr(
1568 feature = "python",
1569 pyo3::pyclass(
1570 frozen,
1571 eq,
1572 eq_int,
1573 hash,
1574 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1575 )
1576)]
1577pub enum TrailingOffsetType {
1578 #[default]
1580 NoTrailingOffset = 0,
1581 Price = 1,
1583 BasisPoints = 2,
1585 Ticks = 3,
1587 PriceTier = 4,
1589}
1590
1591#[repr(C)]
1593#[derive(
1594 Copy,
1595 Clone,
1596 Debug,
1597 Default,
1598 Display,
1599 Hash,
1600 PartialEq,
1601 Eq,
1602 PartialOrd,
1603 Ord,
1604 AsRefStr,
1605 FromRepr,
1606 EnumIter,
1607 EnumString,
1608)]
1609#[strum(ascii_case_insensitive)]
1610#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
1611#[cfg_attr(
1612 feature = "python",
1613 pyo3::pyclass(
1614 frozen,
1615 eq,
1616 eq_int,
1617 hash,
1618 module = "nautilus_trader.core.nautilus_pyo3.model.enums"
1619 )
1620)]
1621pub enum TriggerType {
1622 #[default]
1624 NoTrigger = 0,
1625 Default = 1,
1627 LastPrice = 2,
1629 MarkPrice = 3,
1631 IndexPrice = 4,
1633 BidAsk = 5,
1635 DoubleLast = 6,
1637 DoubleBidAsk = 7,
1639 LastOrBidAsk = 8,
1641 MidPoint = 9,
1643}
1644
1645enum_strum_serde!(AccountType);
1646enum_strum_serde!(AggregationSource);
1647enum_strum_serde!(AggressorSide);
1648enum_strum_serde!(AssetClass);
1649enum_strum_serde!(BarAggregation);
1650enum_strum_serde!(BarIntervalType);
1651enum_strum_serde!(BookAction);
1652enum_strum_serde!(BookType);
1653enum_strum_serde!(ContingencyType);
1654enum_strum_serde!(CurrencyType);
1655enum_strum_serde!(InstrumentClass);
1656enum_strum_serde!(InstrumentCloseType);
1657enum_strum_serde!(LiquiditySide);
1658enum_strum_serde!(MarketStatus);
1659enum_strum_serde!(MarketStatusAction);
1660enum_strum_serde!(OmsType);
1661enum_strum_serde!(OptionKind);
1662enum_strum_serde!(OrderSide);
1663enum_strum_serde!(OrderSideSpecified);
1664enum_strum_serde!(OrderStatus);
1665enum_strum_serde!(OrderType);
1666enum_strum_serde!(PositionAdjustmentType);
1667enum_strum_serde!(PositionSide);
1668enum_strum_serde!(PositionSideSpecified);
1669enum_strum_serde!(PriceType);
1670enum_strum_serde!(RecordFlag);
1671enum_strum_serde!(TimeInForce);
1672enum_strum_serde!(TradingState);
1673enum_strum_serde!(TrailingOffsetType);
1674enum_strum_serde!(TriggerType);