nautilus_model/python/events/order/
pending_update.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::OrderPendingUpdate,
24 identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl OrderPendingUpdate {
30 #[expect(clippy::too_many_arguments)]
33 #[new]
34 #[pyo3(signature = (trader_id, strategy_id, instrument_id, client_order_id, account_id, event_id, ts_event, ts_init, reconciliation, venue_order_id=None))]
35 fn py_new(
36 trader_id: TraderId,
37 strategy_id: StrategyId,
38 instrument_id: InstrumentId,
39 client_order_id: ClientOrderId,
40 account_id: Option<AccountId>,
41 event_id: UUID4,
42 ts_event: u64,
43 ts_init: u64,
44 reconciliation: bool,
45 venue_order_id: Option<VenueOrderId>,
46 ) -> Self {
47 Self::new(
48 trader_id,
49 strategy_id,
50 instrument_id,
51 client_order_id,
52 account_id,
53 event_id,
54 ts_event.into(),
55 ts_init.into(),
56 reconciliation,
57 venue_order_id,
58 )
59 }
60
61 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
62 match op {
63 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
64 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
65 _ => py.NotImplemented(),
66 }
67 }
68
69 fn __repr__(&self) -> String {
70 format!("{self:?}")
71 }
72
73 fn __str__(&self) -> String {
74 self.to_string()
75 }
76
77 #[getter]
78 #[pyo3(name = "causation_id")]
79 fn py_causation_id(&self) -> Option<UUID4> {
80 self.causation_id
81 }
82
83 #[staticmethod]
84 #[pyo3(name = "from_dict")]
85 fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
86 from_dict_pyo3(py, values)
87 }
88
89 #[getter]
90 #[pyo3(name = "trader_id")]
91 fn py_trader_id(&self) -> TraderId {
92 self.trader_id
93 }
94
95 #[getter]
96 #[pyo3(name = "strategy_id")]
97 fn py_strategy_id(&self) -> StrategyId {
98 self.strategy_id
99 }
100
101 #[getter]
102 #[pyo3(name = "instrument_id")]
103 fn py_instrument_id(&self) -> InstrumentId {
104 self.instrument_id
105 }
106
107 #[getter]
108 #[pyo3(name = "client_order_id")]
109 fn py_client_order_id(&self) -> ClientOrderId {
110 self.client_order_id
111 }
112
113 #[getter]
114 #[pyo3(name = "venue_order_id")]
115 fn py_venue_order_id(&self) -> Option<VenueOrderId> {
116 self.venue_order_id
117 }
118
119 #[getter]
120 #[pyo3(name = "account_id")]
121 fn py_account_id(&self) -> Option<AccountId> {
122 self.account_id
123 }
124
125 #[getter]
126 #[pyo3(name = "event_id")]
127 fn py_event_id(&self) -> UUID4 {
128 self.event_id
129 }
130
131 #[getter]
132 #[pyo3(name = "ts_event")]
133 fn py_ts_event(&self) -> u64 {
134 self.ts_event.as_u64()
135 }
136
137 #[getter]
138 #[pyo3(name = "ts_init")]
139 fn py_ts_init(&self) -> u64 {
140 self.ts_init.as_u64()
141 }
142
143 #[getter]
144 #[pyo3(name = "reconciliation")]
145 fn py_reconciliation(&self) -> bool {
146 self.reconciliation
147 }
148
149 #[pyo3(name = "to_dict")]
150 fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
151 let dict = PyDict::new(py);
152 dict.set_item("type", stringify!(OrderPendingUpdate))?;
153 dict.set_item("trader_id", self.trader_id.to_string())?;
154 dict.set_item("strategy_id", self.strategy_id.to_string())?;
155 dict.set_item("instrument_id", self.instrument_id.to_string())?;
156 dict.set_item("client_order_id", self.client_order_id.to_string())?;
157 match self.account_id {
158 Some(account_id) => dict.set_item("account_id", account_id.to_string())?,
159 None => dict.set_item("account_id", py.None())?,
160 }
161 dict.set_item("event_id", self.event_id.to_string())?;
162 dict.set_item("ts_event", self.ts_event.as_u64())?;
163 dict.set_item("ts_init", self.ts_init.as_u64())?;
164 dict.set_item("reconciliation", self.reconciliation)?;
165 match self.venue_order_id {
166 Some(venue_order_id) => dict.set_item("venue_order_id", venue_order_id.to_string())?,
167 None => dict.set_item("venue_order_id", py.None())?,
168 }
169
170 match self.causation_id {
171 Some(causation_id) => dict.set_item("causation_id", causation_id.to_string())?,
172 None => dict.set_item("causation_id", py.None())?,
173 }
174 Ok(dict.into())
175 }
176}