1use crate::cancel_request::CancelRequest;
4use crate::constant::{Direction, Exchange, Offset, OrderType, Status, ACTIVE_STATUSES};
5use crate::time::DtNs;
6
7#[derive(Debug, Clone, PartialEq, Default)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct OrderData {
11 pub gateway_name: String,
13 pub symbol: String,
15 pub exchange: Exchange,
17 pub orderid: String,
19
20 #[cfg_attr(feature = "serde", serde(rename = "type"))]
22 pub order_type: OrderType,
23 pub direction: Option<Direction>,
25 pub offset: Offset,
27 pub price: f64,
29 pub volume: f64,
31 pub traded: f64,
33 pub status: Status,
35 pub datetime: Option<DtNs>,
37 pub reference: String,
39
40 pub name: String,
43 pub status_msg: String,
45 pub traded_price: f64,
47}
48
49impl OrderData {
50 pub fn en_symbol(&self) -> String {
52 crate::symbol::vt_symbol(&self.symbol, self.exchange)
53 }
54
55 pub fn en_orderid(&self) -> String {
57 format!("{}.{}", self.gateway_name, self.orderid)
58 }
59
60 pub fn is_active(&self) -> bool {
62 ACTIVE_STATUSES.contains(&self.status)
63 }
64
65 pub fn create_cancel_request(&self) -> CancelRequest {
67 CancelRequest {
68 orderid: self.orderid.clone(),
69 symbol: self.symbol.clone(),
70 exchange: self.exchange,
71 }
72 }
73}