use crate::constant::{Asset, Exchange, InstrumentType};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ContractData {
pub gateway_name: String,
pub symbol: String,
pub exchange: Exchange,
pub name: String,
pub asset: Asset,
pub instrument_type: Option<InstrumentType>,
pub size: f64,
pub price_tick: f64,
pub product_id: Option<String>,
pub max_limit_order_volume: Option<f64>,
pub min_limit_order_volume: Option<f64>,
pub max_market_order_volume: Option<f64>,
pub min_market_order_volume: Option<f64>,
pub delivery_year: Option<i32>,
pub delivery_month: Option<i32>,
pub open_date: Option<String>,
pub pre_close: Option<f64>,
pub up_stop_price: Option<f64>,
pub down_stop_price: Option<f64>,
pub float_volume: Option<f64>,
pub total_volume: Option<f64>,
pub instrument_status: Option<i64>,
pub is_trading: Option<bool>,
}
impl Default for ContractData {
fn default() -> Self {
Self {
asset: Asset::EQUITY,
size: 1.0,
price_tick: 0.01,
..Self::EMPTY
}
}
}
impl ContractData {
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);
}
}
impl ContractData {
const EMPTY: Self = Self {
gateway_name: String::new(),
symbol: String::new(),
exchange: crate::constant::Exchange::LOCAL,
name: String::new(),
asset: Asset::EQUITY,
instrument_type: None,
size: 0.0,
price_tick: 0.0,
product_id: None,
max_limit_order_volume: None,
min_limit_order_volume: None,
max_market_order_volume: None,
min_market_order_volume: None,
delivery_year: None,
delivery_month: None,
open_date: None,
pre_close: None,
up_stop_price: None,
down_stop_price: None,
float_volume: None,
total_volume: None,
instrument_status: None,
is_trading: None,
};
}