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::identifiers::{ClientId, InstrumentId};
26use strum::Display;
27
28// Re-exports
29pub use self::{
30    cancel::BatchCancelOrders, cancel::CancelAllOrders, cancel::CancelOrder, modify::ModifyOrder,
31    query::QueryAccount, query::QueryOrder, report::GenerateFillReports,
32    report::GenerateOrderStatusReport, report::GeneratePositionReports, submit::SubmitOrder,
33    submit::SubmitOrderList,
34};
35
36// TODO
37#[allow(clippy::large_enum_variant)]
38#[derive(Clone, Debug, Eq, PartialEq, Display)]
39pub enum TradingCommand {
40    SubmitOrder(SubmitOrder),
41    SubmitOrderList(SubmitOrderList),
42    ModifyOrder(ModifyOrder),
43    CancelOrder(CancelOrder),
44    CancelAllOrders(CancelAllOrders),
45    BatchCancelOrders(BatchCancelOrders),
46    QueryOrder(QueryOrder),
47    QueryAccount(QueryAccount),
48}
49
50impl TradingCommand {
51    #[must_use]
52    pub const fn client_id(&self) -> ClientId {
53        match self {
54            Self::SubmitOrder(command) => command.client_id,
55            Self::SubmitOrderList(command) => command.client_id,
56            Self::ModifyOrder(command) => command.client_id,
57            Self::CancelOrder(command) => command.client_id,
58            Self::CancelAllOrders(command) => command.client_id,
59            Self::BatchCancelOrders(command) => command.client_id,
60            Self::QueryOrder(command) => command.client_id,
61            Self::QueryAccount(command) => command.client_id,
62        }
63    }
64
65    #[must_use]
66    pub const fn instrument_id(&self) -> InstrumentId {
67        match self {
68            Self::SubmitOrder(command) => command.instrument_id,
69            Self::SubmitOrderList(command) => command.instrument_id,
70            Self::ModifyOrder(command) => command.instrument_id,
71            Self::CancelOrder(command) => command.instrument_id,
72            Self::CancelAllOrders(command) => command.instrument_id,
73            Self::BatchCancelOrders(command) => command.instrument_id,
74            Self::QueryOrder(command) => command.instrument_id,
75            Self::QueryAccount(_) => panic!("No instrument ID for command"),
76        }
77    }
78
79    #[must_use]
80    pub const fn ts_init(&self) -> UnixNanos {
81        match self {
82            Self::SubmitOrder(command) => command.ts_init,
83            Self::SubmitOrderList(command) => command.ts_init,
84            Self::ModifyOrder(command) => command.ts_init,
85            Self::CancelOrder(command) => command.ts_init,
86            Self::CancelAllOrders(command) => command.ts_init,
87            Self::BatchCancelOrders(command) => command.ts_init,
88            Self::QueryOrder(command) => command.ts_init,
89            Self::QueryAccount(command) => command.ts_init,
90        }
91    }
92}