nautilus_model/python/events/order/
emulated.rs1use nautilus_core::{python::serialization::from_dict_pyo3, UUID4};
17use pyo3::{basic::CompareOp, prelude::*, types::PyDict};
18
19use crate::{
20 events::OrderEmulated,
21 identifiers::{ClientOrderId, InstrumentId, StrategyId, TraderId},
22};
23
24#[pymethods]
25impl OrderEmulated {
26 #[allow(clippy::too_many_arguments)]
27 #[new]
28 fn py_new(
29 trader_id: TraderId,
30 strategy_id: StrategyId,
31 instrument_id: InstrumentId,
32 client_order_id: ClientOrderId,
33 event_id: UUID4,
34 ts_event: u64,
35 ts_init: u64,
36 ) -> Self {
37 Self::new(
38 trader_id,
39 strategy_id,
40 instrument_id,
41 client_order_id,
42 event_id,
43 ts_event.into(),
44 ts_init.into(),
45 )
46 }
47
48 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
49 match op {
50 CompareOp::Eq => self.eq(other).into_py(py),
51 CompareOp::Ne => self.ne(other).into_py(py),
52 _ => py.NotImplemented(),
53 }
54 }
55
56 fn __repr__(&self) -> String {
57 format!("{:?}", self)
58 }
59
60 fn __str__(&self) -> String {
61 self.to_string()
62 }
63
64 #[staticmethod]
65 #[pyo3(name = "from_dict")]
66 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
67 from_dict_pyo3(py, values)
68 }
69
70 #[pyo3(name = "to_dict")]
71 fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
72 let dict = PyDict::new(py);
73 dict.set_item("type", stringify!(OrderEmulated))?;
74 dict.set_item("trader_id", self.trader_id.to_string())?;
75 dict.set_item("strategy_id", self.strategy_id.to_string())?;
76 dict.set_item("instrument_id", self.instrument_id.to_string())?;
77 dict.set_item("client_order_id", self.client_order_id.to_string())?;
78 dict.set_item("event_id", self.event_id.to_string())?;
79 dict.set_item("ts_event", self.ts_event.as_u64())?;
80 dict.set_item("ts_init", self.ts_init.as_u64())?;
81 Ok(dict.into())
82 }
83}