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,
pub direction: Option<Direction>,
pub offset: Offset,
pub price: f64,
pub volume: f64,
pub datetime: Option<DtNs>,
pub commission: f64,
pub slippage: f64,
pub trade_pnl: f64,
pub name: String,
pub traded_amount: f64,
}
impl TradeData {
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);
}
pub fn en_orderid(&self) -> String {
format!("{}.{}", self.gateway_name, self.orderid)
}
pub fn en_tradeid(&self) -> String {
format!("{}.{}", self.gateway_name, self.tradeid)
}
}