[Fix] OesGateway:Optimized connect status detection
This commit is contained in:
parent
71d34d5854
commit
459fc4770f
@ -11,9 +11,10 @@ from vnpy.api.oes.vnoes import MdsApiClientEnvT, MdsApi_DestoryAll, MdsApi_InitL
|
||||
MdsMktDataRequestEntryT, MdsMktDataRequestReqBufT, MdsMktDataRequestReqT, MdsMktRspMsgBodyT, \
|
||||
MdsStockSnapshotBodyT, SGeneralClientChannelT, SMsgHeadT, SPlatform_IsNegEpipe, cast, \
|
||||
eMdsExchangeIdT, eMdsMktSubscribeFlagT, eMdsMsgTypeT, eMdsSecurityTypeT, eMdsSubscribeDataTypeT, \
|
||||
eMdsSubscribeModeT, eMdsSubscribedTickExpireTypeT, eMdsSubscribedTickTypeT, eSMsgProtocolTypeT
|
||||
eMdsSubscribeModeT, eMdsSubscribedTickExpireTypeT, eMdsSubscribedTickTypeT, eSMsgProtocolTypeT, \
|
||||
SPlatform_IsNegEconnaborted
|
||||
|
||||
from vnpy.gateway.oes.utils import create_remote_config
|
||||
from vnpy.gateway.oes.utils import create_remote_config, is_disconnected
|
||||
from vnpy.trader.constant import Exchange
|
||||
from vnpy.trader.gateway import BaseGateway
|
||||
from vnpy.trader.object import SubscribeRequest, TickData
|
||||
@ -118,8 +119,6 @@ class OesMdMessageLoop:
|
||||
""""""
|
||||
tcp_channel = self.env.tcpChannel
|
||||
timeout_ms = 1000
|
||||
# is_timeout = SPlatform_IsNegEtimeout
|
||||
is_disconnected = SPlatform_IsNegEpipe
|
||||
while self._alive:
|
||||
ret = MdsApi_WaitOnMsg(tcp_channel,
|
||||
timeout_ms,
|
||||
|
@ -18,7 +18,7 @@ from vnpy.api.oes.vnoes import OesApiClientEnvT, OesApiSubscribeInfoT, OesApi_De
|
||||
eOesOrdStatusT, eOesOrdTypeShT, eOesOrdTypeSzT, eOesSubscribeReportTypeT
|
||||
|
||||
from vnpy.gateway.oes.error_code import error_to_str
|
||||
from vnpy.gateway.oes.utils import create_remote_config
|
||||
from vnpy.gateway.oes.utils import create_remote_config, is_disconnected
|
||||
from vnpy.trader.constant import Direction, Exchange, Offset, PriceType, Product, Status
|
||||
from vnpy.trader.gateway import BaseGateway
|
||||
from vnpy.trader.object import AccountData, CancelRequest, ContractData, OrderData, OrderRequest, \
|
||||
@ -177,7 +177,6 @@ class OesTdMessageLoop:
|
||||
""""""
|
||||
rpt_channel = self._env.rptChannel
|
||||
timeout_ms = 1000
|
||||
is_disconnected = SPlatform_IsNegEpipe
|
||||
|
||||
while self._alive:
|
||||
ret = OesApi_WaitReportMsg(rpt_channel,
|
||||
@ -643,7 +642,7 @@ class OesTdApi:
|
||||
else:
|
||||
order.status = Status.REJECTED
|
||||
self.gateway.write_log(_("下单失败")) # todo: can I stringify error?
|
||||
if ret == -108: # is here any other ret code indicating connection lost?
|
||||
if is_disconnected(ret):
|
||||
self.gateway.write_log(_("下单时连接发现连接已断开,正在尝试重连"))
|
||||
self._schedule_reconnect_ord_channel()
|
||||
self.gateway.on_order(order)
|
||||
@ -667,7 +666,7 @@ class OesTdApi:
|
||||
oes_req)
|
||||
if ret < 0:
|
||||
self.gateway.write_log(_("撤单失败")) # todo: can I stringify error?
|
||||
if ret == -108: # is here any other ret code indicating connection lost?
|
||||
if is_disconnected(ret): # is here any other ret code indicating connection lost?
|
||||
self.gateway.write_log(_("撤单时连接发现连接已断开,正在尝试重连"))
|
||||
self._schedule_reconnect_ord_channel()
|
||||
|
||||
|
@ -9,6 +9,9 @@ with open(config_template_path, "rt", encoding='utf-8') as f:
|
||||
|
||||
|
||||
def create_remote_config(server: str, username: str, password: str):
|
||||
"""
|
||||
create a SGeneralClientRemoteCfgT.
|
||||
"""
|
||||
cfg = SGeneralClientRemoteCfgT()
|
||||
cfg.username = username
|
||||
cfg.password = password
|
||||
@ -28,3 +31,13 @@ def create_remote_config(server: str, username: str, password: str):
|
||||
cfg.socketOpt.keepCnt = 9
|
||||
return cfg
|
||||
|
||||
|
||||
def is_disconnected(ret: int):
|
||||
"""
|
||||
check whether connection is lost by return value of OesApi/MdsApi
|
||||
106 : ECONNABORTED
|
||||
107 : ECONNREFUSED
|
||||
108 : ECONNRESET
|
||||
maybe there is more than there error codes indicating a disconnected state
|
||||
"""
|
||||
return ret == -106 or ret == -107 or ret == -108
|
||||
|
Loading…
Reference in New Issue
Block a user