nautilus_common/python/custom.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 bytes::Bytes;
17use nautilus_core::UnixNanos;
18use nautilus_model::data::DataType;
19use pyo3::prelude::*;
20
21use crate::custom::CustomData;
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl CustomData {
26 /// Represents a custom data.
27 #[new]
28 fn py_new(data_type: DataType, value: Vec<u8>, ts_event: u64, ts_init: u64) -> Self {
29 Self::new(
30 data_type,
31 Bytes::from(value),
32 UnixNanos::from(ts_event),
33 UnixNanos::from(ts_init),
34 )
35 }
36
37 #[getter]
38 #[pyo3(name = "data_type")]
39 fn py_data_type(&self) -> DataType {
40 self.data_type.clone()
41 }
42
43 #[getter]
44 #[pyo3(name = "value")]
45 fn py_value(&self) -> Vec<u8> {
46 self.value.to_vec()
47 }
48
49 #[getter]
50 #[pyo3(name = "ts_event")]
51 const fn py_ts_event(&self) -> u64 {
52 self.ts_event.as_u64()
53 }
54
55 #[getter]
56 #[pyo3(name = "ts_init")]
57 const fn py_ts_init(&self) -> u64 {
58 self.ts_init.as_u64()
59 }
60}