nautilus_model/python/events/order/
updated.rs1use nautilus_core::{
17 UUID4,
18 python::{IntoPyObjectNautilusExt, serialization::from_dict_pyo3},
19};
20use pyo3::{basic::CompareOp, prelude::*, types::PyDict};
21
22use crate::{
23 events::OrderUpdated,
24 identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
25 types::{Price, Quantity},
26};
27
28#[pymethods]
29#[pyo3_stub_gen::derive::gen_stub_pymethods]
30impl OrderUpdated {
31 #[expect(clippy::too_many_arguments)]
33 #[new]
34 #[pyo3(signature = (trader_id, strategy_id, instrument_id, client_order_id, quantity, event_id, ts_event, ts_init, reconciliation, venue_order_id=None, account_id=None, price=None, trigger_price=None, protection_price=None, is_quote_quantity=false))]
35 fn py_new(
36 trader_id: TraderId,
37 strategy_id: StrategyId,
38 instrument_id: InstrumentId,
39 client_order_id: ClientOrderId,
40 quantity: Quantity,
41 event_id: UUID4,
42 ts_event: u64,
43 ts_init: u64,
44 reconciliation: bool,
45 venue_order_id: Option<VenueOrderId>,
46 account_id: Option<AccountId>,
47 price: Option<Price>,
48 trigger_price: Option<Price>,
49 protection_price: Option<Price>,
50 is_quote_quantity: bool,
51 ) -> Self {
52 Self::new(
53 trader_id,
54 strategy_id,
55 instrument_id,
56 client_order_id,
57 quantity,
58 event_id,
59 ts_event.into(),
60 ts_init.into(),
61 reconciliation,
62 venue_order_id,
63 account_id,
64 price,
65 trigger_price,
66 protection_price,
67 is_quote_quantity,
68 )
69 }
70
71 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
72 match op {
73 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
74 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
75 _ => py.NotImplemented(),
76 }
77 }
78
79 fn __repr__(&self) -> String {
80 format!("{self:?}")
81 }
82
83 fn __str__(&self) -> String {
84 self.to_string()
85 }
86
87 #[getter]
88 #[pyo3(name = "causation_id")]
89 fn py_causation_id(&self) -> Option<UUID4> {
90 self.causation_id
91 }
92
93 #[staticmethod]
94 #[pyo3(name = "from_dict")]
95 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
96 from_dict_pyo3(py, values)
97 }
98
99 #[getter]
100 #[pyo3(name = "trader_id")]
101 fn py_trader_id(&self) -> TraderId {
102 self.trader_id
103 }
104
105 #[getter]
106 #[pyo3(name = "strategy_id")]
107 fn py_strategy_id(&self) -> StrategyId {
108 self.strategy_id
109 }
110
111 #[getter]
112 #[pyo3(name = "instrument_id")]
113 fn py_instrument_id(&self) -> InstrumentId {
114 self.instrument_id
115 }
116
117 #[getter]
118 #[pyo3(name = "client_order_id")]
119 fn py_client_order_id(&self) -> ClientOrderId {
120 self.client_order_id
121 }
122
123 #[getter]
124 #[pyo3(name = "venue_order_id")]
125 fn py_venue_order_id(&self) -> Option<VenueOrderId> {
126 self.venue_order_id
127 }
128
129 #[getter]
130 #[pyo3(name = "account_id")]
131 fn py_account_id(&self) -> Option<AccountId> {
132 self.account_id
133 }
134
135 #[getter]
136 #[pyo3(name = "quantity")]
137 fn py_quantity(&self) -> Quantity {
138 self.quantity
139 }
140
141 #[getter]
142 #[pyo3(name = "price")]
143 fn py_price(&self) -> Option<Price> {
144 self.price
145 }
146
147 #[getter]
148 #[pyo3(name = "trigger_price")]
149 fn py_trigger_price(&self) -> Option<Price> {
150 self.trigger_price
151 }
152
153 #[getter]
154 #[pyo3(name = "protection_price")]
155 fn py_protection_price(&self) -> Option<Price> {
156 self.protection_price
157 }
158
159 #[getter]
160 #[pyo3(name = "event_id")]
161 fn py_event_id(&self) -> UUID4 {
162 self.event_id
163 }
164
165 #[getter]
166 #[pyo3(name = "ts_event")]
167 fn py_ts_event(&self) -> u64 {
168 self.ts_event.as_u64()
169 }
170
171 #[getter]
172 #[pyo3(name = "ts_init")]
173 fn py_ts_init(&self) -> u64 {
174 self.ts_init.as_u64()
175 }
176
177 #[getter]
178 #[pyo3(name = "is_quote_quantity")]
179 fn py_is_quote_quantity(&self) -> bool {
180 self.is_quote_quantity
181 }
182
183 #[getter]
184 #[pyo3(name = "reconciliation")]
185 fn py_reconciliation(&self) -> bool {
186 self.reconciliation
187 }
188
189 #[pyo3(name = "to_dict")]
190 fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
191 let dict = PyDict::new(py);
192 dict.set_item("type", stringify!(OrderUpdated))?;
193 dict.set_item("trader_id", self.trader_id.to_string())?;
194 dict.set_item("strategy_id", self.strategy_id.to_string())?;
195 dict.set_item("instrument_id", self.instrument_id.to_string())?;
196 dict.set_item("client_order_id", self.client_order_id.to_string())?;
197 dict.set_item("quantity", self.quantity.to_string())?;
198 dict.set_item("event_id", self.event_id.to_string())?;
199 dict.set_item("ts_event", self.ts_event.as_u64())?;
200 dict.set_item("ts_init", self.ts_init.as_u64())?;
201 dict.set_item("reconciliation", self.reconciliation)?;
202 match self.venue_order_id {
203 Some(venue_order_id) => dict.set_item("venue_order_id", venue_order_id.to_string())?,
204 None => dict.set_item("venue_order_id", py.None())?,
205 }
206
207 match self.account_id {
208 Some(account_id) => dict.set_item("account_id", account_id.to_string())?,
209 None => dict.set_item("account_id", py.None())?,
210 }
211
212 match self.price {
213 Some(price) => dict.set_item("price", price.to_string())?,
214 None => dict.set_item("price", py.None())?,
215 }
216
217 match self.trigger_price {
218 Some(trigger_price) => dict.set_item("trigger_price", trigger_price.to_string())?,
219 None => dict.set_item("trigger_price", py.None())?,
220 }
221
222 match self.protection_price {
223 Some(protection_price) => {
224 dict.set_item("protection_price", protection_price.to_string())?;
225 }
226 None => dict.set_item("protection_price", py.None())?,
227 }
228 dict.set_item("is_quote_quantity", self.is_quote_quantity)?;
229 match self.causation_id {
230 Some(causation_id) => dict.set_item("causation_id", causation_id.to_string())?,
231 None => dict.set_item("causation_id", py.None())?,
232 }
233 Ok(dict.into())
234 }
235}