From 763ce46410e48785a7982124a7313c706756d662 Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Tue, 8 Nov 2016 22:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E8=BE=BE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E5=AE=89=E5=85=A8=E9=80=80=E5=87=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/shzdGateway/shzdGateway.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/vn.trader/shzdGateway/shzdGateway.py b/vn.trader/shzdGateway/shzdGateway.py index eaea2303..b740406b 100644 --- a/vn.trader/shzdGateway/shzdGateway.py +++ b/vn.trader/shzdGateway/shzdGateway.py @@ -77,9 +77,13 @@ class ShzdGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) + #fileName = os.getcwd() + '/shzdGateway/' + fileName + from vtFunction import filePath + path = filePath() + #path = os.path.abspath(os.path.dirname(__file__)) + print 'path:', path fileName = os.path.join(path, fileName) - + try: f = file(fileName) except IOError: @@ -146,7 +150,7 @@ class ShzdGateway(VtGateway): #---------------------------------------------------------------------- def close(self): """关闭""" - self.api.release() # 释放接口对象 + self.api.close() # 释放接口对象 #---------------------------------------------------------------------- def initQuery(self): @@ -223,6 +227,9 @@ class ShzdGatewayApi(ShzdApi): # 持仓缓存 self.posDict = {} # key为vtPositionName,value为VtPositionData + # 是否进行了初始化 + self.inited = False + self.initCallbacks() #---------------------------------------------------------------------- @@ -578,6 +585,7 @@ class ShzdGatewayApi(ShzdApi): return else: self.gateway.writeLog(u'接口初始化成功') + self.inited = True # 连接交易服务器 n = self.registerFront(frontAddress, frontPort) @@ -710,6 +718,11 @@ class ShzdGatewayApi(ShzdApi): req['11'] = self.accountNo self.shzdSendInfoToTrade(req) + #---------------------------------------------------------------------- + def close(self): + """关闭接口""" + if self.inited: + self.release() #---------------------------------------------------------------------- def printDict(d): @@ -719,4 +732,4 @@ def printDict(d): l.sort() for k in l: print k, ':', d[k] - + \ No newline at end of file