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 #[getter]
76 #[pyo3(name = "trader_id")]
77 fn py_trader_id(&self) -> TraderId {
78 self.trader_id
79 }
80
81 #[getter]
82 #[pyo3(name = "strategy_id")]
83 fn py_strategy_id(&self) -> StrategyId {
84 self.strategy_id
85 }
86
87 #[getter]
88 #[pyo3(name = "instrument_id")]
89 fn py_instrument_id(&self) -> InstrumentId {
90 self.instrument_id
91 }
92
93 #[getter]
94 #[pyo3(name = "client_order_id")]
95 fn py_client_order_id(&self) -> ClientOrderId {
96 self.client_order_id
97 }
98
99 #[getter]
100 #[pyo3(name = "account_id")]
101 fn py_account_id(&self) -> AccountId {
102 self.account_id
103 }
104
105 #[getter]
106 #[pyo3(name = "event_id")]
107 fn py_event_id(&self) -> UUID4 {
108 self.event_id
109 }
110
111 #[getter]
112 #[pyo3(name = "ts_event")]
113 fn py_ts_event(&self) -> u64 {
114 self.ts_event.as_u64()
115 }
116
117 #[getter]
118 #[pyo3(name = "ts_init")]
119 fn py_ts_init(&self) -> u64 {
120 self.ts_init.as_u64()
121 }
122
123 #[pyo3(name = "to_dict")]
124 fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
125 let dict = PyDict::new(py);
126 dict.set_item("type", stringify!(OrderSubmitted))?;
127 dict.set_item("trader_id", self.trader_id.to_string())?;
128 dict.set_item("strategy_id", self.strategy_id.to_string())?;
129 dict.set_item("instrument_id", self.instrument_id.to_string())?;
130 dict.set_item("client_order_id", self.client_order_id.to_string())?;
131 dict.set_item("account_id", self.account_id.to_string())?;
132 dict.set_item("event_id", self.event_id.to_string())?;
133 dict.set_item("ts_event", self.ts_event.as_u64())?;
134 dict.set_item("ts_init", self.ts_init.as_u64())?;
135 Ok(dict.into())
136 }
137}