nautilus_model/events/order/
modify_rejected.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)]
40#[derive(Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, Builder)]
41#[builder(default)]
42#[serde(tag = "type")]
43#[cfg_attr(
44 feature = "python",
45 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
46)]
47pub struct OrderModifyRejected {
48 pub trader_id: TraderId,
50 pub strategy_id: StrategyId,
52 pub instrument_id: InstrumentId,
54 pub client_order_id: ClientOrderId,
56 pub reason: Ustr,
58 pub event_id: UUID4,
60 pub ts_event: UnixNanos,
62 pub ts_init: UnixNanos,
64 #[serde(deserialize_with = "from_bool_as_u8")]
66 pub reconciliation: u8, pub venue_order_id: Option<VenueOrderId>,
69 pub account_id: Option<AccountId>,
71}
72
73impl OrderModifyRejected {
74 #[allow(clippy::too_many_arguments)]
76 pub fn new(
77 trader_id: TraderId,
78 strategy_id: StrategyId,
79 instrument_id: InstrumentId,
80 client_order_id: ClientOrderId,
81 reason: Ustr,
82 event_id: UUID4,
83 ts_event: UnixNanos,
84 ts_init: UnixNanos,
85 reconciliation: bool,
86 venue_order_id: Option<VenueOrderId>,
87 account_id: Option<AccountId>,
88 ) -> Self {
89 Self {
90 trader_id,
91 strategy_id,
92 instrument_id,
93 client_order_id,
94 reason,
95 event_id,
96 ts_event,
97 ts_init,
98 reconciliation: u8::from(reconciliation),
99 venue_order_id,
100 account_id,
101 }
102 }
103}
104
105impl Debug for OrderModifyRejected {
106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 write!(f,
108 "{}(trader_id={}, strategy_id={}, instrument_id={}, client_order_id={}, venue_order_id={}, account_id={}, reason='{}', event_id={}, ts_event={}, ts_init={})",
109 stringify!(OrderModifyRejected),
110 self.trader_id,
111 self.strategy_id,
112 self.instrument_id,
113 self.client_order_id,
114 self.venue_order_id.map_or("None".to_string(), |venue_order_id| format!("{venue_order_id}")),
115 self.account_id.map_or("None".to_string(), |account_id| format!("{account_id}")),
116 self.reason,
117 self.event_id,
118 self.ts_event,
119 self.ts_init
120 )
121 }
122}
123
124impl Display for OrderModifyRejected {
125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126 write!(
127 f,
128 "{}(instrument_id={}, client_order_id={}, venue_order_id={}, account_id={}, reason='{}', ts_event={})",
129 stringify!(OrderModifyRejected),
130 self.instrument_id,
131 self.client_order_id,
132 self.venue_order_id.map_or("None".to_string(), |venue_order_id| format!("{venue_order_id}")),
133 self.account_id.map_or("None".to_string(), |account_id| format!("{account_id}")),
134 self.reason,
135 self.ts_event
136 )
137 }
138}
139
140impl OrderEvent for OrderModifyRejected {
141 fn id(&self) -> UUID4 {
142 self.event_id
143 }
144
145 fn kind(&self) -> &str {
146 stringify!(OrderModifyRejected)
147 }
148
149 fn order_type(&self) -> Option<OrderType> {
150 None
151 }
152
153 fn order_side(&self) -> Option<OrderSide> {
154 None
155 }
156
157 fn trader_id(&self) -> TraderId {
158 self.trader_id
159 }
160
161 fn strategy_id(&self) -> StrategyId {
162 self.strategy_id
163 }
164
165 fn instrument_id(&self) -> InstrumentId {
166 self.instrument_id
167 }
168
169 fn trade_id(&self) -> Option<TradeId> {
170 None
171 }
172
173 fn currency(&self) -> Option<Currency> {
174 None
175 }
176
177 fn client_order_id(&self) -> ClientOrderId {
178 self.client_order_id
179 }
180
181 fn reason(&self) -> Option<Ustr> {
182 Some(self.reason)
183 }
184
185 fn quantity(&self) -> Option<Quantity> {
186 None
187 }
188
189 fn time_in_force(&self) -> Option<TimeInForce> {
190 None
191 }
192
193 fn liquidity_side(&self) -> Option<LiquiditySide> {
194 None
195 }
196
197 fn post_only(&self) -> Option<bool> {
198 None
199 }
200
201 fn reduce_only(&self) -> Option<bool> {
202 None
203 }
204
205 fn quote_quantity(&self) -> Option<bool> {
206 None
207 }
208
209 fn reconciliation(&self) -> bool {
210 false
211 }
212
213 fn price(&self) -> Option<Price> {
214 None
215 }
216
217 fn last_px(&self) -> Option<Price> {
218 None
219 }
220
221 fn last_qty(&self) -> Option<Quantity> {
222 None
223 }
224
225 fn trigger_price(&self) -> Option<Price> {
226 None
227 }
228
229 fn trigger_type(&self) -> Option<TriggerType> {
230 None
231 }
232
233 fn limit_offset(&self) -> Option<Decimal> {
234 None
235 }
236
237 fn trailing_offset(&self) -> Option<Decimal> {
238 None
239 }
240
241 fn trailing_offset_type(&self) -> Option<TrailingOffsetType> {
242 None
243 }
244
245 fn expire_time(&self) -> Option<UnixNanos> {
246 None
247 }
248
249 fn display_qty(&self) -> Option<Quantity> {
250 None
251 }
252
253 fn emulation_trigger(&self) -> Option<TriggerType> {
254 None
255 }
256
257 fn trigger_instrument_id(&self) -> Option<InstrumentId> {
258 None
259 }
260
261 fn contingency_type(&self) -> Option<ContingencyType> {
262 None
263 }
264
265 fn order_list_id(&self) -> Option<OrderListId> {
266 None
267 }
268
269 fn linked_order_ids(&self) -> Option<Vec<ClientOrderId>> {
270 None
271 }
272
273 fn parent_order_id(&self) -> Option<ClientOrderId> {
274 None
275 }
276
277 fn exec_algorithm_id(&self) -> Option<ExecAlgorithmId> {
278 None
279 }
280
281 fn exec_spawn_id(&self) -> Option<ClientOrderId> {
282 None
283 }
284
285 fn venue_order_id(&self) -> Option<VenueOrderId> {
286 self.venue_order_id
287 }
288
289 fn account_id(&self) -> Option<AccountId> {
290 self.account_id
291 }
292
293 fn position_id(&self) -> Option<PositionId> {
294 None
295 }
296
297 fn commission(&self) -> Option<Money> {
298 None
299 }
300
301 fn ts_event(&self) -> UnixNanos {
302 self.ts_event
303 }
304
305 fn ts_init(&self) -> UnixNanos {
306 self.ts_init
307 }
308}
309
310#[cfg(test)]
314mod tests {
315 use rstest::rstest;
316
317 use crate::events::order::{modify_rejected::OrderModifyRejected, stubs::*};
318
319 #[rstest]
320 fn test_order_modified_rejected(order_modify_rejected: OrderModifyRejected) {
321 let display = format!("{order_modify_rejected}");
322 assert_eq!(
323 display,
324 "OrderModifyRejected(instrument_id=BTCUSDT.COINBASE, client_order_id=O-19700101-000000-001-001-1, \
325 venue_order_id=001, account_id=SIM-001, reason='ORDER_DOES_NOT_EXIST', ts_event=0)"
326 );
327 }
328}