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