可以给Tick增加很多额外的信息用来做交易
买卖价差,开平状态,订单簿深度,斜率,涨跌,涨跌幅 等等
@dataclass
class TickData(BaseData):
"""
Tick data contains information about:
* last trade in market
* orderbook snapshot
* intraday market statistics.
"""
symbol: str
exchange: Exchange
datetime: datetime
name: str = ""
volume: float = 0
open_interest: float = 0
last_price: float = 0
last_volume: float = 0
limit_up: float = 0
limit_down: float = 0
open_price: float = 0
high_price: float = 0
low_price: float = 0
pre_close: float = 0
bid_price_1: float = 0
bid_price_2: float = 0
bid_price_3: float = 0
bid_price_4: float = 0
bid_price_5: float = 0
ask_price_1: float = 0
ask_price_2: float = 0
ask_price_3: float = 0
ask_price_4: float = 0
ask_price_5: float = 0
bid_volume_1: float = 0
bid_volume_2: float = 0
bid_volume_3: float = 0
bid_volume_4: float = 0
bid_volume_5: float = 0
ask_volume_1: float = 0
ask_volume_2: float = 0
ask_volume_3: float = 0
ask_volume_4: float = 0
ask_volume_5: float = 0
@property
def spread(self):
"""买卖价差"""
try:
return round(self.ask_price_1 - self.bid_price_1, 2)
except:
return None
@property
def offset(self):
"""
开平状态:多开,空开,空平,多平,多换,空换
"""
pass
@property
def depth(self):
"""订单簿深度"""
try:
return round((self.ask_volume_1 + self.bid_volume_1) / 2, 2)
except:
return None
@property
def slope(self):
"""斜率"""
try:
return round(self.spread / self.depth, 2)
except:
return None
@property
def change(self):
"""涨跌"""
try:
return round(self.last_price - self.pre_close, 2)
except:
return None
@property
def change_rate(self):
"""涨跌幅"""
try:
return round(100 * (self.last_price - self.pre_close) / self.pre_close, 2)
except:
return None
def __post_init__(self):
""""""
self.vt_symbol = f"{self.symbol}.{self.exchange.value}"