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
//! 成交对象(`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 {
crate::symbol::vt_symbol(&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)
}
}