增加pnl单元格的颜色显示,修复ctpGateway持仓查询中均价计算的错误

This commit is contained in:
chenxy123 2017-04-21 21:27:00 +08:00
parent 2362320ee8
commit d8fa6daac7
2 changed files with 37 additions and 2 deletions

View File

@ -715,7 +715,8 @@ class CtpTdApi(TdApi):
# 计算持仓均价 # 计算持仓均价
if pos.position: if pos.position:
pos.price = (cost + data['PositionCost']) / pos.position size = self.symbolSizeDict[pos.symbol]
pos.price = (cost + data['PositionCost']) / (pos.position * size)
# 读取冻结 # 读取冻结
if pos.direction is DIRECTION_LONG: if pos.direction is DIRECTION_LONG:

View File

@ -13,6 +13,10 @@ from vtGateway import *
import vtText import vtText
COLOR_RED = QtGui.QColor('red')
COLOR_GREEN = QtGui.QColor('green')
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def loadFont(): def loadFont():
"""载入字体设置""" """载入字体设置"""
@ -172,6 +176,36 @@ class AskCell(QtGui.QTableWidgetItem):
self.setText(text) self.setText(text)
########################################################################
class PnlCell(QtGui.QTableWidgetItem):
"""显示盈亏的单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(PnlCell, self).__init__()
self.data = None
self.color = ''
if text:
self.setContent(text)
#----------------------------------------------------------------------
def setContent(self, text):
"""设置内容"""
self.setText(text)
try:
value = float(text)
if value >= 0 and self.color != 'red':
self.color = 'red'
self.setForeground(COLOR_RED)
elif value < 0 and self.color != 'green':
self.color = 'green'
self.setForeground(COLOR_GREEN)
except ValueError:
pass
######################################################################## ########################################################################
class BasicMonitor(QtGui.QTableWidget): class BasicMonitor(QtGui.QTableWidget):
""" """
@ -588,7 +622,7 @@ class PositionMonitor(BasicMonitor):
d['ydPosition'] = {'chinese':vtText.YD_POSITION, 'cellType':BasicCell} d['ydPosition'] = {'chinese':vtText.YD_POSITION, 'cellType':BasicCell}
d['frozen'] = {'chinese':vtText.FROZEN, 'cellType':BasicCell} d['frozen'] = {'chinese':vtText.FROZEN, 'cellType':BasicCell}
d['price'] = {'chinese':vtText.PRICE, 'cellType':BasicCell} d['price'] = {'chinese':vtText.PRICE, 'cellType':BasicCell}
d['positionProfit'] = {'chinese':vtText.POSITION_PROFIT, 'cellType':BasicCell} d['positionProfit'] = {'chinese':vtText.POSITION_PROFIT, 'cellType':PnlCell}
d['gatewayName'] = {'chinese':vtText.GATEWAY, 'cellType':BasicCell} d['gatewayName'] = {'chinese':vtText.GATEWAY, 'cellType':BasicCell}
self.setHeaderDict(d) self.setHeaderDict(d)