nautilus_common/messages/execution/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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::QueryOrder, report::GenerateFillReports, report::GenerateOrderStatusReport,
32    report::GeneratePositionReports, submit::SubmitOrder, submit::SubmitOrderList,
33};
34
35// TODO
36#[allow(clippy::large_enum_variant)]
37#[derive(Clone, Debug, Eq, PartialEq, 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
75    #[must_use]
76    pub const fn ts_init(&self) -> UnixNanos {
77        match self {
78            Self::SubmitOrder(command) => command.ts_init,
79            Self::SubmitOrderList(command) => command.ts_init,
80            Self::ModifyOrder(command) => command.ts_init,
81            Self::CancelOrder(command) => command.ts_init,
82            Self::CancelAllOrders(command) => command.ts_init,
83            Self::BatchCancelOrders(command) => command.ts_init,
84            Self::QueryOrder(command) => command.ts_init,
85        }
86    }
87}