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