nautilus_common/messages/execution/
modify.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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 indexmap::IndexMap;
20use nautilus_core::{UUID4, UnixNanos};
21use nautilus_model::{
22    identifiers::{ClientId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
23    types::{Price, Quantity},
24};
25use serde::{Deserialize, Serialize};
26
27#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
28#[serde(tag = "type")]
29pub struct ModifyOrder {
30    pub trader_id: TraderId,
31    pub client_id: Option<ClientId>,
32    pub strategy_id: StrategyId,
33    pub instrument_id: InstrumentId,
34    pub client_order_id: ClientOrderId,
35    pub venue_order_id: Option<VenueOrderId>,
36    pub quantity: Option<Quantity>,
37    pub price: Option<Price>,
38    pub trigger_price: Option<Price>,
39    pub command_id: UUID4,
40    pub ts_init: UnixNanos,
41    pub params: Option<IndexMap<String, String>>,
42}
43
44impl ModifyOrder {
45    /// Creates a new [`ModifyOrder`] instance.
46    #[allow(clippy::too_many_arguments)]
47    #[must_use]
48    pub fn new(
49        trader_id: TraderId,
50        client_id: Option<ClientId>,
51        strategy_id: StrategyId,
52        instrument_id: InstrumentId,
53        client_order_id: ClientOrderId,
54        venue_order_id: Option<VenueOrderId>,
55        quantity: Option<Quantity>,
56        price: Option<Price>,
57        trigger_price: Option<Price>,
58        command_id: UUID4,
59        ts_init: UnixNanos,
60        params: Option<IndexMap<String, String>>,
61    ) -> Self {
62        Self {
63            trader_id,
64            client_id,
65            strategy_id,
66            instrument_id,
67            client_order_id,
68            venue_order_id,
69            quantity,
70            price,
71            trigger_price,
72            command_id,
73            ts_init,
74            params,
75        }
76    }
77}
78
79impl Display for ModifyOrder {
80    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        write!(
82            f,
83            "ModifyOrder(instrument_id={}, client_order_id={}, venue_order_id={:?}, quantity={}, price={}, trigger_price={})",
84            self.instrument_id,
85            self.client_order_id,
86            self.venue_order_id,
87            self.quantity
88                .map_or("None".to_string(), |quantity| format!("{quantity}")),
89            self.price
90                .map_or("None".to_string(), |price| format!("{price}")),
91            self.trigger_price
92                .map_or("None".to_string(), |trigger_price| format!(
93                    "{trigger_price}"
94                )),
95        )
96    }
97}
98
99#[cfg(test)]
100mod tests {}