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:152-196`;含迅投 XtOrder 扩展字段)。

use crate::cancel_request::CancelRequest;
use crate::constant::{Direction, Exchange, Offset, OrderType, Status};
use crate::time::DtNs;

/// 订单最新状态跟踪数据。
#[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OrderData {
    /// 上游网关名
    pub gateway_name: String,
    /// 合约代码
    pub symbol: String,
    /// 交易所
    pub exchange: Exchange,
    /// 委托号(网关内唯一)
    pub orderid: String,

    /// 委托类型(Python `type`;Rust 改名避关键字,serde 线上字段名还原为 `"type"`)
    #[cfg_attr(feature = "serde", serde(rename = "type"))]
    pub order_type: OrderType,
    /// 方向(缺省 None)
    pub direction: Option<Direction>,
    /// 开平(缺省 NONE)
    pub offset: Offset,
    /// 委托价
    pub price: f64,
    /// 委托总量
    pub volume: f64,
    /// 已成交量
    pub traded: f64,
    /// 状态(缺省 SUBMITTING)
    pub status: Status,
    /// 时间戳(UTC 纪元纳秒;缺省 None)
    pub datetime: Option<DtNs>,
    /// 策略/来源备注
    pub reference: String,

    // —— 迅投 XtOrder 扩展(object.py:172-175)——
    /// 证券名称
    pub name: String,
    /// 委托状态描述(废单原因)
    pub status_msg: String,
    /// 成交均价
    pub traded_price: f64,
}

impl OrderData {
    /// `en_symbol`(派生方法;分配一次)。
    pub fn en_symbol(&self) -> String {
        let mut buf = String::with_capacity(self.exchange.as_str().len() + 1 + self.symbol.len());
        self.en_symbol_into(&mut buf);
        buf
    }

    /// 零分配版本:追加到复用缓冲。
    pub fn en_symbol_into(&self, buf: &mut String) {
        crate::symbol::write_vt_symbol(buf, &self.symbol, self.exchange);
    }

    /// `en_orderid` = `"{gateway_name}.{orderid}"`(`object.py:180`)。
    pub fn en_orderid(&self) -> String {
        format!("{}.{}", self.gateway_name, self.orderid)
    }

    /// 订单是否活跃(`object.py:182`;真源为 [`Status::is_active`])。
    pub fn is_active(&self) -> bool {
        self.status.is_active()
    }

    /// 由订单直接生成撤单请求(`object.py:188`)。
    pub fn create_cancel_request(&self) -> CancelRequest {
        CancelRequest {
            orderid: self.orderid.clone(),
            symbol: self.symbol.clone(),
            exchange: self.exchange,
        }
    }
}