Skip to main content

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