From e2e93cef3bf463cbc9a1782449b1ed30ecc89525 Mon Sep 17 00:00:00 2001 From: nanoric Date: Fri, 8 Mar 2019 06:26:17 -0400 Subject: [PATCH] =?UTF-8?q?[Fix]=20oes.MdApi:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=80=80=E5=87=BA=E6=97=B6=E8=BF=98=E5=9C=A8=E9=87=8D=E8=BF=9E?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/gateway/oes/oes_md.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/vnpy/gateway/oes/oes_md.py b/vnpy/gateway/oes/oes_md.py index 9d76e1ae..75d41432 100644 --- a/vnpy/gateway/oes/oes_md.py +++ b/vnpy/gateway/oes/oes_md.py @@ -6,13 +6,12 @@ from threading import Thread from typing import Any, Callable, Dict from vnpy.api.oes.vnoes import MdsApiClientEnvT, MdsApi_DestoryAll, MdsApi_InitAllByConvention, \ - MdsApi_IsValidQryChannel, MdsApi_IsValidTcpChannel, MdsApi_LogoutAll, \ - MdsApi_SubscribeMarketData, MdsApi_WaitOnMsg, MdsL2StockSnapshotBodyT, MdsMktDataRequestEntryT, \ - MdsMktDataRequestReqT, MdsMktRspMsgBodyT, MdsStockSnapshotBodyT, SGeneralClientChannelT, \ - SMsgHeadT, SPlatform_IsNegEpipe, SPlatform_IsNegEtimeout, cast, eMdsExchangeIdT, \ - eMdsMktSubscribeFlagT, eMdsMsgTypeT, eMdsSecurityTypeT, eMdsSubscribeDataTypeT, \ - eMdsSubscribeModeT, eMdsSubscribedTickExpireTypeT, eSMsgProtocolTypeT, MdsApi_SetThreadUsername, \ - MdsApi_SetThreadPassword + MdsApi_IsValidQryChannel, MdsApi_IsValidTcpChannel, MdsApi_LogoutAll, MdsApi_SetThreadPassword, \ + MdsApi_SetThreadUsername, MdsApi_SubscribeMarketData, MdsApi_WaitOnMsg, MdsL2StockSnapshotBodyT, \ + MdsMktDataRequestEntryT, MdsMktDataRequestReqT, MdsMktRspMsgBodyT, MdsStockSnapshotBodyT, \ + SGeneralClientChannelT, SMsgHeadT, SPlatform_IsNegEpipe, SPlatform_IsNegEtimeout, cast, \ + eMdsExchangeIdT, eMdsMktSubscribeFlagT, eMdsMsgTypeT, eMdsSecurityTypeT, eMdsSubscribeDataTypeT, \ + eMdsSubscribeModeT, eMdsSubscribedTickExpireTypeT, eSMsgProtocolTypeT from vnpy.trader.constant import Exchange from vnpy.trader.gateway import BaseGateway @@ -36,11 +35,13 @@ class OesMdMessageLoop: self.th = Thread(target=self.message_loop) self.message_handlers: Dict[int, Callable[[dict], None]] = { + # tick & orderbook eMdsMsgTypeT.MDS_MSGTYPE_MARKET_DATA_SNAPSHOT_FULL_REFRESH: self.on_market_full_refresh, eMdsMsgTypeT.MDS_MSGTYPE_L2_MARKET_DATA_SNAPSHOT: self.on_l2_market_data_snapshot, eMdsMsgTypeT.MDS_MSGTYPE_L2_ORDER: self.on_l2_order, eMdsMsgTypeT.MDS_MSGTYPE_L2_TRADE: self.on_l2_trade, + # others eMdsMsgTypeT.MDS_MSGTYPE_QRY_SECURITY_STATUS: self.on_security_status, eMdsMsgTypeT.MDS_MSGTYPE_L2_MARKET_DATA_INCREMENTAL: lambda x: 1, eMdsMsgTypeT.MDS_MSGTYPE_L2_BEST_ORDERS_SNAPSHOT: self.on_best_orders_snapshot, @@ -50,6 +51,7 @@ class OesMdMessageLoop: eMdsMsgTypeT.MDS_MSGTYPE_TRADING_SESSION_STATUS: self.on_trading_session_status, eMdsMsgTypeT.MDS_MSGTYPE_SECURITY_STATUS: self.on_security_status, eMdsMsgTypeT.MDS_MSGTYPE_MARKET_DATA_REQUEST: self.on_market_data_request, + eMdsMsgTypeT.MDS_MSGTYPE_HEARTBEAT: lambda x: 1, } self.last_tick: Dict[str, TickData] = {} @@ -76,6 +78,9 @@ class OesMdMessageLoop: self.alive = True self.th.start() + def stop(self): + self.alive = False + def join(self): self.th.join() @@ -113,7 +118,7 @@ class OesMdMessageLoop: # pass # just no message if is_disconnected(ret): self.gateway.write_log(_("与行情服务器的连接已断开。")) - while not self.reconnect(): + while not self.reconnect() and self.alive: time.sleep(1) return @@ -180,9 +185,6 @@ class OesMdMessageLoop: def on_security_status(self, d: MdsMktRspMsgBodyT): pass - def stop(self): - self.alive = False - class OesMdApi: