nautilus_common/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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 common components.
17
18use log::Level;
19use serde::{Deserialize, Serialize};
20use strum::{Display, EnumIter, EnumString, FromRepr};
21
22/// The state of a component within the system.
23#[repr(C)]
24#[derive(
25    Copy,
26    Clone,
27    Debug,
28    Default,
29    Display,
30    Hash,
31    PartialEq,
32    Eq,
33    PartialOrd,
34    Ord,
35    FromRepr,
36    EnumIter,
37    EnumString,
38    Serialize,
39    Deserialize,
40)]
41#[strum(ascii_case_insensitive)]
42#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
43#[cfg_attr(
44    feature = "python",
45    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
46)]
47pub enum ComponentState {
48    /// When a component is instantiated, but not yet ready to fulfill its specification.
49    #[default]
50    PreInitialized = 0,
51    /// When a component is able to be started.
52    Ready = 1,
53    /// When a component is executing its actions on `start`.
54    Starting = 2,
55    /// When a component is operating normally and can fulfill its specification.
56    Running = 3,
57    /// When a component is executing its actions on `stop`.
58    Stopping = 4,
59    /// When a component has successfully stopped.
60    Stopped = 5,
61    /// When a component is started again after its initial start.
62    Resuming = 6,
63    /// When a component is executing its actions on `reset`.
64    Resetting = 7,
65    /// When a component is executing its actions on `dispose`.
66    Disposing = 8,
67    /// When a component has successfully shut down and released all of its resources.
68    Disposed = 9,
69    /// When a component is executing its actions on `degrade`.
70    Degrading = 10,
71    /// When a component has successfully degraded and may not meet its full specification.
72    Degraded = 11,
73    /// When a component is executing its actions on `fault`.
74    Faulting = 12,
75    /// When a component has successfully shut down due to a detected fault.
76    Faulted = 13,
77}
78
79/// A trigger condition for a component within the system.
80#[repr(C)]
81#[derive(
82    Copy,
83    Clone,
84    Debug,
85    Display,
86    Hash,
87    PartialEq,
88    Eq,
89    PartialOrd,
90    Ord,
91    FromRepr,
92    EnumIter,
93    EnumString,
94    Serialize,
95    Deserialize,
96)]
97#[strum(ascii_case_insensitive)]
98#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
99#[cfg_attr(
100    feature = "python",
101    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
102)]
103pub enum ComponentTrigger {
104    /// A trigger for the component to initialize.
105    Initialize = 1,
106    /// A trigger for the component to start.
107    Start = 2,
108    /// A trigger when the component has successfully started.
109    StartCompleted = 3,
110    /// A trigger for the component to stop.
111    Stop = 4,
112    /// A trigger when the component has successfully stopped.
113    StopCompleted = 5,
114    /// A trigger for the component to resume (after being stopped).
115    Resume = 6,
116    /// A trigger when the component has successfully resumed.
117    ResumeCompleted = 7,
118    /// A trigger for the component to reset.
119    Reset = 8,
120    /// A trigger when the component has successfully reset.
121    ResetCompleted = 9,
122    /// A trigger for the component to dispose and release resources.
123    Dispose = 10,
124    /// A trigger when the component has successfully disposed.
125    DisposeCompleted = 11,
126    /// A trigger for the component to degrade.
127    Degrade = 12,
128    /// A trigger when the component has successfully degraded.
129    DegradeCompleted = 13,
130    /// A trigger for the component to fault.
131    Fault = 14,
132    /// A trigger when the component has successfully faulted.
133    FaultCompleted = 15,
134}
135
136/// Represents the environment context for a Posei system.
137#[repr(C)]
138#[derive(
139    Copy,
140    Clone,
141    Debug,
142    Display,
143    Hash,
144    PartialEq,
145    Eq,
146    PartialOrd,
147    Ord,
148    FromRepr,
149    EnumIter,
150    EnumString,
151    Serialize,
152    Deserialize,
153)]
154#[strum(ascii_case_insensitive)]
155#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
156#[cfg_attr(
157    feature = "python",
158    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
159)]
160pub enum Environment {
161    Backtest,
162    Sandbox,
163    Live,
164}
165
166/// The log level for log messages.
167#[repr(C)]
168#[derive(
169    Copy,
170    Clone,
171    Debug,
172    Display,
173    Hash,
174    PartialEq,
175    Eq,
176    PartialOrd,
177    Ord,
178    FromRepr,
179    EnumIter,
180    EnumString,
181    Serialize,
182    Deserialize,
183)]
184#[strum(ascii_case_insensitive)]
185#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
186#[cfg_attr(
187    feature = "python",
188    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
189)]
190pub enum LogLevel {
191    /// The **OFF** log level. A level lower than all other log levels (off).
192    #[strum(serialize = "OFF")]
193    #[serde(rename = "OFF")]
194    Off = 0,
195    /// The **TRACE** log level. Only available in Rust for debug/development builds.
196    #[strum(serialize = "TRACE")]
197    #[serde(rename = "TRACE")]
198    Trace = 1,
199    /// The **DEBUG** log level.
200    #[strum(serialize = "DEBUG")]
201    #[serde(rename = "DEBUG")]
202    Debug = 2,
203    /// The **INFO** log level.
204    #[strum(serialize = "INFO")]
205    #[serde(rename = "INFO")]
206    Info = 3,
207    /// The **WARNING** log level.
208    #[strum(serialize = "WARN", serialize = "WARNING")]
209    #[serde(rename = "WARNING")]
210    Warning = 4,
211    /// The **ERROR** log level.
212    #[strum(serialize = "ERROR")]
213    #[serde(rename = "ERROR")]
214    Error = 5,
215}
216
217/// The log color for log messages.
218#[repr(C)]
219#[derive(
220    Copy,
221    Clone,
222    Debug,
223    Display,
224    Hash,
225    PartialEq,
226    Eq,
227    PartialOrd,
228    Ord,
229    FromRepr,
230    EnumIter,
231    EnumString,
232    Serialize,
233    Deserialize,
234)]
235#[strum(ascii_case_insensitive)]
236#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
237#[cfg_attr(
238    feature = "python",
239    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
240)]
241pub enum LogColor {
242    /// The default/normal log color.
243    #[strum(serialize = "NORMAL")]
244    Normal = 0,
245    /// The green log color, typically used with [`LogLevel::Info`] log levels and associated with success events.
246    #[strum(serialize = "GREEN")]
247    Green = 1,
248    /// The blue log color, typically used with [`LogLevel::Info`] log levels and associated with user actions.
249    #[strum(serialize = "BLUE")]
250    Blue = 2,
251    /// The magenta log color, typically used with [`LogLevel::Info`] log levels.
252    #[strum(serialize = "MAGENTA")]
253    Magenta = 3,
254    /// The cyan log color, typically used with [`LogLevel::Info`] log levels.
255    #[strum(serialize = "CYAN")]
256    Cyan = 4,
257    /// The yellow log color, typically used with [`LogLevel::Warning`] log levels.
258    #[strum(serialize = "YELLOW")]
259    Yellow = 5,
260    /// The red log color, typically used with [`LogLevel::Error`] level.
261    #[strum(serialize = "RED")]
262    Red = 6,
263}
264
265impl LogColor {
266    #[must_use]
267    pub const fn as_ansi(&self) -> &str {
268        match *self {
269            Self::Normal => "",
270            Self::Green => "\x1b[92m",
271            Self::Blue => "\x1b[94m",
272            Self::Magenta => "\x1b[35m",
273            Self::Cyan => "\x1b[36m",
274            Self::Yellow => "\x1b[1;33m",
275            Self::Red => "\x1b[1;31m",
276        }
277    }
278}
279
280impl From<u8> for LogColor {
281    fn from(value: u8) -> Self {
282        match value {
283            1 => Self::Green,
284            2 => Self::Blue,
285            3 => Self::Magenta,
286            4 => Self::Cyan,
287            5 => Self::Yellow,
288            6 => Self::Red,
289            _ => Self::Normal,
290        }
291    }
292}
293
294impl From<Level> for LogColor {
295    fn from(value: Level) -> Self {
296        match value {
297            Level::Error => Self::Red,
298            Level::Warn => Self::Yellow,
299            Level::Info => Self::Normal,
300            Level::Debug => Self::Normal,
301            Level::Trace => Self::Normal,
302        }
303    }
304}
305
306/// An ANSI log line format specifier.
307/// This is used for formatting log messages with ANSI escape codes.
308#[repr(C)]
309#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, FromRepr, EnumString, Display)]
310#[strum(ascii_case_insensitive)]
311#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
312#[cfg_attr(
313    feature = "python",
314    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
315)]
316pub enum LogFormat {
317    /// Header log format. This ANSI escape code is used for magenta text color,
318    /// often used for headers or titles in the log output.
319    #[strum(serialize = "\x1b[95m")]
320    Header,
321
322    /// Endc log format. This ANSI escape code is used to reset all format attributes
323    /// to their defaults. It should be used after applying other formats.
324    #[strum(serialize = "\x1b[0m")]
325    Endc,
326
327    /// Bold log format. This ANSI escape code is used to make the text bold in the log output.
328    #[strum(serialize = "\x1b[1m")]
329    Bold,
330
331    /// Underline log format. This ANSI escape code is used to underline the text in the log output.
332    #[strum(serialize = "\x1b[4m")]
333    Underline,
334}
335
336/// The serialization encoding.
337#[repr(C)]
338#[derive(
339    Copy,
340    Clone,
341    Debug,
342    Display,
343    Hash,
344    PartialEq,
345    Eq,
346    PartialOrd,
347    Ord,
348    FromRepr,
349    EnumIter,
350    EnumString,
351    Serialize,
352    Deserialize,
353)]
354#[strum(ascii_case_insensitive)]
355#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
356#[cfg_attr(
357    feature = "python",
358    pyo3::pyclass(eq, eq_int, module = "posei_trader.core.nautilus_pyo3.common.enums")
359)]
360pub enum SerializationEncoding {
361    /// The MessagePack encoding.
362    #[serde(rename = "msgpack")]
363    MsgPack = 0,
364    /// The JavaScript Object Notation (JSON) encoding.
365    #[serde(rename = "json")]
366    Json = 1,
367}