nautilus_execution/messages/
cancel_all.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
16use std::fmt::Display;
17
18use derive_builder::Builder;
19use nautilus_core::{UUID4, UnixNanos};
20use nautilus_model::{
21    enums::OrderSide,
22    identifiers::{ClientId, InstrumentId, StrategyId, TraderId},
23};
24use serde::{Deserialize, Serialize};
25
26#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Builder)]
27#[builder(default)]
28#[serde(tag = "type")]
29pub struct CancelAllOrders {
30    pub trader_id: TraderId,
31    pub client_id: ClientId,
32    pub strategy_id: StrategyId,
33    pub instrument_id: InstrumentId,
34    pub order_side: OrderSide,
35    pub command_id: UUID4,
36    pub ts_init: UnixNanos,
37}
38
39impl CancelAllOrders {
40    /// Creates a new [`CancelAllOrders`] instance.
41    #[allow(clippy::too_many_arguments)]
42    pub const fn new(
43        trader_id: TraderId,
44        client_id: ClientId,
45        strategy_id: StrategyId,
46        instrument_id: InstrumentId,
47        order_side: OrderSide,
48        command_id: UUID4,
49        ts_init: UnixNanos,
50    ) -> anyhow::Result<Self> {
51        Ok(Self {
52            trader_id,
53            client_id,
54            strategy_id,
55            instrument_id,
56            order_side,
57            command_id,
58            ts_init,
59        })
60    }
61}
62
63impl Display for CancelAllOrders {
64    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65        write!(
66            f,
67            "CancelAllOrders(instrument_id={}, order_side={})",
68            self.instrument_id, self.order_side,
69        )
70    }
71}
72
73////////////////////////////////////////////////////////////////////////////////
74// Tests
75////////////////////////////////////////////////////////////////////////////////
76#[cfg(test)]
77mod tests {}