nautilus_model/python/events/order/
triggered.rs1use nautilus_core::{python::serialization::from_dict_pyo3, UUID4};
17use pyo3::{basic::CompareOp, prelude::*, types::PyDict};
18
19use crate::{
20 events::OrderTriggered,
21 identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
22};
23
24#[pymethods]
25impl OrderTriggered {
26 #[allow(clippy::too_many_arguments)]
27 #[new]
28 #[pyo3(signature = (trader_id, strategy_id, instrument_id, client_order_id, event_id, ts_event, ts_init, reconciliation, venue_order_id=None, account_id=None))]
29 fn py_new(
30 trader_id: TraderId,
31 strategy_id: StrategyId,
32 instrument_id: InstrumentId,
33 client_order_id: ClientOrderId,
34 event_id: UUID4,
35 ts_event: u64,
36 ts_init: u64,
37 reconciliation: bool,
38 venue_order_id: Option<VenueOrderId>,
39 account_id: Option<AccountId>,
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 reconciliation,
50 venue_order_id,
51 account_id,
52 )
53 }
54
55 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
56 match op {
57 CompareOp::Eq => self.eq(other).into_py(py),
58 CompareOp::Ne => self.ne(other).into_py(py),
59 _ => py.NotImplemented(),
60 }
61 }
62
63 fn __repr__(&self) -> String {
64 format!("{:?}", self)
65 }
66
67 fn __str__(&self) -> String {
68 self.to_string()
69 }
70
71 #[staticmethod]
72 #[pyo3(name = "from_dict")]
73 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
74 from_dict_pyo3(py, values)
75 }
76
77 #[pyo3(name = "to_dict")]
78 fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
79 let dict = PyDict::new(py);
80 dict.set_item("type", stringify!(OrderTriggered))?;
81 dict.set_item("trader_id", self.trader_id.to_string())?;
82 dict.set_item("strategy_id", self.strategy_id.to_string())?;
83 dict.set_item("instrument_id", self.instrument_id.to_string())?;
84 dict.set_item("client_order_id", self.client_order_id.to_string())?;
85 dict.set_item("event_id", self.event_id.to_string())?;
86 dict.set_item("ts_event", self.ts_event.as_u64())?;
87 dict.set_item("ts_init", self.ts_init.as_u64())?;
88 dict.set_item("reconciliation", self.reconciliation)?;
89 match self.venue_order_id {
90 Some(venue_order_id) => dict.set_item("venue_order_id", venue_order_id.to_string())?,
91 None => dict.set_item("venue_order_id", "None")?,
92 }
93 match self.account_id {
94 Some(account_id) => dict.set_item("account_id", account_id.to_string())?,
95 None => dict.set_item("account_id", "None")?,
96 }
97 Ok(dict.into())
98 }
99}