Skip to main content

nautilus_databento/
enums.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//! Enumerations for the Databento integration.
17
18use std::str::FromStr;
19
20use nautilus_model::{enum_strum_serde, enums::FromU8};
21use serde::{Deserialize, Deserializer, Serialize, Serializer};
22use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
23
24/// Represents a Databento statistic type.
25#[repr(C)]
26#[derive(
27    Copy,
28    Clone,
29    Debug,
30    Display,
31    Hash,
32    PartialEq,
33    Eq,
34    PartialOrd,
35    Ord,
36    AsRefStr,
37    FromRepr,
38    EnumIter,
39    EnumString,
40)]
41#[strum(ascii_case_insensitive)]
42#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
43#[cfg_attr(
44    feature = "python",
45    pyo3::pyclass(
46        eq,
47        eq_int,
48        rename_all = "SCREAMING_SNAKE_CASE",
49        module = "nautilus_trader.core.nautilus_pyo3.databento",
50        from_py_object
51    )
52)]
53#[cfg_attr(
54    feature = "python",
55    pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.databento")
56)]
57pub enum DatabentoStatisticType {
58    OpeningPrice = 1,
59    IndicativeOpeningPrice = 2,
60    SettlementPrice = 3,
61    TradingSessionLowPrice = 4,
62    TradingSessionHighPrice = 5,
63    ClearedVolume = 6,
64    LowestOffer = 7,
65    HighestBid = 8,
66    OpenInterest = 9,
67    FixingPrice = 10,
68    ClosePrice = 11,
69    NetChange = 12,
70    Vwap = 13,
71    Volatility = 14,
72    Delta = 15,
73    UncrossingPrice = 16,
74    UpperPriceLimit = 17,
75    LowerPriceLimit = 18,
76    BlockVolume = 19,
77    IndicativeClosePrice = 20,
78}
79
80impl FromU8 for DatabentoStatisticType {
81    fn from_u8(value: u8) -> Option<Self> {
82        match value {
83            1 => Some(Self::OpeningPrice),
84            2 => Some(Self::IndicativeOpeningPrice),
85            3 => Some(Self::SettlementPrice),
86            4 => Some(Self::TradingSessionLowPrice),
87            5 => Some(Self::TradingSessionHighPrice),
88            6 => Some(Self::ClearedVolume),
89            7 => Some(Self::LowestOffer),
90            8 => Some(Self::HighestBid),
91            9 => Some(Self::OpenInterest),
92            10 => Some(Self::FixingPrice),
93            11 => Some(Self::ClosePrice),
94            12 => Some(Self::NetChange),
95            13 => Some(Self::Vwap),
96            14 => Some(Self::Volatility),
97            15 => Some(Self::Delta),
98            16 => Some(Self::UncrossingPrice),
99            17 => Some(Self::UpperPriceLimit),
100            18 => Some(Self::LowerPriceLimit),
101            19 => Some(Self::BlockVolume),
102            20 => Some(Self::IndicativeClosePrice),
103            _ => None,
104        }
105    }
106}
107
108/// Represents a Databento statistic update action.
109#[repr(C)]
110#[derive(
111    Copy,
112    Clone,
113    Debug,
114    Display,
115    Hash,
116    PartialEq,
117    Eq,
118    PartialOrd,
119    Ord,
120    AsRefStr,
121    FromRepr,
122    EnumIter,
123    EnumString,
124)]
125#[strum(ascii_case_insensitive)]
126#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
127#[cfg_attr(
128    feature = "python",
129    pyo3::pyclass(
130        eq,
131        eq_int,
132        rename_all = "SCREAMING_SNAKE_CASE",
133        module = "nautilus_trader.core.nautilus_pyo3.databento",
134        from_py_object
135    )
136)]
137#[cfg_attr(
138    feature = "python",
139    pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.databento")
140)]
141pub enum DatabentoStatisticUpdateAction {
142    Added = 1,
143    Deleted = 2,
144}
145
146impl FromU8 for DatabentoStatisticUpdateAction {
147    fn from_u8(value: u8) -> Option<Self> {
148        match value {
149            1 => Some(Self::Added),
150            2 => Some(Self::Deleted),
151            _ => None,
152        }
153    }
154}
155
156enum_strum_serde!(DatabentoStatisticType);
157enum_strum_serde!(DatabentoStatisticUpdateAction);