nautilus_common/messages/execution/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.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//! Execution specific messages such as order commands.
17
18pub mod cancel;
19pub mod modify;
20pub mod query;
21pub mod report;
22pub mod submit;
23
24// Re-exports
25pub use nautilus_core::Params;
26use nautilus_core::UnixNanos;
27use nautilus_model::{
28    identifiers::{ClientId, InstrumentId, StrategyId},
29    reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
30};
31use strum::Display;
32
33pub use self::{
34    cancel::{BatchCancelOrders, CancelAllOrders, CancelOrder},
35    modify::ModifyOrder,
36    query::{QueryAccount, QueryOrder},
37    report::{
38        GenerateExecutionMassStatus, GenerateFillReports, GenerateOrderStatusReport,
39        GenerateOrderStatusReports, GeneratePositionStatusReports,
40    },
41    submit::{SubmitOrder, SubmitOrderList},
42};
43
44/// Execution report variants for reconciliation.
45#[derive(Clone, Debug, Display)]
46pub enum ExecutionReport {
47    OrderStatus(Box<OrderStatusReport>),
48    Fill(Box<FillReport>),
49    Position(Box<PositionStatusReport>),
50    Mass(Box<ExecutionMassStatus>),
51}
52
53// TODO
54#[allow(clippy::large_enum_variant)]
55#[derive(Clone, Debug, Eq, PartialEq, Display)]
56pub enum TradingCommand {
57    SubmitOrder(SubmitOrder),
58    SubmitOrderList(SubmitOrderList),
59    ModifyOrder(ModifyOrder),
60    CancelOrder(CancelOrder),
61    CancelAllOrders(CancelAllOrders),
62    BatchCancelOrders(BatchCancelOrders),
63    QueryOrder(QueryOrder),
64    QueryAccount(QueryAccount),
65}
66
67impl TradingCommand {
68    #[must_use]
69    pub const fn client_id(&self) -> Option<ClientId> {
70        match self {
71            Self::SubmitOrder(command) => command.client_id,
72            Self::SubmitOrderList(command) => command.client_id,
73            Self::ModifyOrder(command) => command.client_id,
74            Self::CancelOrder(command) => command.client_id,
75            Self::CancelAllOrders(command) => command.client_id,
76            Self::BatchCancelOrders(command) => command.client_id,
77            Self::QueryOrder(command) => command.client_id,
78            Self::QueryAccount(command) => command.client_id,
79        }
80    }
81
82    /// Returns the instrument ID for the command.
83    ///
84    /// # Panics
85    ///
86    /// Panics if the command is `QueryAccount` which does not have an instrument ID.
87    #[must_use]
88    pub const fn instrument_id(&self) -> InstrumentId {
89        match self {
90            Self::SubmitOrder(command) => command.instrument_id,
91            Self::SubmitOrderList(command) => command.instrument_id,
92            Self::ModifyOrder(command) => command.instrument_id,
93            Self::CancelOrder(command) => command.instrument_id,
94            Self::CancelAllOrders(command) => command.instrument_id,
95            Self::BatchCancelOrders(command) => command.instrument_id,
96            Self::QueryOrder(command) => command.instrument_id,
97            Self::QueryAccount(_) => panic!("No instrument ID for command"),
98        }
99    }
100
101    #[must_use]
102    pub const fn ts_init(&self) -> UnixNanos {
103        match self {
104            Self::SubmitOrder(command) => command.ts_init,
105            Self::SubmitOrderList(command) => command.ts_init,
106            Self::ModifyOrder(command) => command.ts_init,
107            Self::CancelOrder(command) => command.ts_init,
108            Self::CancelAllOrders(command) => command.ts_init,
109            Self::BatchCancelOrders(command) => command.ts_init,
110            Self::QueryOrder(command) => command.ts_init,
111            Self::QueryAccount(command) => command.ts_init,
112        }
113    }
114
115    #[must_use]
116    pub const fn strategy_id(&self) -> Option<StrategyId> {
117        match self {
118            Self::SubmitOrder(command) => Some(command.strategy_id),
119            Self::SubmitOrderList(command) => Some(command.strategy_id),
120            Self::ModifyOrder(command) => Some(command.strategy_id),
121            Self::CancelOrder(command) => Some(command.strategy_id),
122            Self::CancelAllOrders(command) => Some(command.strategy_id),
123            Self::BatchCancelOrders(command) => Some(command.strategy_id),
124            Self::QueryOrder(command) => Some(command.strategy_id),
125            Self::QueryAccount(_) => None,
126        }
127    }
128}