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