增加pnl单元格的颜色显示,修复ctpGateway持仓查询中均价计算的错误
This commit is contained in:
parent
2362320ee8
commit
d8fa6daac7
@ -715,7 +715,8 @@ class CtpTdApi(TdApi):
|
||||
|
||||
# 计算持仓均价
|
||||
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:
|
||||
|
@ -13,6 +13,10 @@ from vtGateway import *
|
||||
import vtText
|
||||
|
||||
|
||||
COLOR_RED = QtGui.QColor('red')
|
||||
COLOR_GREEN = QtGui.QColor('green')
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def loadFont():
|
||||
"""载入字体设置"""
|
||||
@ -172,6 +176,36 @@ class AskCell(QtGui.QTableWidgetItem):
|
||||
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):
|
||||
"""
|
||||
@ -588,7 +622,7 @@ class PositionMonitor(BasicMonitor):
|
||||
d['ydPosition'] = {'chinese':vtText.YD_POSITION, 'cellType':BasicCell}
|
||||
d['frozen'] = {'chinese':vtText.FROZEN, '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}
|
||||
self.setHeaderDict(d)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user