nautilus_common/messages/execution/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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
24use nautilus_core::UnixNanos;
25use nautilus_model::{
26    identifiers::{ClientId, InstrumentId},
27    reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
28};
29use strum::Display;
30
31// Re-exports
32pub use self::{
33    cancel::BatchCancelOrders, cancel::CancelAllOrders, cancel::CancelOrder, modify::ModifyOrder,
34    query::QueryAccount, query::QueryOrder, report::GenerateFillReports,
35    report::GenerateOrderStatusReport, report::GeneratePositionReports, submit::SubmitOrder,
36    submit::SubmitOrderList,
37};
38
39/// Execution report variants for reconciliation.
40#[derive(Clone, Debug, Display)]
41pub enum ExecutionReport {
42    OrderStatus(Box<OrderStatusReport>),
43    Fill(Box<FillReport>),
44    Position(Box<PositionStatusReport>),
45    Mass(Box<ExecutionMassStatus>),
46}
47
48// TODO
49#[allow(clippy::large_enum_variant)]
50#[derive(Clone, Debug, Eq, PartialEq, Display)]
51pub enum TradingCommand {
52    SubmitOrder(SubmitOrder),
53    SubmitOrderList(SubmitOrderList),
54    ModifyOrder(ModifyOrder),
55    CancelOrder(CancelOrder),
56    CancelAllOrders(CancelAllOrders),
57    BatchCancelOrders(BatchCancelOrders),
58    QueryOrder(QueryOrder),
59    QueryAccount(QueryAccount),
60}
61
62impl TradingCommand {
63    #[must_use]
64    pub const fn client_id(&self) -> ClientId {
65        match self {
66            Self::SubmitOrder(command) => command.client_id,
67            Self::SubmitOrderList(command) => command.client_id,
68            Self::ModifyOrder(command) => command.client_id,
69            Self::CancelOrder(command) => command.client_id,
70            Self::CancelAllOrders(command) => command.client_id,
71            Self::BatchCancelOrders(command) => command.client_id,
72            Self::QueryOrder(command) => command.client_id,
73            Self::QueryAccount(command) => command.client_id,
74        }
75    }
76
77    /// Returns the instrument ID for the command.
78    ///
79    /// # Panics
80    ///
81    /// Panics if the command is `QueryAccount` which does not have an instrument ID.
82    #[must_use]
83    pub const fn instrument_id(&self) -> InstrumentId {
84        match self {
85            Self::SubmitOrder(command) => command.instrument_id,
86            Self::SubmitOrderList(command) => command.instrument_id,
87            Self::ModifyOrder(command) => command.instrument_id,
88            Self::CancelOrder(command) => command.instrument_id,
89            Self::CancelAllOrders(command) => command.instrument_id,
90            Self::BatchCancelOrders(command) => command.instrument_id,
91            Self::QueryOrder(command) => command.instrument_id,
92            Self::QueryAccount(_) => panic!("No instrument ID for command"),
93        }
94    }
95
96    #[must_use]
97    pub const fn ts_init(&self) -> UnixNanos {
98        match self {
99            Self::SubmitOrder(command) => command.ts_init,
100            Self::SubmitOrderList(command) => command.ts_init,
101            Self::ModifyOrder(command) => command.ts_init,
102            Self::CancelOrder(command) => command.ts_init,
103            Self::CancelAllOrders(command) => command.ts_init,
104            Self::BatchCancelOrders(command) => command.ts_init,
105            Self::QueryOrder(command) => command.ts_init,
106            Self::QueryAccount(command) => command.ts_init,
107        }
108    }
109}