From 5871e7619de82cad0044657be8e4a88783511bce Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Wed, 1 Jun 2016 23:28:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E8=BD=BD=E5=85=A5?= =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E7=9A=84=E7=AA=97=E5=8F=A3=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEloadWindowSetting=E7=9A=84=E6=BD=9C=E5=9C=A8=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98=202.=20=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DCTP=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=8C=81?= =?UTF-8?q?=E4=BB=93=E6=9F=A5=E8=AF=A2=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctpGateway/ctpGateway.py | 11 ++++++----- vn.trader/uiMainWindow.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index dcd444ff..2a21dea9 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -1316,12 +1316,13 @@ class PositionBuffer(object): def updateBuffer(self, data): """更新缓存,返回更新后的持仓数据""" # 昨仓和今仓的数据更新是分在两条记录里的,因此需要判断检查该条记录对应仓位 - if data['TodayPosition']: - self.todayPosition = data['Position'] - self.todayPositionCost = data['PositionCost'] - elif data['YdPosition']: + # 因为今仓字段TodayPosition可能变为0(被全部平仓),因此分辨今昨仓需要用YdPosition字段 + if data['YdPosition']: self.ydPosition = data['Position'] - self.ydPositionCost = data['PositionCost'] + self.ydPositionCost = data['PositionCost'] + else: + self.todayPosition = data['Position'] + self.todayPositionCost = data['PositionCost'] # 持仓的昨仓和今仓相加后为总持仓 self.pos.position = self.todayPosition + self.ydPosition diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index 32de7b33..02833bae 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -327,8 +327,17 @@ class MainWindow(QtGui.QMainWindow): def loadWindowSettings(self): """载入窗口设置""" settings = QtCore.QSettings('vn.py', 'vn.trader') - self.restoreState(settings.value('state').toByteArray()) - self.restoreGeometry(settings.value('geometry').toByteArray()) + # 这里由于PyQt4的版本不同,settings.value('state')调用返回的结果可能是: + # 1. None(初次调用,注册表里无相应记录,因此为空) + # 2. QByteArray(比较新的PyQt4) + # 3. QVariant(以下代码正确执行所需的返回结果) + # 所以为了兼容考虑,这里加了一个try...except,如果是1、2的情况就pass + # 可能导致主界面的设置无法载入(每次退出时的保存其实是成功了) + try: + self.restoreState(settings.value('state').toByteArray()) + self.restoreGeometry(settings.value('geometry').toByteArray()) + except AttributeError: + pass ########################################################################