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