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 submit;
24pub mod submit_list;
25
26use nautilus_model::identifiers::{ClientId, InstrumentId};
27use strum::Display;
28
29// Re-exports
30pub use self::{
31    cancel::CancelOrder, cancel_all::CancelAllOrders, cancel_batch::BatchCancelOrders,
32    modify::ModifyOrder, query::QueryOrder, submit::SubmitOrder, submit_list::SubmitOrderList,
33};
34
35// TODO
36#[allow(clippy::large_enum_variant)]
37#[derive(Clone, Debug, Display)]
38pub enum TradingCommand {
39    SubmitOrder(SubmitOrder),
40    SubmitOrderList(SubmitOrderList),
41    ModifyOrder(ModifyOrder),
42    CancelOrder(CancelOrder),
43    CancelAllOrders(CancelAllOrders),
44    BatchCancelOrders(BatchCancelOrders),
45    QueryOrder(QueryOrder),
46}
47
48impl TradingCommand {
49    #[must_use]
50    pub const fn client_id(&self) -> ClientId {
51        match self {
52            Self::SubmitOrder(command) => command.client_id,
53            Self::SubmitOrderList(command) => command.client_id,
54            Self::ModifyOrder(command) => command.client_id,
55            Self::CancelOrder(command) => command.client_id,
56            Self::CancelAllOrders(command) => command.client_id,
57            Self::BatchCancelOrders(command) => command.client_id,
58            Self::QueryOrder(command) => command.client_id,
59        }
60    }
61
62    #[must_use]
63    pub const fn instrument_id(&self) -> InstrumentId {
64        match self {
65            Self::SubmitOrder(command) => command.instrument_id,
66            Self::SubmitOrderList(command) => command.instrument_id,
67            Self::ModifyOrder(command) => command.instrument_id,
68            Self::CancelOrder(command) => command.instrument_id,
69            Self::CancelAllOrders(command) => command.instrument_id,
70            Self::BatchCancelOrders(command) => command.instrument_id,
71            Self::QueryOrder(command) => command.instrument_id,
72        }
73    }
74}