use crate::cancel_request::CancelRequest;
use crate::constant::{Direction, Exchange, Offset, OrderType, Status, ACTIVE_STATUSES};
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,
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub order_type: OrderType,
pub direction: Option<Direction>,
pub offset: Offset,
pub price: f64,
pub volume: f64,
pub traded: f64,
pub status: Status,
pub datetime: Option<DtNs>,
pub reference: String,
pub name: String,
pub status_msg: String,
pub traded_price: f64,
}
impl OrderData {
pub fn en_symbol(&self) -> String {
crate::symbol::vt_symbol(&self.symbol, self.exchange)
}
pub fn en_orderid(&self) -> String {
format!("{}.{}", self.gateway_name, self.orderid)
}
pub fn is_active(&self) -> bool {
ACTIVE_STATUSES.contains(&self.status)
}
pub fn create_cancel_request(&self) -> CancelRequest {
CancelRequest {
orderid: self.orderid.clone(),
symbol: self.symbol.clone(),
exchange: self.exchange,
}
}
}