1. 修复载入主界面的窗口设置loadWindowSetting的潜在兼容性问题
2. 尝试修复CTP接口的持仓查询错误问题
This commit is contained in:
parent
b32e5afa0f
commit
5871e7619d
@ -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']
|
||||
else:
|
||||
self.todayPosition = data['Position']
|
||||
self.todayPositionCost = data['PositionCost']
|
||||
|
||||
# 持仓的昨仓和今仓相加后为总持仓
|
||||
self.pos.position = self.todayPosition + self.ydPosition
|
||||
|
@ -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
|
||||
|
||||
|
||||
########################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user