Skip to main content

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, GenerateExecutionMassStatusBuilder, GenerateFillReports,
39        GenerateFillReportsBuilder, GenerateOrderStatusReport, GenerateOrderStatusReportBuilder,
40        GenerateOrderStatusReports, GenerateOrderStatusReportsBuilder,
41        GeneratePositionStatusReports, GeneratePositionStatusReportsBuilder,
42    },
43    submit::{SubmitOrder, SubmitOrderList},
44};
45
46/// Execution report variants for reconciliation.
47#[derive(Clone, Debug, Display)]
48pub enum ExecutionReport {
49    Order(Box<OrderStatusReport>),
50    Fill(Box<FillReport>),
51    Position(Box<PositionStatusReport>),
52    MassStatus(Box<ExecutionMassStatus>),
53}
54
55// TODO
56#[allow(clippy::large_enum_variant)]
57#[derive(Clone, Debug, Eq, PartialEq, Display)]
58pub enum TradingCommand {
59    SubmitOrder(SubmitOrder),
60    SubmitOrderList(SubmitOrderList),
61    ModifyOrder(ModifyOrder),
62    CancelOrder(CancelOrder),
63    CancelAllOrders(CancelAllOrders),
64    BatchCancelOrders(BatchCancelOrders),
65    QueryOrder(QueryOrder),
66    QueryAccount(QueryAccount),
67}
68
69impl TradingCommand {
70    #[must_use]
71    pub const fn client_id(&self) -> Option<ClientId> {
72        match self {
73            Self::SubmitOrder(command) => command.client_id,
74            Self::SubmitOrderList(command) => command.client_id,
75            Self::ModifyOrder(command) => command.client_id,
76            Self::CancelOrder(command) => command.client_id,
77            Self::CancelAllOrders(command) => command.client_id,
78            Self::BatchCancelOrders(command) => command.client_id,
79            Self::QueryOrder(command) => command.client_id,
80            Self::QueryAccount(command) => command.client_id,
81        }
82    }
83
84    /// Returns the instrument ID for the command.
85    ///
86    /// # Panics
87    ///
88    /// Panics if the command is `QueryAccount` which does not have an instrument ID.
89    #[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::CancelOrder(command) => command.instrument_id,
96            Self::CancelAllOrders(command) => command.instrument_id,
97            Self::BatchCancelOrders(command) => command.instrument_id,
98            Self::QueryOrder(command) => command.instrument_id,
99            Self::QueryAccount(_) => panic!("No instrument ID for command"),
100        }
101    }
102
103    #[must_use]
104    pub const fn ts_init(&self) -> UnixNanos {
105        match self {
106            Self::SubmitOrder(command) => command.ts_init,
107            Self::SubmitOrderList(command) => command.ts_init,
108            Self::ModifyOrder(command) => command.ts_init,
109            Self::CancelOrder(command) => command.ts_init,
110            Self::CancelAllOrders(command) => command.ts_init,
111            Self::BatchCancelOrders(command) => command.ts_init,
112            Self::QueryOrder(command) => command.ts_init,
113            Self::QueryAccount(command) => command.ts_init,
114        }
115    }
116
117    #[must_use]
118    pub const fn strategy_id(&self) -> Option<StrategyId> {
119        match self {
120            Self::SubmitOrder(command) => Some(command.strategy_id),
121            Self::SubmitOrderList(command) => Some(command.strategy_id),
122            Self::ModifyOrder(command) => Some(command.strategy_id),
123            Self::CancelOrder(command) => Some(command.strategy_id),
124            Self::CancelAllOrders(command) => Some(command.strategy_id),
125            Self::BatchCancelOrders(command) => Some(command.strategy_id),
126            Self::QueryOrder(command) => Some(command.strategy_id),
127            Self::QueryAccount(_) => None,
128        }
129    }
130}