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 #[staticmethod]
88 #[pyo3(name = "from_dict")]
89 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
90 from_dict_pyo3(py, values)
91 }
92
93 #[getter]
94 #[pyo3(name = "trader_id")]
95 fn py_trader_id(&self) -> TraderId {
96 self.trader_id
97 }
98
99 #[getter]
100 #[pyo3(name = "strategy_id")]
101 fn py_strategy_id(&self) -> StrategyId {
102 self.strategy_id
103 }
104
105 #[getter]
106 #[pyo3(name = "instrument_id")]
107 fn py_instrument_id(&self) -> InstrumentId {
108 self.instrument_id
109 }
110
111 #[getter]
112 #[pyo3(name = "client_order_id")]
113 fn py_client_order_id(&self) -> ClientOrderId {
114 self.client_order_id
115 }
116
117 #[getter]
118 #[pyo3(name = "venue_order_id")]
119 fn py_venue_order_id(&self) -> Option<VenueOrderId> {
120 self.venue_order_id
121 }
122
123 #[getter]
124 #[pyo3(name = "account_id")]
125 fn py_account_id(&self) -> Option<AccountId> {
126 self.account_id
127 }
128
129 #[getter]
130 #[pyo3(name = "quantity")]
131 fn py_quantity(&self) -> Quantity {
132 self.quantity
133 }
134
135 #[getter]
136 #[pyo3(name = "price")]
137 fn py_price(&self) -> Option<Price> {
138 self.price
139 }
140
141 #[getter]
142 #[pyo3(name = "trigger_price")]
143 fn py_trigger_price(&self) -> Option<Price> {
144 self.trigger_price
145 }
146
147 #[getter]
148 #[pyo3(name = "event_id")]
149 fn py_event_id(&self) -> UUID4 {
150 self.event_id
151 }
152
153 #[getter]
154 #[pyo3(name = "ts_event")]
155 fn py_ts_event(&self) -> u64 {
156 self.ts_event.as_u64()
157 }
158
159 #[getter]
160 #[pyo3(name = "ts_init")]
161 fn py_ts_init(&self) -> u64 {
162 self.ts_init.as_u64()
163 }
164
165 #[getter]
166 #[pyo3(name = "is_quote_quantity")]
167 fn py_is_quote_quantity(&self) -> bool {
168 self.is_quote_quantity
169 }
170
171 #[getter]
172 #[pyo3(name = "reconciliation")]
173 fn py_reconciliation(&self) -> bool {
174 self.reconciliation != 0
175 }
176
177 #[pyo3(name = "to_dict")]
178 fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
179 let dict = PyDict::new(py);
180 dict.set_item("type", stringify!(OrderUpdated))?;
181 dict.set_item("trader_id", self.trader_id.to_string())?;
182 dict.set_item("strategy_id", self.strategy_id.to_string())?;
183 dict.set_item("instrument_id", self.instrument_id.to_string())?;
184 dict.set_item("client_order_id", self.client_order_id.to_string())?;
185 dict.set_item("quantity", self.quantity.to_string())?;
186 dict.set_item("event_id", self.event_id.to_string())?;
187 dict.set_item("ts_event", self.ts_event.as_u64())?;
188 dict.set_item("ts_init", self.ts_init.as_u64())?;
189 dict.set_item("reconciliation", self.reconciliation)?;
190 match self.venue_order_id {
191 Some(venue_order_id) => dict.set_item("venue_order_id", venue_order_id.to_string())?,
192 None => dict.set_item("venue_order_id", py.None())?,
193 }
194
195 match self.account_id {
196 Some(account_id) => dict.set_item("account_id", account_id.to_string())?,
197 None => dict.set_item("account_id", py.None())?,
198 }
199
200 match self.price {
201 Some(price) => dict.set_item("price", price.to_string())?,
202 None => dict.set_item("price", py.None())?,
203 }
204
205 match self.trigger_price {
206 Some(trigger_price) => dict.set_item("trigger_price", trigger_price.to_string())?,
207 None => dict.set_item("trigger_price", py.None())?,
208 }
209 dict.set_item("is_quote_quantity", self.is_quote_quantity)?;
210 Ok(dict.into())
211 }
212}