nautilus_execution/messages/
modify.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::{UnixNanos, UUID4};
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, Default, Serialize, Deserialize, Builder)]
27#[builder(default)]
28#[serde(tag = "type")]
29pub struct ModifyOrder {
30    pub trader_id: TraderId,
31    pub client_id: ClientId,
32    pub strategy_id: StrategyId,
33    pub instrument_id: InstrumentId,
34    pub client_order_id: ClientOrderId,
35    pub venue_order_id: 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}
42
43impl ModifyOrder {
44    /// Creates a new [`ModifyOrder`] instance.
45    #[allow(clippy::too_many_arguments)]
46    pub const fn new(
47        trader_id: TraderId,
48        client_id: ClientId,
49        strategy_id: StrategyId,
50        instrument_id: InstrumentId,
51        client_order_id: ClientOrderId,
52        venue_order_id: VenueOrderId,
53        quantity: Option<Quantity>,
54        price: Option<Price>,
55        trigger_price: Option<Price>,
56        command_id: UUID4,
57        ts_init: UnixNanos,
58    ) -> anyhow::Result<Self> {
59        Ok(Self {
60            trader_id,
61            client_id,
62            strategy_id,
63            instrument_id,
64            client_order_id,
65            venue_order_id,
66            quantity,
67            price,
68            trigger_price,
69            command_id,
70            ts_init,
71        })
72    }
73}
74
75impl Display for ModifyOrder {
76    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77        write!(
78            f,
79            "ModifyOrder(instrument_id={}, client_order_id={}, venue_order_id={}, quantity={}, price={}, trigger_price={})",
80            self.instrument_id, self.client_order_id, self.venue_order_id,
81            self.quantity.map_or("None".to_string(), |quantity| format!("{quantity}")),
82            self.price.map_or("None".to_string(), |price| format!("{price}")),
83            self.trigger_price.map_or("None".to_string(), |trigger_price| format!("{trigger_price}")),
84        )
85    }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89// Tests
90////////////////////////////////////////////////////////////////////////////////
91#[cfg(test)]
92mod tests {}