nautilus_model/events/order/
canceled.rs1use std::fmt::{Debug, Display};
17
18use derive_builder::Builder;
19use nautilus_core::{serialization::from_bool_as_u8, UnixNanos, UUID4};
20use rust_decimal::Decimal;
21use serde::{Deserialize, Serialize};
22use ustr::Ustr;
23
24use crate::{
25 enums::{
26 ContingencyType, LiquiditySide, OrderSide, OrderType, TimeInForce, TrailingOffsetType,
27 TriggerType,
28 },
29 events::OrderEvent,
30 identifiers::{
31 AccountId, ClientOrderId, ExecAlgorithmId, InstrumentId, OrderListId, PositionId,
32 StrategyId, TradeId, TraderId, VenueOrderId,
33 },
34 types::{Currency, Money, Price, Quantity},
35};
36
37#[repr(C)]
39#[derive(Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, Builder)]
40#[builder(default)]
41#[serde(tag = "type")]
42#[cfg_attr(
43 feature = "python",
44 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
45)]
46pub struct OrderCanceled {
47 pub trader_id: TraderId,
49 pub strategy_id: StrategyId,
51 pub instrument_id: InstrumentId,
53 pub client_order_id: ClientOrderId,
55 pub event_id: UUID4,
57 pub ts_event: UnixNanos,
59 pub ts_init: UnixNanos,
61 #[serde(deserialize_with = "from_bool_as_u8")]
63 pub reconciliation: u8, pub venue_order_id: Option<VenueOrderId>,
66 pub account_id: Option<AccountId>,
68}
69
70impl OrderCanceled {
71 #[allow(clippy::too_many_arguments)]
73 pub fn new(
74 trader_id: TraderId,
75 strategy_id: StrategyId,
76 instrument_id: InstrumentId,
77 client_order_id: ClientOrderId,
78 event_id: UUID4,
79 ts_event: UnixNanos,
80 ts_init: UnixNanos,
81 reconciliation: bool,
82 venue_order_id: Option<VenueOrderId>,
83 account_id: Option<AccountId>,
84 ) -> Self {
85 Self {
86 trader_id,
87 strategy_id,
88 instrument_id,
89 client_order_id,
90 event_id,
91 ts_event,
92 ts_init,
93 reconciliation: u8::from(reconciliation),
94 venue_order_id,
95 account_id,
96 }
97 }
98}
99
100impl Debug for OrderCanceled {
101 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102 write!(f,
103 "{}(trader_id={}, strategy_id={}, instrument_id={}, client_order_id={}, venue_order_id={}, account_id={}, event_id={}, ts_event={}, ts_init={})",
104 stringify!(OrderCanceled),
105 self.trader_id,
106 self.strategy_id,
107 self.instrument_id,
108 self.client_order_id,
109 self.venue_order_id.map_or_else(|| "None".to_string(), |venue_order_id| format!("{venue_order_id}")),
110 self.account_id.map_or_else(|| "None".to_string(), |account_id| format!("{account_id}")),
111 self.event_id,
112 self.ts_event,
113 self.ts_init
114 )
115 }
116}
117
118impl Display for OrderCanceled {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 write!(
121 f,
122 "{}(instrument_id={}, client_order_id={}, venue_order_id={}, account_id={}, ts_event={})",
123 stringify!(OrderCanceled),
124 self.instrument_id,
125 self.client_order_id,
126 self.venue_order_id.map_or("None".to_string(), |venue_order_id| format!("{venue_order_id}")),
127 self.account_id.map_or("None".to_string(), |account_id| format!("{account_id}")),
128 self.ts_event
129 )
130 }
131}
132
133impl OrderEvent for OrderCanceled {
134 fn id(&self) -> UUID4 {
135 self.event_id
136 }
137
138 fn kind(&self) -> &str {
139 stringify!(OrderCanceled)
140 }
141
142 fn order_type(&self) -> Option<OrderType> {
143 None
144 }
145
146 fn order_side(&self) -> Option<OrderSide> {
147 None
148 }
149
150 fn trader_id(&self) -> TraderId {
151 self.trader_id
152 }
153
154 fn strategy_id(&self) -> StrategyId {
155 self.strategy_id
156 }
157
158 fn instrument_id(&self) -> InstrumentId {
159 self.instrument_id
160 }
161
162 fn trade_id(&self) -> Option<TradeId> {
163 None
164 }
165
166 fn currency(&self) -> Option<Currency> {
167 None
168 }
169
170 fn client_order_id(&self) -> ClientOrderId {
171 self.client_order_id
172 }
173
174 fn reason(&self) -> Option<Ustr> {
175 None
176 }
177
178 fn quantity(&self) -> Option<Quantity> {
179 None
180 }
181
182 fn time_in_force(&self) -> Option<TimeInForce> {
183 None
184 }
185
186 fn liquidity_side(&self) -> Option<LiquiditySide> {
187 None
188 }
189
190 fn post_only(&self) -> Option<bool> {
191 None
192 }
193
194 fn reduce_only(&self) -> Option<bool> {
195 None
196 }
197
198 fn quote_quantity(&self) -> Option<bool> {
199 None
200 }
201
202 fn reconciliation(&self) -> bool {
203 false
204 }
205
206 fn price(&self) -> Option<Price> {
207 None
208 }
209
210 fn last_px(&self) -> Option<Price> {
211 None
212 }
213
214 fn last_qty(&self) -> Option<Quantity> {
215 None
216 }
217
218 fn trigger_price(&self) -> Option<Price> {
219 None
220 }
221
222 fn trigger_type(&self) -> Option<TriggerType> {
223 None
224 }
225
226 fn limit_offset(&self) -> Option<Decimal> {
227 None
228 }
229
230 fn trailing_offset(&self) -> Option<Decimal> {
231 None
232 }
233
234 fn trailing_offset_type(&self) -> Option<TrailingOffsetType> {
235 None
236 }
237
238 fn expire_time(&self) -> Option<UnixNanos> {
239 None
240 }
241
242 fn display_qty(&self) -> Option<Quantity> {
243 None
244 }
245
246 fn emulation_trigger(&self) -> Option<TriggerType> {
247 None
248 }
249
250 fn trigger_instrument_id(&self) -> Option<InstrumentId> {
251 None
252 }
253
254 fn contingency_type(&self) -> Option<ContingencyType> {
255 None
256 }
257
258 fn order_list_id(&self) -> Option<OrderListId> {
259 None
260 }
261
262 fn linked_order_ids(&self) -> Option<Vec<ClientOrderId>> {
263 None
264 }
265
266 fn parent_order_id(&self) -> Option<ClientOrderId> {
267 None
268 }
269
270 fn exec_algorithm_id(&self) -> Option<ExecAlgorithmId> {
271 None
272 }
273
274 fn exec_spawn_id(&self) -> Option<ClientOrderId> {
275 None
276 }
277
278 fn venue_order_id(&self) -> Option<VenueOrderId> {
279 self.venue_order_id
280 }
281
282 fn account_id(&self) -> Option<AccountId> {
283 self.account_id
284 }
285
286 fn position_id(&self) -> Option<PositionId> {
287 None
288 }
289
290 fn commission(&self) -> Option<Money> {
291 None
292 }
293
294 fn ts_event(&self) -> UnixNanos {
295 self.ts_event
296 }
297
298 fn ts_init(&self) -> UnixNanos {
299 self.ts_init
300 }
301}
302
303#[cfg(test)]
307mod tests {}