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::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)]
56#[derive(Clone, Debug, Eq, PartialEq, Display)]
57pub enum TradingCommand {
58 SubmitOrder(SubmitOrder),
59 SubmitOrderList(SubmitOrderList),
60 ModifyOrder(ModifyOrder),
61 CancelOrder(CancelOrder),
62 CancelAllOrders(CancelAllOrders),
63 BatchCancelOrders(BatchCancelOrders),
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::CancelOrder(command) => command.client_id,
76 Self::CancelAllOrders(command) => command.client_id,
77 Self::BatchCancelOrders(command) => command.client_id,
78 Self::QueryOrder(command) => command.client_id,
79 Self::QueryAccount(command) => command.client_id,
80 }
81 }
82
83 #[must_use]
89 pub const fn instrument_id(&self) -> InstrumentId {
90 match self {
91 Self::SubmitOrder(command) => command.instrument_id,
92 Self::SubmitOrderList(command) => command.instrument_id,
93 Self::ModifyOrder(command) => command.instrument_id,
94 Self::CancelOrder(command) => command.instrument_id,
95 Self::CancelAllOrders(command) => command.instrument_id,
96 Self::BatchCancelOrders(command) => command.instrument_id,
97 Self::QueryOrder(command) => command.instrument_id,
98 Self::QueryAccount(_) => panic!("No instrument ID for command"),
99 }
100 }
101
102 #[must_use]
103 pub const fn ts_init(&self) -> UnixNanos {
104 match self {
105 Self::SubmitOrder(command) => command.ts_init,
106 Self::SubmitOrderList(command) => command.ts_init,
107 Self::ModifyOrder(command) => command.ts_init,
108 Self::CancelOrder(command) => command.ts_init,
109 Self::CancelAllOrders(command) => command.ts_init,
110 Self::BatchCancelOrders(command) => command.ts_init,
111 Self::QueryOrder(command) => command.ts_init,
112 Self::QueryAccount(command) => command.ts_init,
113 }
114 }
115
116 #[must_use]
117 pub const fn strategy_id(&self) -> Option<StrategyId> {
118 match self {
119 Self::SubmitOrder(command) => Some(command.strategy_id),
120 Self::SubmitOrderList(command) => Some(command.strategy_id),
121 Self::ModifyOrder(command) => Some(command.strategy_id),
122 Self::CancelOrder(command) => Some(command.strategy_id),
123 Self::CancelAllOrders(command) => Some(command.strategy_id),
124 Self::BatchCancelOrders(command) => Some(command.strategy_id),
125 Self::QueryOrder(command) => Some(command.strategy_id),
126 Self::QueryAccount(_) => None,
127 }
128 }
129
130 #[must_use]
131 pub const fn params(&self) -> Option<&Params> {
132 match self {
133 Self::SubmitOrder(command) => command.params.as_ref(),
134 Self::SubmitOrderList(command) => command.params.as_ref(),
135 Self::ModifyOrder(command) => command.params.as_ref(),
136 Self::CancelOrder(command) => command.params.as_ref(),
137 Self::CancelAllOrders(command) => command.params.as_ref(),
138 Self::BatchCancelOrders(command) => command.params.as_ref(),
139 Self::QueryOrder(command) => command.params.as_ref(),
140 Self::QueryAccount(command) => command.params.as_ref(),
141 }
142 }
143}