use crate::cancel_request::CancelRequest;
use crate::constant::{Direction, Exchange, Offset, OrderType, Status};
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 {
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 is_active(&self) -> bool {
self.status.is_active()
}
pub fn create_cancel_request(&self) -> CancelRequest {
CancelRequest {
orderid: self.orderid.clone(),
symbol: self.symbol.clone(),
exchange: self.exchange,
}
}
}