nautilus_common/messages/execution/
modify.rs1use 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 #[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 {}