ek-data 0.2.8

Trading data contracts for the enkeep ek ecosystem: venue enums, zero-dep epoch-nanosecond time, decimal-exact price rounding, vt-symbol convention, bus event dictionary, tick/bar/order/trade/position/account/contract objects and request objects (Python enkeep_trade trader/object.py + constant.py, faithfully ported).
Documentation
//! 日志对象(`object.py:286-296`)。
//!
//! Python 缺省等级 `logging.INFO = 20`;Rust 直接以字节值表达(20/30/40),
//! 与 enkeep 的 LogEngine 口径一致。
//! Python 版在 `__post_init__` 里另存创建时刻 `time`;Rust 版不存——
//! 时刻由网关/载荷方随发随记(EVENT_LOG 流自带总线时序)。

/// `logging.INFO = 20`
pub const LEVEL_INFO: i32 = 20;
/// `logging.WARNING = 30`
pub const LEVEL_WARNING: i32 = 30;
/// `logging.ERROR = 40`
pub const LEVEL_ERROR: i32 = 40;

/// 日志数据:GUI 日志面板/日志文件的载荷。
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LogData {
    /// 上游网关名
    pub gateway_name: String,
    /// 日志正文
    pub msg: String,
    /// 等级(缺省 [`LEVEL_INFO`];Python `level: int = INFO`,object.py:292)
    pub level: i32,
}

impl Default for LogData {
    /// Python 缺省等级 `logging.INFO = 20`(`object.py:292`)。
    fn default() -> Self {
        Self {
            gateway_name: String::new(),
            msg: String::new(),
            level: LEVEL_INFO,
        }
    }
}

impl LogData {
    /// 用 [`LEVEL_INFO`] 构造(Python `msg` 必填 + 缺省级别的便捷式)。
    pub fn info(gateway_name: &str, msg: impl Into<String>) -> Self {
        Self {
            gateway_name: gateway_name.to_string(),
            msg: msg.into(),
            level: LEVEL_INFO,
        }
    }

    /// 是告警级(level >= WARNING)。
    pub fn is_warning_or_above(&self) -> bool {
        self.level >= LEVEL_WARNING
    }
}