nautilus_execution/messages/
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 cancel_all;
20pub mod cancel_batch;
21pub mod modify;
22pub mod query;
23pub mod reports;
24pub mod submit;
25pub mod submit_list;
26
27use nautilus_core::UnixNanos;
28use nautilus_model::identifiers::{ClientId, InstrumentId};
29use strum::Display;
30
31// Re-exports
32pub use self::{
33    cancel::CancelOrder, cancel_all::CancelAllOrders, cancel_batch::BatchCancelOrders,
34    modify::ModifyOrder, query::QueryOrder, submit::SubmitOrder, submit_list::SubmitOrderList,
35};
36
37// TODO
38#[allow(clippy::large_enum_variant)]
39#[derive(Clone, Debug, Eq, PartialEq, Display)]
40pub enum TradingCommand {
41    SubmitOrder(SubmitOrder),
42    SubmitOrderList(SubmitOrderList),
43    ModifyOrder(ModifyOrder),
44    CancelOrder(CancelOrder),
45    CancelAllOrders(CancelAllOrders),
46    BatchCancelOrders(BatchCancelOrders),
47    QueryOrder(QueryOrder),
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        }
62    }
63
64    #[must_use]
65    pub const fn instrument_id(&self) -> InstrumentId {
66        match self {
67            Self::SubmitOrder(command) => command.instrument_id,
68            Self::SubmitOrderList(command) => command.instrument_id,
69            Self::ModifyOrder(command) => command.instrument_id,
70            Self::CancelOrder(command) => command.instrument_id,
71            Self::CancelAllOrders(command) => command.instrument_id,
72            Self::BatchCancelOrders(command) => command.instrument_id,
73            Self::QueryOrder(command) => command.instrument_id,
74        }
75    }
76
77    #[must_use]
78    pub const fn ts_init(&self) -> UnixNanos {
79        match self {
80            Self::SubmitOrder(command) => command.ts_init,
81            Self::SubmitOrderList(command) => command.ts_init,
82            Self::ModifyOrder(command) => command.ts_init,
83            Self::CancelOrder(command) => command.ts_init,
84            Self::CancelAllOrders(command) => command.ts_init,
85            Self::BatchCancelOrders(command) => command.ts_init,
86            Self::QueryOrder(command) => command.ts_init,
87        }
88    }
89}