From 65133141f8cfe43539a7d50ba2e6878bab09af73 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 10 Jun 2019 14:46:36 +0800 Subject: [PATCH] [Add] HbdmGateway auto resubscribe market data when connected --- tests/trader/run.py | 8 ++++---- vnpy/gateway/hbdm/hbdm_gateway.py | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/trader/run.py b/tests/trader/run.py index 26b48183..b4e1db91 100644 --- a/tests/trader/run.py +++ b/tests/trader/run.py @@ -5,7 +5,7 @@ from vnpy.trader.ui import MainWindow, create_qapp # from vnpy.gateway.bitmex import BitmexGateway # from vnpy.gateway.futu import FutuGateway -from vnpy.gateway.ib import IbGateway +# from vnpy.gateway.ib import IbGateway # from vnpy.gateway.ctp import CtpGateway # # from vnpy.gateway.ctptest import CtptestGateway # from vnpy.gateway.femas import FemasGateway @@ -17,7 +17,7 @@ from vnpy.gateway.ib import IbGateway # from vnpy.gateway.onetoken import OnetokenGateway # from vnpy.gateway.okexf import OkexfGateway # from vnpy.gateway.xtp import XtpGateway -# from vnpy.gateway.hbdm import HbdmGateway +from vnpy.gateway.hbdm import HbdmGateway # from vnpy.gateway.tap import TapGateway # from vnpy.app.cta_strategy import CtaStrategyApp @@ -39,7 +39,7 @@ def main(): # main_engine.add_gateway(CtpGateway) # # main_engine.add_gateway(CtptestGateway) # main_engine.add_gateway(FemasGateway) - main_engine.add_gateway(IbGateway) + # main_engine.add_gateway(IbGateway) # main_engine.add_gateway(FutuGateway) # main_engine.add_gateway(BitmexGateway) # main_engine.add_gateway(TigerGateway) @@ -49,7 +49,7 @@ def main(): # main_engine.add_gateway(BitfinexGateway) # main_engine.add_gateway(OnetokenGateway) # main_engine.add_gateway(OkexfGateway) - # main_engine.add_gateway(HbdmGateway) + main_engine.add_gateway(HbdmGateway) # main_engine.add_gateway(TapGateway) # main_engine.add_app(CtaStrategyApp) diff --git a/vnpy/gateway/hbdm/hbdm_gateway.py b/vnpy/gateway/hbdm/hbdm_gateway.py index fe0d93dc..9c786ec8 100644 --- a/vnpy/gateway/hbdm/hbdm_gateway.py +++ b/vnpy/gateway/hbdm/hbdm_gateway.py @@ -957,6 +957,9 @@ class HbdmDataWebsocketApi(HbdmWebsocketApiBase): def on_connected(self): """""" self.gateway.write_log("行情Websocket API连接成功") + + for ws_symbol in self.ticks.keys(): + self.subscribe_data(ws_symbol) def subscribe(self, req: SubscribeRequest): """""" @@ -979,7 +982,11 @@ class HbdmDataWebsocketApi(HbdmWebsocketApiBase): gateway_name=self.gateway_name, ) self.ticks[ws_symbol] = tick - + + self.subscribe_data(ws_symbol) + + def subscribe_data(self, ws_symbol: str): + """""" # Subscribe to market depth update self.req_id += 1 req = {