use crate::constant::Exchange;
use crate::time::DtNs;
#[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TickData {
pub gateway_name: String,
pub symbol: String,
pub exchange: Exchange,
pub datetime: DtNs,
pub trading_day: Option<i32>,
pub action_day: Option<i32>,
pub update_time: String,
pub update_millisec: i64,
pub name: String,
pub volume: f64,
pub turnover: f64,
pub open_interest: f64,
pub last_price: f64,
pub last_volume: f64,
pub limit_up: f64,
pub limit_down: f64,
pub open_price: f64,
pub high_price: f64,
pub low_price: f64,
pub pre_close: f64,
pub pct_change: f64,
pub bid_price_1: f64,
pub bid_price_2: f64,
pub bid_price_3: f64,
pub bid_price_4: f64,
pub bid_price_5: f64,
pub ask_price_1: f64,
pub ask_price_2: f64,
pub ask_price_3: f64,
pub ask_price_4: f64,
pub ask_price_5: f64,
pub bid_volume_1: f64,
pub bid_volume_2: f64,
pub bid_volume_3: f64,
pub bid_volume_4: f64,
pub bid_volume_5: f64,
pub ask_volume_1: f64,
pub ask_volume_2: f64,
pub ask_volume_3: f64,
pub ask_volume_4: f64,
pub ask_volume_5: f64,
pub localtime: Option<DtNs>,
}
impl TickData {
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 reach_limit_up(&self, diff_price: f64) -> bool {
self.bid_price_1 + diff_price >= self.limit_up
}
pub fn reach_limit_down(&self, diff_price: f64) -> bool {
self.ask_price_1 - diff_price <= self.limit_down
}
pub fn reach_limit(&self, diff_price: f64) -> bool {
self.reach_limit_up(diff_price) || self.reach_limit_down(diff_price)
}
}