nautilus_model/python/events/order/
emulated.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::OrderEmulated,
24 identifiers::{ClientOrderId, InstrumentId, StrategyId, TraderId},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl OrderEmulated {
30 #[new]
32 fn py_new(
33 trader_id: TraderId,
34 strategy_id: StrategyId,
35 instrument_id: InstrumentId,
36 client_order_id: ClientOrderId,
37 event_id: UUID4,
38 ts_event: u64,
39 ts_init: u64,
40 ) -> Self {
41 Self::new(
42 trader_id,
43 strategy_id,
44 instrument_id,
45 client_order_id,
46 event_id,
47 ts_event.into(),
48 ts_init.into(),
49 )
50 }
51
52 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
53 match op {
54 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
55 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
56 _ => py.NotImplemented(),
57 }
58 }
59
60 fn __repr__(&self) -> String {
61 format!("{self:?}")
62 }
63
64 fn __str__(&self) -> String {
65 self.to_string()
66 }
67
68 #[staticmethod]
69 #[pyo3(name = "from_dict")]
70 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
71 from_dict_pyo3(py, values)
72 }
73
74 #[getter]
75 #[pyo3(name = "trader_id")]
76 fn py_trader_id(&self) -> TraderId {
77 self.trader_id
78 }
79
80 #[getter]
81 #[pyo3(name = "strategy_id")]
82 fn py_strategy_id(&self) -> StrategyId {
83 self.strategy_id
84 }
85
86 #[getter]
87 #[pyo3(name = "instrument_id")]
88 fn py_instrument_id(&self) -> InstrumentId {
89 self.instrument_id
90 }
91
92 #[getter]
93 #[pyo3(name = "client_order_id")]
94 fn py_client_order_id(&self) -> ClientOrderId {
95 self.client_order_id
96 }
97
98 #[getter]
99 #[pyo3(name = "event_id")]
100 fn py_event_id(&self) -> UUID4 {
101 self.event_id
102 }
103
104 #[getter]
105 #[pyo3(name = "ts_event")]
106 fn py_ts_event(&self) -> u64 {
107 self.ts_event.as_u64()
108 }
109
110 #[getter]
111 #[pyo3(name = "ts_init")]
112 fn py_ts_init(&self) -> u64 {
113 self.ts_init.as_u64()
114 }
115
116 #[pyo3(name = "to_dict")]
117 fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
118 let dict = PyDict::new(py);
119 dict.set_item("type", stringify!(OrderEmulated))?;
120 dict.set_item("trader_id", self.trader_id.to_string())?;
121 dict.set_item("strategy_id", self.strategy_id.to_string())?;
122 dict.set_item("instrument_id", self.instrument_id.to_string())?;
123 dict.set_item("client_order_id", self.client_order_id.to_string())?;
124 dict.set_item("event_id", self.event_id.to_string())?;
125 dict.set_item("ts_event", self.ts_event.as_u64())?;
126 dict.set_item("ts_init", self.ts_init.as_u64())?;
127 Ok(dict.into())
128 }
129}