nautilus_model/python/events/order/
submitted.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::OrderSubmitted,
24 identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId},
25};
26
27#[pymethods]
28impl OrderSubmitted {
29 #[allow(clippy::too_many_arguments)]
30 #[new]
31 fn py_new(
32 trader_id: TraderId,
33 strategy_id: StrategyId,
34 instrument_id: InstrumentId,
35 client_order_id: ClientOrderId,
36 account_id: AccountId,
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 account_id,
47 event_id,
48 ts_event.into(),
49 ts_init.into(),
50 )
51 }
52
53 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
54 match op {
55 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
56 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
57 _ => py.NotImplemented(),
58 }
59 }
60
61 fn __repr__(&self) -> String {
62 format!("{:?}", self)
63 }
64
65 fn __str__(&self) -> String {
66 self.to_string()
67 }
68
69 #[staticmethod]
70 #[pyo3(name = "from_dict")]
71 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
72 from_dict_pyo3(py, values)
73 }
74
75 #[pyo3(name = "to_dict")]
76 fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
77 let dict = PyDict::new(py);
78 dict.set_item("type", stringify!(OrderSubmitted))?;
79 dict.set_item("trader_id", self.trader_id.to_string())?;
80 dict.set_item("strategy_id", self.strategy_id.to_string())?;
81 dict.set_item("instrument_id", self.instrument_id.to_string())?;
82 dict.set_item("client_order_id", self.client_order_id.to_string())?;
83 dict.set_item("account_id", self.account_id.to_string())?;
84 dict.set_item("event_id", self.event_id.to_string())?;
85 dict.set_item("ts_event", self.ts_event.as_u64())?;
86 dict.set_item("ts_init", self.ts_init.as_u64())?;
87 Ok(dict.into())
88 }
89}