From 90f535d5cba87ee36872211553a904d827cb4c6d Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 28 Mar 2018 13:02:04 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E4=BA=A4=E6=98=93=E7=BB=84=E4=BB=B6=E7=9A=84Tick=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=9C=BA=E5=88=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/uiBasicWidget.py | 81 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index 62c0c65a..ee385bd2 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -721,7 +721,7 @@ class TradingWidget(QtWidgets.QFrame): self.gatewayList.extend(gatewayNameList) self.initUi() - self.connectSignal() + self.registerEvent() #---------------------------------------------------------------------- def initUi(self): @@ -961,10 +961,6 @@ class TradingWidget(QtWidgets.QFrame): self.labelLastPrice.setText('') self.labelReturn.setText('') - # 重新注册事件监听 - self.eventEngine.unregister(EVENT_TICK + self.symbol, self.signal.emit) - self.eventEngine.register(EVENT_TICK + vtSymbol, self.signal.emit) - # 订阅合约 req = VtSubscribeReq() req.symbol = symbol @@ -984,48 +980,51 @@ class TradingWidget(QtWidgets.QFrame): def updateTick(self, event): """更新行情""" tick = event.dict_['data'] + if tick.vtSymbol != self.symbol: + return + + if not self.checkFixed.isChecked(): + self.spinPrice.setValue(tick.lastPrice) + + self.labelBidPrice1.setText(str(tick.bidPrice1)) + self.labelAskPrice1.setText(str(tick.askPrice1)) + self.labelBidVolume1.setText(str(tick.bidVolume1)) + self.labelAskVolume1.setText(str(tick.askVolume1)) + + if tick.bidPrice2: + self.labelBidPrice2.setText(str(tick.bidPrice2)) + self.labelBidPrice3.setText(str(tick.bidPrice3)) + self.labelBidPrice4.setText(str(tick.bidPrice4)) + self.labelBidPrice5.setText(str(tick.bidPrice5)) - if tick.vtSymbol == self.symbol: - if not self.checkFixed.isChecked(): - self.spinPrice.setValue(tick.lastPrice) - self.labelBidPrice1.setText(str(tick.bidPrice1)) - self.labelAskPrice1.setText(str(tick.askPrice1)) - self.labelBidVolume1.setText(str(tick.bidVolume1)) - self.labelAskVolume1.setText(str(tick.askVolume1)) - - if tick.bidPrice2: - self.labelBidPrice2.setText(str(tick.bidPrice2)) - self.labelBidPrice3.setText(str(tick.bidPrice3)) - self.labelBidPrice4.setText(str(tick.bidPrice4)) - self.labelBidPrice5.setText(str(tick.bidPrice5)) - - self.labelAskPrice2.setText(str(tick.askPrice2)) - self.labelAskPrice3.setText(str(tick.askPrice3)) - self.labelAskPrice4.setText(str(tick.askPrice4)) - self.labelAskPrice5.setText(str(tick.askPrice5)) - - self.labelBidVolume2.setText(str(tick.bidVolume2)) - self.labelBidVolume3.setText(str(tick.bidVolume3)) - self.labelBidVolume4.setText(str(tick.bidVolume4)) - self.labelBidVolume5.setText(str(tick.bidVolume5)) - - self.labelAskVolume2.setText(str(tick.askVolume2)) - self.labelAskVolume3.setText(str(tick.askVolume3)) - self.labelAskVolume4.setText(str(tick.askVolume4)) - self.labelAskVolume5.setText(str(tick.askVolume5)) + self.labelAskPrice2.setText(str(tick.askPrice2)) + self.labelAskPrice3.setText(str(tick.askPrice3)) + self.labelAskPrice4.setText(str(tick.askPrice4)) + self.labelAskPrice5.setText(str(tick.askPrice5)) - self.labelLastPrice.setText(str(tick.lastPrice)) + self.labelBidVolume2.setText(str(tick.bidVolume2)) + self.labelBidVolume3.setText(str(tick.bidVolume3)) + self.labelBidVolume4.setText(str(tick.bidVolume4)) + self.labelBidVolume5.setText(str(tick.bidVolume5)) - if tick.preClosePrice: - rt = (tick.lastPrice/tick.preClosePrice)-1 - self.labelReturn.setText(('%.2f' %(rt*100))+'%') - else: - self.labelReturn.setText('') + self.labelAskVolume2.setText(str(tick.askVolume2)) + self.labelAskVolume3.setText(str(tick.askVolume3)) + self.labelAskVolume4.setText(str(tick.askVolume4)) + self.labelAskVolume5.setText(str(tick.askVolume5)) + + self.labelLastPrice.setText(str(tick.lastPrice)) + + if tick.preClosePrice: + rt = (tick.lastPrice/tick.preClosePrice)-1 + self.labelReturn.setText(('%.2f' %(rt*100))+'%') + else: + self.labelReturn.setText('') #---------------------------------------------------------------------- - def connectSignal(self): - """连接Signal""" + def registerEvent(self): + """注册事件监听""" self.signal.connect(self.updateTick) + self.eventEngine.register(EVENT_TICK, self.signal.emit) #---------------------------------------------------------------------- def sendOrder(self):