def subscribe_by_symbol(self, symbol: str) -> None: """""" # Create tick data buffer tick = TickData( symbol=symbol, name=symbol_name_map.get(symbol, ""), exchange=Exchange.HUOBI, datetime=datetime.now(CHINA_TZ), gateway_name=self.gateway_name, ) self.ticks[symbol] = tick bar = BarData(symbol=symbol, exchange=Exchange.HUOBI, datetime=datetime.now(CHINA_TZ), gateway_name=self.gateway_name, interval=Interval.MINUTE) self.bars[symbol] = bar # Subscribe to market depth update self.req_id += 1 req = {"sub": f"market.{symbol}.depth.step0", "id": str(self.req_id)} self.send_packet(req) # Subscribe to market detail update self.req_id += 1 req = {"sub": f"market.{symbol}.detail", "id": str(self.req_id)} self.send_packet(req) # Subscribe to market kline update self.req_id += 1 req = {"sub": f"market.{symbol}.kline.1min", "id": str(self.req_id)} self.send_packet(req)
def to_tick(self): """""" tick = TickData(symbol=self.name, exchange=Exchange.LOCAL, datetime=self.datetime, name=self.name, last_price=(self.bid_price + self.ask_price) / 2, bid_price_1=self.bid_price, ask_price_1=self.ask_price, bid_volume_1=self.bid_volume, ask_volume_1=self.ask_volume, gateway_name="SPREAD") return tick
def subscribe(self, req: SubscribeRequest) -> None: """""" # buf = [i for i in req.symbol if not i.isdigit()] # symbol = "".join(buf) # ws_symbol = f"{symbol}" # Create tick data buffer tick = TickData( symbol=req.symbol, name=req.symbol, exchange=Exchange.HUOBI, datetime=datetime.now(CHINA_TZ), gateway_name=self.gateway_name, ) self.ticks[req.symbol] = tick self.subscribe_data(req.symbol)
def subscribe(self, req: SubscribeRequest): """""" contract_type = symbol_type_map.get(req.symbol, "") if not contract_type: return buf = [i for i in req.symbol if not i.isdigit()] symbol = "".join(buf) ws_contract_type = CONTRACT_TYPE_MAP[contract_type] ws_symbol = f"{symbol}_{ws_contract_type}" # Create tick data buffer tick = TickData( symbol=req.symbol, name=req.symbol, exchange=Exchange.HUOBI, datetime=datetime.now(CHINA_TZ), gateway_name=self.gateway_name, ) self.ticks[ws_symbol] = tick self.subscribe_data(ws_symbol)
def to_tick(self): """ Generate TickData object from DbTickData. """ tick = TickData( symbol=self.symbol, exchange=Exchange(self.exchange), datetime=DB_TZ.localize(self.datetime), name=self.name, volume=self.volume, open_interest=self.open_interest, last_price=self.last_price, last_volume=self.last_volume, limit_up=self.limit_up, limit_down=self.limit_down, open_price=self.open_price, high_price=self.high_price, low_price=self.low_price, pre_close=self.pre_close, bid_price_1=self.bid_price_1, ask_price_1=self.ask_price_1, bid_volume_1=self.bid_volume_1, ask_volume_1=self.ask_volume_1, gateway_name="DB", ) if self.bid_price_2: tick.bid_price_2 = self.bid_price_2 tick.bid_price_3 = self.bid_price_3 tick.bid_price_4 = self.bid_price_4 tick.bid_price_5 = self.bid_price_5 tick.ask_price_2 = self.ask_price_2 tick.ask_price_3 = self.ask_price_3 tick.ask_price_4 = self.ask_price_4 tick.ask_price_5 = self.ask_price_5 tick.bid_volume_2 = self.bid_volume_2 tick.bid_volume_3 = self.bid_volume_3 tick.bid_volume_4 = self.bid_volume_4 tick.bid_volume_5 = self.bid_volume_5 tick.ask_volume_2 = self.ask_volume_2 tick.ask_volume_3 = self.ask_volume_3 tick.ask_volume_4 = self.ask_volume_4 tick.ask_volume_5 = self.ask_volume_5 return tick