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:199-232`;含迅投 XtTrade 扩展字段)。

use crate::constant::{Direction, Exchange, Offset};
use crate::time::DtNs;

/// 成交回报数据:一单可多笔。
#[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TradeData {
    /// 上游网关名
    pub gateway_name: String,
    /// 合约代码
    pub symbol: String,
    /// 交易所
    pub exchange: Exchange,
    /// 所属委托号(网关内唯一)
    pub orderid: String,
    /// 成交号(网关内唯一)
    pub tradeid: String,
    /// 方向(缺省 None)
    pub direction: Option<Direction>,
    /// 开平(缺省 NONE)
    pub offset: Offset,
    /// 成交价
    pub price: f64,
    /// 成交量
    pub volume: f64,
    /// 时间戳(UTC 纪元纳秒;缺省 None)
    pub datetime: Option<DtNs>,

    /// 手续费(enkeep 扩展)
    pub commission: f64,
    /// 滑点(enkeep 扩展)
    pub slippage: f64,
    /// 平仓盈亏(平仓时计算,enkeep 扩展)
    pub trade_pnl: f64,

    // —— 迅投 XtTrade 扩展(object.py:222-225)——
    /// 证券名称
    pub name: String,
    /// 成交金额
    pub traded_amount: f64,
}

impl TradeData {
    /// `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:230`)。
    pub fn en_orderid(&self) -> String {
        format!("{}.{}", self.gateway_name, self.orderid)
    }

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