From 628dee6230bf6e621ac6ab70ead9c533162b87c7 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Sun, 17 Feb 2019 13:47:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E8=B0=83=E6=95=B4=E5=88=97?= =?UTF-8?q?=E5=AE=BD=EF=BC=8C=E5=BD=B1=E5=93=8D=E6=98=BE=E7=A4=BA=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/uiBasicWidget.py | 80 +++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index 0bcd4612..59b39ea1 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -359,7 +359,7 @@ class BasicMonitor(QtWidgets.QTableWidget): self.setItem(0, n, cell) # 调整列宽 - self.resizeColumns() + #self.resizeColumns() # 重新打开排序 if self.sorting: @@ -1111,39 +1111,50 @@ class TradingWidget(QtWidgets.QFrame): #---------------------------------------------------------------------- def sendOrder(self): """发单""" - symbol = str(self.lineSymbol.text()) - vtSymbol = symbol - exchange = self.comboExchange.currentText() - currency = self.comboCurrency.currentText() - productClass = self.comboProductClass.currentText() - gatewayName = self.comboGateway.currentText() - - # 查询合约 - if exchange: - vtSymbol = '.'.join([symbol, exchange]) - contract = self.mainEngine.getContract(vtSymbol) - else: + try: + symbol = str(self.lineSymbol.text()) vtSymbol = symbol - contract = self.mainEngine.getContract(symbol) - - if contract: - if not gatewayName: - gatewayName = contract.gatewayName - exchange = contract.exchange # 保证有交易所代码 - - req = VtOrderReq() - req.symbol = symbol - req.vtSymbol = vtSymbol - req.exchange = exchange - req.price = self.spinPrice.value() - req.volume = self.spinVolume.value() - req.direction = self.comboDirection.currentText() - req.priceType = self.comboPriceType.currentText() - req.offset = self.comboOffset.currentText() - req.currency = currency - req.productClass = productClass - - self.mainEngine.sendOrder(req, gatewayName) + exchange = self.comboExchange.currentText() + currency = self.comboCurrency.currentText() + productClass = self.comboProductClass.currentText() + gatewayName = self.comboGateway.currentText() + + # 查询合约 + if exchange: + vtSymbol = '.'.join([symbol, exchange]) + contract = self.mainEngine.getContract(vtSymbol) + else: + vtSymbol = symbol + contract = self.mainEngine.getContract(symbol) + + if contract: + if not gatewayName: + gatewayName = contract.gatewayName + exchange = contract.exchange # 保证有交易所代码 + + if gatewayName not in self.mainEngine.connected_gw_names: + if len(self.mainEngine.connected_gw_names) == 1: + gatewayName = self.mainEngine.connected_gw_names[0] + else: + self.mainEngine.writeError(u'没有连接网关:{}'.format(gatewayName)) + return + + req = VtOrderReq() + req.symbol = symbol + req.vtSymbol = vtSymbol + req.exchange = exchange + req.price = self.spinPrice.value() + req.volume = self.spinVolume.value() + req.direction = self.comboDirection.currentText() + req.priceType = self.comboPriceType.currentText() + req.offset = self.comboOffset.currentText() + req.currency = currency + req.productClass = productClass + + self.mainEngine.sendOrder(req, gatewayName) + except Exception as ex: + self.mainEngine.writeError( + u'tradingWg.sendOrder exception:{},{}'.format(str(ex), traceback.format_exc())) def canelOrder(self): """撤单""" @@ -1290,7 +1301,8 @@ class ContractMonitor(BasicMonitor): l = self.mainEngine.getAllContracts() d = {'.'.join([contract.exchange, contract.symbol]):contract for contract in l} l2 = d.keys() - l2.sort(reverse=True) + #l2.sort(reverse=True) + l2 = sorted(l2, reverse=True) self.setRowCount(len(l2)) row = 0