nautilus_common/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
16//! A user custom data type.
17
18use bytes::Bytes;
19use nautilus_core::UnixNanos;
20use nautilus_model::data::DataType;
21use serde::{Deserialize, Serialize};
22
23/// Represents a custom data.
24#[repr(C)]
25#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
26#[cfg_attr(
27 feature = "python",
28 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.common", from_py_object)
29)]
30#[cfg_attr(
31 feature = "python",
32 pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.common")
33)]
34pub struct CustomData {
35 pub data_type: DataType,
36 pub value: Bytes,
37 pub ts_event: UnixNanos,
38 pub ts_init: UnixNanos,
39}
40
41impl CustomData {
42 /// Creates a new [`CustomData`] instance.
43 pub const fn new(
44 data_type: DataType,
45 value: Bytes,
46 ts_event: UnixNanos,
47 ts_init: UnixNanos,
48 ) -> Self {
49 Self {
50 data_type,
51 value,
52 ts_event,
53 ts_init,
54 }
55 }
56}