1use crate::constant::{Direction, Exchange, Offset};
4use crate::time::DtNs;
5
6#[derive(Debug, Clone, PartialEq, Default)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct TradeData {
10 pub gateway_name: String,
12 pub symbol: String,
14 pub exchange: Exchange,
16 pub orderid: String,
18 pub tradeid: String,
20 pub direction: Option<Direction>,
22 pub offset: Offset,
24 pub price: f64,
26 pub volume: f64,
28 pub datetime: Option<DtNs>,
30
31 pub commission: f64,
33 pub slippage: f64,
35 pub trade_pnl: f64,
37
38 pub name: String,
41 pub traded_amount: f64,
43}
44
45impl TradeData {
46 pub fn en_symbol(&self) -> String {
48 crate::symbol::vt_symbol(&self.symbol, self.exchange)
49 }
50
51 pub fn en_orderid(&self) -> String {
53 format!("{}.{}", self.gateway_name, self.orderid)
54 }
55
56 pub fn en_tradeid(&self) -> String {
58 format!("{}.{}", self.gateway_name, self.tradeid)
59 }
60}