nautilus_common/messages/execution/
modify.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
16use std::fmt::Display;
17
18use derive_builder::Builder;
19use nautilus_core::{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, 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    ///
46    /// # Errors
47    ///
48    /// Returns an error if parameters are invalid.
49    #[allow(clippy::too_many_arguments)]
50    pub const fn new(
51        trader_id: TraderId,
52        client_id: ClientId,
53        strategy_id: StrategyId,
54        instrument_id: InstrumentId,
55        client_order_id: ClientOrderId,
56        venue_order_id: VenueOrderId,
57        quantity: Option<Quantity>,
58        price: Option<Price>,
59        trigger_price: Option<Price>,
60        command_id: UUID4,
61        ts_init: UnixNanos,
62    ) -> anyhow::Result<Self> {
63        Ok(Self {
64            trader_id,
65            client_id,
66            strategy_id,
67            instrument_id,
68            client_order_id,
69            venue_order_id,
70            quantity,
71            price,
72            trigger_price,
73            command_id,
74            ts_init,
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////////////////////////////////////////////////////////////////////////////////
100// Tests
101////////////////////////////////////////////////////////////////////////////////
102#[cfg(test)]
103mod tests {}