nautilus_model/python/events/order/
released.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::OrderReleased,
24    identifiers::{ClientOrderId, InstrumentId, StrategyId, TraderId},
25    types::Price,
26};
27
28#[pymethods]
29impl OrderReleased {
30    #[allow(clippy::too_many_arguments)]
31    #[new]
32    fn py_new(
33        trader_id: TraderId,
34        strategy_id: StrategyId,
35        instrument_id: InstrumentId,
36        client_order_id: ClientOrderId,
37        released_price: Price,
38        event_id: UUID4,
39        ts_event: u64,
40        ts_init: u64,
41    ) -> Self {
42        Self::new(
43            trader_id,
44            strategy_id,
45            instrument_id,
46            client_order_id,
47            released_price,
48            event_id,
49            ts_event.into(),
50            ts_init.into(),
51        )
52    }
53
54    fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
55        match op {
56            CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
57            CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
58            _ => py.NotImplemented(),
59        }
60    }
61
62    fn __repr__(&self) -> String {
63        format!("{:?}", self)
64    }
65
66    fn __str__(&self) -> String {
67        self.to_string()
68    }
69
70    #[staticmethod]
71    #[pyo3(name = "from_dict")]
72    fn py_from_dict(py: Python<'_>, values: Py<PyDict>) -> PyResult<Self> {
73        from_dict_pyo3(py, values)
74    }
75
76    #[pyo3(name = "to_dict")]
77    fn py_to_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
78        let dict = PyDict::new(py);
79        dict.set_item("type", stringify!(OrderReleased))?;
80        dict.set_item("trader_id", self.trader_id.to_string())?;
81        dict.set_item("strategy_id", self.strategy_id.to_string())?;
82        dict.set_item("instrument_id", self.instrument_id.to_string())?;
83        dict.set_item("client_order_id", self.client_order_id.to_string())?;
84        dict.set_item("released_price", self.released_price.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        Ok(dict.into())
89    }
90}