1use crate::constant::{Asset, Exchange, InstrumentType};
7
8#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct ContractData {
12 pub gateway_name: String,
14 pub symbol: String,
16 pub exchange: Exchange,
18 pub name: String,
20 pub asset: Asset,
22 pub instrument_type: Option<InstrumentType>,
24 pub size: f64,
26 pub price_tick: f64,
28
29 pub product_id: Option<String>,
31
32 pub max_limit_order_volume: Option<f64>,
34 pub min_limit_order_volume: Option<f64>,
36 pub max_market_order_volume: Option<f64>,
38 pub min_market_order_volume: Option<f64>,
40
41 pub delivery_year: Option<i32>,
43 pub delivery_month: Option<i32>,
45
46 pub open_date: Option<String>,
49 pub pre_close: Option<f64>,
51 pub up_stop_price: Option<f64>,
53 pub down_stop_price: Option<f64>,
55 pub float_volume: Option<f64>,
57 pub total_volume: Option<f64>,
59 pub instrument_status: Option<i64>,
61 pub is_trading: Option<bool>,
63}
64
65impl Default for ContractData {
66 fn default() -> Self {
69 Self {
70 asset: Asset::EQUITY,
71 size: 1.0,
72 price_tick: 0.01,
73 ..Self::EMPTY
74 }
75 }
76}
77
78impl ContractData {
79 pub fn en_symbol(&self) -> String {
81 let mut buf = String::with_capacity(self.exchange.as_str().len() + 1 + self.symbol.len());
82 self.en_symbol_into(&mut buf);
83 buf
84 }
85
86 pub fn en_symbol_into(&self, buf: &mut String) {
88 crate::symbol::write_vt_symbol(buf, &self.symbol, self.exchange);
89 }
90}
91
92impl ContractData {
94 const EMPTY: Self = Self {
95 gateway_name: String::new(),
96 symbol: String::new(),
97 exchange: crate::constant::Exchange::LOCAL,
98 name: String::new(),
99 asset: Asset::EQUITY,
100 instrument_type: None,
101 size: 0.0,
102 price_tick: 0.0,
103 product_id: None,
104 max_limit_order_volume: None,
105 min_limit_order_volume: None,
106 max_market_order_volume: None,
107 min_market_order_volume: None,
108 delivery_year: None,
109 delivery_month: None,
110 open_date: None,
111 pre_close: None,
112 up_stop_price: None,
113 down_stop_price: None,
114 float_volume: None,
115 total_volume: None,
116 instrument_status: None,
117 is_trading: None,
118 };
119}