Skip to main content

nautilus_model/python/events/order/
released.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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::OrderReleased,
24    identifiers::{ClientOrderId, InstrumentId, StrategyId, TraderId},
25    types::Price,
26};
27
28#[pymethods]
29#[pyo3_stub_gen::derive::gen_stub_pymethods]
30impl OrderReleased {
31    /// Represents an event where an order was released from the `OrderEmulated` by the Nautilus system.
32    #[expect(clippy::too_many_arguments)]
33    #[new]
34    fn py_new(
35        trader_id: TraderId,
36        strategy_id: StrategyId,
37        instrument_id: InstrumentId,
38        client_order_id: ClientOrderId,
39        released_price: Price,
40        event_id: UUID4,
41        ts_event: u64,
42        ts_init: u64,
43    ) -> Self {
44        Self::new(
45            trader_id,
46            strategy_id,
47            instrument_id,
48            client_order_id,
49            released_price,
50            event_id,
51            ts_event.into(),
52            ts_init.into(),
53        )
54    }
55
56    fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
57        match op {
58            CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
59            CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
60            _ => py.NotImplemented(),
61        }
62    }
63
64    fn __repr__(&self) -> String {
65        format!("{self:?}")
66    }
67
68    fn __str__(&self) -> String {
69        self.to_string()
70    }
71
72    #[staticmethod]
73    #[pyo3(name = "from_dict")]
74    fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
75        from_dict_pyo3(py, values)
76    }
77
78    #[getter]
79    #[pyo3(name = "trader_id")]
80    fn py_trader_id(&self) -> TraderId {
81        self.trader_id
82    }
83
84    #[getter]
85    #[pyo3(name = "strategy_id")]
86    fn py_strategy_id(&self) -> StrategyId {
87        self.strategy_id
88    }
89
90    #[getter]
91    #[pyo3(name = "instrument_id")]
92    fn py_instrument_id(&self) -> InstrumentId {
93        self.instrument_id
94    }
95
96    #[getter]
97    #[pyo3(name = "client_order_id")]
98    fn py_client_order_id(&self) -> ClientOrderId {
99        self.client_order_id
100    }
101
102    #[getter]
103    #[pyo3(name = "released_price")]
104    fn py_released_price(&self) -> Price {
105        self.released_price
106    }
107
108    #[getter]
109    #[pyo3(name = "event_id")]
110    fn py_event_id(&self) -> UUID4 {
111        self.event_id
112    }
113
114    #[getter]
115    #[pyo3(name = "ts_event")]
116    fn py_ts_event(&self) -> u64 {
117        self.ts_event.as_u64()
118    }
119
120    #[getter]
121    #[pyo3(name = "ts_init")]
122    fn py_ts_init(&self) -> u64 {
123        self.ts_init.as_u64()
124    }
125
126    #[pyo3(name = "to_dict")]
127    fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
128        let dict = PyDict::new(py);
129        dict.set_item("type", stringify!(OrderReleased))?;
130        dict.set_item("trader_id", self.trader_id.to_string())?;
131        dict.set_item("strategy_id", self.strategy_id.to_string())?;
132        dict.set_item("instrument_id", self.instrument_id.to_string())?;
133        dict.set_item("client_order_id", self.client_order_id.to_string())?;
134        dict.set_item("released_price", self.released_price.to_string())?;
135        dict.set_item("event_id", self.event_id.to_string())?;
136        dict.set_item("ts_event", self.ts_event.as_u64())?;
137        dict.set_item("ts_init", self.ts_init.as_u64())?;
138        Ok(dict.into())
139    }
140}