nautilus_model/python/events/order/
accepted.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use nautilus_core::{
17    UUID4,
18    python::{IntoPyObjectNautilusExt, serialization::from_dict_pyo3},
19};
20use pyo3::{basic::CompareOp, prelude::*, types::PyDict};
21
22use crate::{
23    events::OrderAccepted,
24    identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
25};
26
27#[pymethods]
28impl OrderAccepted {
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        venue_order_id: VenueOrderId,
37        account_id: AccountId,
38        event_id: UUID4,
39        ts_event: u64,
40        ts_init: u64,
41        reconciliation: bool,
42    ) -> Self {
43        Self::new(
44            trader_id,
45            strategy_id,
46            instrument_id,
47            client_order_id,
48            venue_order_id,
49            account_id,
50            event_id,
51            ts_event.into(),
52            ts_init.into(),
53            reconciliation,
54        )
55    }
56
57    fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
58        match op {
59            CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
60            CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
61            _ => py.NotImplemented(),
62        }
63    }
64
65    fn __repr__(&self) -> String {
66        format!("{self:?}")
67    }
68
69    fn __str__(&self) -> String {
70        self.to_string()
71    }
72
73    #[staticmethod]
74    #[pyo3(name = "from_dict")]
75    fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
76        from_dict_pyo3(py, values)
77    }
78
79    #[getter]
80    #[pyo3(name = "trader_id")]
81    fn py_trader_id(&self) -> TraderId {
82        self.trader_id
83    }
84
85    #[getter]
86    #[pyo3(name = "strategy_id")]
87    fn py_strategy_id(&self) -> StrategyId {
88        self.strategy_id
89    }
90
91    #[getter]
92    #[pyo3(name = "instrument_id")]
93    fn py_instrument_id(&self) -> InstrumentId {
94        self.instrument_id
95    }
96
97    #[getter]
98    #[pyo3(name = "client_order_id")]
99    fn py_client_order_id(&self) -> ClientOrderId {
100        self.client_order_id
101    }
102
103    #[getter]
104    #[pyo3(name = "venue_order_id")]
105    fn py_venue_order_id(&self) -> VenueOrderId {
106        self.venue_order_id
107    }
108
109    #[getter]
110    #[pyo3(name = "account_id")]
111    fn py_account_id(&self) -> AccountId {
112        self.account_id
113    }
114
115    #[getter]
116    #[pyo3(name = "event_id")]
117    fn py_event_id(&self) -> UUID4 {
118        self.event_id
119    }
120
121    #[getter]
122    #[pyo3(name = "ts_event")]
123    fn py_ts_event(&self) -> u64 {
124        self.ts_event.as_u64()
125    }
126
127    #[getter]
128    #[pyo3(name = "ts_init")]
129    fn py_ts_init(&self) -> u64 {
130        self.ts_init.as_u64()
131    }
132
133    #[getter]
134    #[pyo3(name = "reconciliation")]
135    fn py_reconciliation(&self) -> bool {
136        self.reconciliation != 0
137    }
138
139    #[pyo3(name = "to_dict")]
140    fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
141        let dict = PyDict::new(py);
142        dict.set_item("type", stringify!(OrderAccepted))?;
143        dict.set_item("trader_id", self.trader_id.to_string())?;
144        dict.set_item("strategy_id", self.strategy_id.to_string())?;
145        dict.set_item("instrument_id", self.instrument_id.to_string())?;
146        dict.set_item("client_order_id", self.client_order_id.to_string())?;
147        dict.set_item("venue_order_id", self.venue_order_id.to_string())?;
148        dict.set_item("account_id", self.account_id.to_string())?;
149        dict.set_item("event_id", self.event_id.to_string())?;
150        dict.set_item("ts_event", self.ts_event.as_u64())?;
151        dict.set_item("ts_init", self.ts_init.as_u64())?;
152        dict.set_item("reconciliation", self.reconciliation)?;
153        Ok(dict.into())
154    }
155}