1. 修复载入主界面的窗口设置loadWindowSetting的潜在兼容性问题

2. 尝试修复CTP接口的持仓查询错误问题
This commit is contained in:
chenxy123 2016-06-01 23:28:11 +08:00
parent b32e5afa0f
commit 5871e7619d
2 changed files with 17 additions and 7 deletions

View File

@ -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

View File

@ -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
########################################################################