nautilus_common/messages/execution/
cancel.rs1use std::fmt::Display;
17
18use derive_builder::Builder;
19use indexmap::IndexMap;
20use nautilus_core::{UUID4, UnixNanos};
21use nautilus_model::{
22 enums::OrderSide,
23 identifiers::{ClientId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
24};
25use serde::{Deserialize, Serialize};
26
27#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
28#[serde(tag = "type")]
29pub struct CancelOrder {
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 command_id: UUID4,
37 pub ts_init: UnixNanos,
38 pub params: Option<IndexMap<String, String>>,
39}
40
41impl CancelOrder {
42 #[allow(clippy::too_many_arguments)]
44 #[must_use]
45 pub fn new(
46 trader_id: TraderId,
47 client_id: Option<ClientId>,
48 strategy_id: StrategyId,
49 instrument_id: InstrumentId,
50 client_order_id: ClientOrderId,
51 venue_order_id: Option<VenueOrderId>,
52 command_id: UUID4,
53 ts_init: UnixNanos,
54 params: Option<IndexMap<String, String>>,
55 ) -> Self {
56 Self {
57 trader_id,
58 client_id,
59 strategy_id,
60 instrument_id,
61 client_order_id,
62 venue_order_id,
63 command_id,
64 ts_init,
65 params,
66 }
67 }
68}
69
70impl Display for CancelOrder {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 write!(
73 f,
74 "CancelOrder(instrument_id={}, client_order_id={}, venue_order_id={:?})",
75 self.instrument_id, self.client_order_id, self.venue_order_id,
76 )
77 }
78}
79
80#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
81#[serde(tag = "type")]
82pub struct CancelAllOrders {
83 pub trader_id: TraderId,
84 pub client_id: Option<ClientId>,
85 pub strategy_id: StrategyId,
86 pub instrument_id: InstrumentId,
87 pub order_side: OrderSide,
88 pub command_id: UUID4,
89 pub ts_init: UnixNanos,
90 pub params: Option<IndexMap<String, String>>,
91}
92
93impl CancelAllOrders {
94 #[allow(clippy::too_many_arguments)]
96 #[must_use]
97 pub fn new(
98 trader_id: TraderId,
99 client_id: Option<ClientId>,
100 strategy_id: StrategyId,
101 instrument_id: InstrumentId,
102 order_side: OrderSide,
103 command_id: UUID4,
104 ts_init: UnixNanos,
105 params: Option<IndexMap<String, String>>,
106 ) -> Self {
107 Self {
108 trader_id,
109 client_id,
110 strategy_id,
111 instrument_id,
112 order_side,
113 command_id,
114 ts_init,
115 params,
116 }
117 }
118}
119
120impl Display for CancelAllOrders {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 write!(
123 f,
124 "CancelAllOrders(instrument_id={}, order_side={})",
125 self.instrument_id, self.order_side,
126 )
127 }
128}
129
130#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
131#[serde(tag = "type")]
132pub struct BatchCancelOrders {
133 pub trader_id: TraderId,
134 pub client_id: Option<ClientId>,
135 pub strategy_id: StrategyId,
136 pub instrument_id: InstrumentId,
137 pub cancels: Vec<CancelOrder>,
138 pub command_id: UUID4,
139 pub ts_init: UnixNanos,
140 pub params: Option<IndexMap<String, String>>,
141}
142
143impl BatchCancelOrders {
144 #[allow(clippy::too_many_arguments)]
146 #[must_use]
147 pub fn new(
148 trader_id: TraderId,
149 client_id: Option<ClientId>,
150 strategy_id: StrategyId,
151 instrument_id: InstrumentId,
152 cancels: Vec<CancelOrder>,
153 command_id: UUID4,
154 ts_init: UnixNanos,
155 params: Option<IndexMap<String, String>>,
156 ) -> Self {
157 Self {
158 trader_id,
159 client_id,
160 strategy_id,
161 instrument_id,
162 cancels,
163 command_id,
164 ts_init,
165 params,
166 }
167 }
168}
169
170impl Display for BatchCancelOrders {
171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
172 write!(
173 f,
174 "BatchCancelOrders(instrument_id={}, cancels=TBD)",
175 self.instrument_id,
176 )
177 }
178}
179
180#[cfg(test)]
181mod tests {}