nautilus_model/python/events/order/
updated.rs1use nautilus_core::{python::serialization::from_dict_pyo3, UUID4};
17use pyo3::{basic::CompareOp, prelude::*, types::PyDict};
18
19use crate::{
20 events::OrderUpdated,
21 identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
22 types::{Price, Quantity},
23};
24
25#[pymethods]
26impl OrderUpdated {
27 #[allow(clippy::too_many_arguments)]
28 #[new]
29 #[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))]
30 fn py_new(
31 trader_id: TraderId,
32 strategy_id: StrategyId,
33 instrument_id: InstrumentId,
34 client_order_id: ClientOrderId,
35 quantity: Quantity,
36 event_id: UUID4,
37 ts_event: u64,
38 ts_init: u64,
39 reconciliation: bool,
40 venue_order_id: Option<VenueOrderId>,
41 account_id: Option<AccountId>,
42 price: Option<Price>,
43 trigger_price: Option<Price>,
44 ) -> Self {
45 Self::new(
46 trader_id,
47 strategy_id,
48 instrument_id,
49 client_order_id,
50 quantity,
51 event_id,
52 ts_event.into(),
53 ts_init.into(),
54 reconciliation,
55 venue_order_id,
56 account_id,
57 price,
58 trigger_price,
59 )
60 }
61
62 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
63 match op {
64 CompareOp::Eq => self.eq(other).into_py(py),
65 CompareOp::Ne => self.ne(other).into_py(py),
66 _ => py.NotImplemented(),
67 }
68 }
69
70 fn __repr__(&self) -> String {
71 format!("{:?}", self)
72 }
73
74 fn __str__(&self) -> String {
75 self.to_string()
76 }
77
78 #[staticmethod]
79 #[pyo3(name = "from_dict")]
80 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
81 from_dict_pyo3(py, values)
82 }
83
84 #[pyo3(name = "to_dict")]
85 fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
86 let dict = PyDict::new(py);
87 dict.set_item("type", stringify!(OrderUpdated))?;
88 dict.set_item("trader_id", self.trader_id.to_string())?;
89 dict.set_item("strategy_id", self.strategy_id.to_string())?;
90 dict.set_item("instrument_id", self.instrument_id.to_string())?;
91 dict.set_item("client_order_id", self.client_order_id.to_string())?;
92 dict.set_item("quantity", self.quantity.to_string())?;
93 dict.set_item("event_id", self.event_id.to_string())?;
94 dict.set_item("ts_event", self.ts_event.as_u64())?;
95 dict.set_item("ts_init", self.ts_init.as_u64())?;
96 dict.set_item("reconciliation", self.reconciliation)?;
97 match self.venue_order_id {
98 Some(venue_order_id) => dict.set_item("venue_order_id", venue_order_id.to_string())?,
99 None => dict.set_item("venue_order_id", py.None())?,
100 }
101 match self.account_id {
102 Some(account_id) => dict.set_item("account_id", account_id.to_string())?,
103 None => dict.set_item("account_id", py.None())?,
104 }
105 match self.price {
106 Some(price) => dict.set_item("price", price.to_string())?,
107 None => dict.set_item("price", py.None())?,
108 }
109 match self.trigger_price {
110 Some(trigger_price) => dict.set_item("trigger_price", trigger_price.to_string())?,
111 None => dict.set_item("trigger_price", py.None())?,
112 }
113 Ok(dict.into())
114 }
115}