From e6762a63e3e289cebbd4d8e2cbd9cfcfaf7e7302 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 13 Jun 2017 14:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0wind=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=9C=A8=E6=9C=AA=E8=BF=9E=E6=8E=A5=E6=97=B6=E7=9A=84=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trader/gateway/windGateway/windGateway.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/vnpy/trader/gateway/windGateway/windGateway.py b/vnpy/trader/gateway/windGateway/windGateway.py index d1307841..279eac5c 100644 --- a/vnpy/trader/gateway/windGateway/windGateway.py +++ b/vnpy/trader/gateway/windGateway/windGateway.py @@ -85,6 +85,9 @@ class WindGateway(VtGateway): # 而vt中的tick是完整更新,因此需要本地维护一个所有字段的快照 self.tickDict = {} + # 订阅请求缓存 + self.subscribeBufferDict = {} + self.registerEvent() #---------------------------------------------------------------------- @@ -100,8 +103,14 @@ class WindGateway(VtGateway): def subscribe(self, subscribeReq): """订阅行情""" windSymbol = '.'.join([subscribeReq.symbol, exchangeMap[subscribeReq.exchange]]) - data = self.w.wsq(windSymbol, self.wsqParam, func=self.wsqCallBack) - + + # 若已经连接则直接订阅 + if self.connected: + data = self.w.wsq(windSymbol, self.wsqParam, func=self.wsqCallBack) + # 否则缓存在字典中 + else: + self.subscribeBufferDict[windSymbol] = subscribeReq + #---------------------------------------------------------------------- def sendOrder(self, orderReq): """发单""" @@ -160,7 +169,7 @@ class WindGateway(VtGateway): self.tickDict[windSymbol] = tick dt = data.Times[0] - tick.time = dt.strftime('%H:%M:%S') + tick.time = dt.strftime('%H:%M:%S.%f') tick.date = dt.strftime('%Y%m%d') # 采用遍历的形式读取数值 @@ -186,6 +195,11 @@ class WindGateway(VtGateway): if not result.ErrorCode: log.logContent = u'Wind接口连接成功' + + # 发出缓存的订阅请求 + for req in self.subscribeBufferDict.values(): + self.subscribe(req) + self.subscribeBufferDict.clear() else: log.logContent = u'Wind接口连接失败,错误代码%d' %result.ErrorCode self.onLog(log) \ No newline at end of file