1use crate::constant::{Direction, Exchange};
4
5#[derive(Debug, Clone, PartialEq, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct PositionData {
9 pub gateway_name: String,
11 pub symbol: String,
13 pub exchange: Exchange,
15 pub direction: Direction,
17
18 pub volume: f64,
20 pub frozen: f64,
22 pub price: f64,
24 pub pnl: f64,
26 pub yd_volume: f64,
28
29 pub name: String,
32 pub can_use_volume: f64,
34 pub market_value: f64,
36 pub on_road_volume: f64,
38 pub avg_price: f64,
40 pub last_price: f64,
42 pub profit_rate: f64,
44}
45
46impl PositionData {
47 pub fn en_symbol(&self) -> String {
49 let mut buf = String::with_capacity(self.exchange.as_str().len() + 1 + self.symbol.len());
50 self.en_symbol_into(&mut buf);
51 buf
52 }
53
54 pub fn en_symbol_into(&self, buf: &mut String) {
56 crate::symbol::write_vt_symbol(buf, &self.symbol, self.exchange);
57 }
58
59 pub fn en_positionid(&self) -> String {
65 format!(
66 "{}.{}.{}",
67 self.gateway_name,
68 self.en_symbol(),
69 self.direction.as_str()
70 )
71 }
72}