nautilus_common/messages/execution/
mod.rs1pub mod cancel;
19pub mod modify;
20pub mod query;
21pub mod report;
22pub mod submit;
23
24use nautilus_core::{Params, UnixNanos};
25use nautilus_model::{
26 identifiers::{ClientId, InstrumentId, StrategyId},
27 reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
28};
29use strum::Display;
30
31pub use self::{
32 cancel::{BatchCancelOrders, CancelAllOrders, CancelOrder},
33 modify::{BatchModifyOrders, ModifyOrder},
34 query::{QueryAccount, QueryOrder},
35 report::{
36 GenerateExecutionMassStatus, GenerateExecutionMassStatusBuilder, GenerateFillReports,
37 GenerateFillReportsBuilder, GenerateOrderStatusReport, GenerateOrderStatusReportBuilder,
38 GenerateOrderStatusReports, GenerateOrderStatusReportsBuilder,
39 GeneratePositionStatusReports, GeneratePositionStatusReportsBuilder,
40 },
41 submit::{SubmitOrder, SubmitOrderList},
42};
43
44#[derive(Clone, Debug, Display)]
46pub enum ExecutionReport {
47 Order(Box<OrderStatusReport>),
48 Fill(Box<FillReport>),
49 OrderWithFills(Box<OrderStatusReport>, Vec<FillReport>),
50 Position(Box<PositionStatusReport>),
51 MassStatus(Box<ExecutionMassStatus>),
52}
53
54#[expect(clippy::large_enum_variant)]
55#[derive(Clone, Debug, Eq, PartialEq, Display)]
56pub enum TradingCommand {
57 SubmitOrder(SubmitOrder),
58 SubmitOrderList(SubmitOrderList),
59 ModifyOrder(ModifyOrder),
60 ModifyOrders(BatchModifyOrders),
61 CancelOrder(CancelOrder),
62 CancelOrders(BatchCancelOrders),
63 CancelAllOrders(CancelAllOrders),
64 QueryOrder(QueryOrder),
65 QueryAccount(QueryAccount),
66}
67
68impl TradingCommand {
69 #[must_use]
70 pub const fn client_id(&self) -> Option<ClientId> {
71 match self {
72 Self::SubmitOrder(command) => command.client_id,
73 Self::SubmitOrderList(command) => command.client_id,
74 Self::ModifyOrder(command) => command.client_id,
75 Self::ModifyOrders(command) => command.client_id,
76 Self::CancelOrder(command) => command.client_id,
77 Self::CancelOrders(command) => command.client_id,
78 Self::CancelAllOrders(command) => command.client_id,
79 Self::QueryOrder(command) => command.client_id,
80 Self::QueryAccount(command) => command.client_id,
81 }
82 }
83
84 #[must_use]
90 pub const fn instrument_id(&self) -> InstrumentId {
91 match self {
92 Self::SubmitOrder(command) => command.instrument_id,
93 Self::SubmitOrderList(command) => command.instrument_id,
94 Self::ModifyOrder(command) => command.instrument_id,
95 Self::ModifyOrders(command) => command.instrument_id,
96 Self::CancelOrder(command) => command.instrument_id,
97 Self::CancelOrders(command) => command.instrument_id,
98 Self::CancelAllOrders(command) => command.instrument_id,
99 Self::QueryOrder(command) => command.instrument_id,
100 Self::QueryAccount(_) => panic!("No instrument ID for command"),
101 }
102 }
103
104 #[must_use]
105 pub const fn ts_init(&self) -> UnixNanos {
106 match self {
107 Self::SubmitOrder(command) => command.ts_init,
108 Self::SubmitOrderList(command) => command.ts_init,
109 Self::ModifyOrder(command) => command.ts_init,
110 Self::ModifyOrders(command) => command.ts_init,
111 Self::CancelOrder(command) => command.ts_init,
112 Self::CancelOrders(command) => command.ts_init,
113 Self::CancelAllOrders(command) => command.ts_init,
114 Self::QueryOrder(command) => command.ts_init,
115 Self::QueryAccount(command) => command.ts_init,
116 }
117 }
118
119 #[must_use]
120 pub const fn strategy_id(&self) -> Option<StrategyId> {
121 match self {
122 Self::SubmitOrder(command) => Some(command.strategy_id),
123 Self::SubmitOrderList(command) => Some(command.strategy_id),
124 Self::ModifyOrder(command) => Some(command.strategy_id),
125 Self::ModifyOrders(command) => Some(command.strategy_id),
126 Self::CancelOrder(command) => Some(command.strategy_id),
127 Self::CancelOrders(command) => Some(command.strategy_id),
128 Self::CancelAllOrders(command) => Some(command.strategy_id),
129 Self::QueryOrder(command) => Some(command.strategy_id),
130 Self::QueryAccount(_) => None,
131 }
132 }
133
134 #[must_use]
135 pub const fn params(&self) -> Option<&Params> {
136 match self {
137 Self::SubmitOrder(command) => command.params.as_ref(),
138 Self::SubmitOrderList(command) => command.params.as_ref(),
139 Self::ModifyOrder(command) => command.params.as_ref(),
140 Self::ModifyOrders(command) => command.params.as_ref(),
141 Self::CancelOrder(command) => command.params.as_ref(),
142 Self::CancelOrders(command) => command.params.as_ref(),
143 Self::CancelAllOrders(command) => command.params.as_ref(),
144 Self::QueryOrder(command) => command.params.as_ref(),
145 Self::QueryAccount(command) => command.params.as_ref(),
146 }
147 }
148}