From d519cfbdfea8e559542fc69b0c3667216cd22eb4 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 6 Jan 2018 13:30:58 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E6=B7=BB=E5=8A=A0xtpGateway=E7=9A=84?= =?UTF-8?q?=E6=96=AD=E7=BA=BF=E9=87=8D=E8=BF=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/gateway/xtpGateway/xtpGateway.py | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/vnpy/trader/gateway/xtpGateway/xtpGateway.py b/vnpy/trader/gateway/xtpGateway/xtpGateway.py index e44f5dd1..95a30581 100644 --- a/vnpy/trader/gateway/xtpGateway/xtpGateway.py +++ b/vnpy/trader/gateway/xtpGateway/xtpGateway.py @@ -261,6 +261,16 @@ class XtpMdApi(QuoteApi): content = (u'行情服务器连接断开,原因:%s' %reason) self.writeLog(content) + # 重新连接 + n = self.login(self.address, self.port, self.userID, self.password, 1) + if not n: + self.connectionStatus = True + self.loginStatus = True + self.gateway.mdConnected = True + self.writeLog(u'行情服务器登录成功') + else: + self.writeLog(u'行情服务器登录失败,原因:%s' %n) + #---------------------------------------------------------------------- def onError(self, error): """错误回报""" @@ -418,7 +428,6 @@ class XtpMdApi(QuoteApi): os.makedirs(path) self.createQuoteApi(clientID, path) - print address, port, userID, password n = self.login(address, port, userID, password, 1) if not n: self.connectionStatus = True @@ -501,6 +510,18 @@ class XtpTdApi(TraderApi): content = (u'交易服务器连接断开,原因:%s' %reason) self.writeLog(content) + # 发起重新连接 + n = self.login(self.address, self.port, self.userID, self.password, 1) + + if n: + self.sessionID = n + self.connectionStatus = True + self.loginStatus = True + self.gateway.tdConnected = True + self.writeLog(u'交易服务器登录成功,会话编号:%s' %n) + else: + self.writeLog(u'交易服务器登录失败') + #---------------------------------------------------------------------- def onError(self, data): """错误回报"""