From d8fa6daac7f81885ca0376180d9a72108d4e4e68 Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Fri, 21 Apr 2017 21:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0pnl=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E9=A2=9C=E8=89=B2=E6=98=BE=E7=A4=BA=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DctpGateway=E6=8C=81=E4=BB=93=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=B8=AD=E5=9D=87=E4=BB=B7=E8=AE=A1=E7=AE=97=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/gateway/ctpGateway/ctpGateway.py | 3 +- vn.trader/uiBasicWidget.py | 36 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/vn.trader/gateway/ctpGateway/ctpGateway.py b/vn.trader/gateway/ctpGateway/ctpGateway.py index 44da2fb0..a2e12200 100644 --- a/vn.trader/gateway/ctpGateway/ctpGateway.py +++ b/vn.trader/gateway/ctpGateway/ctpGateway.py @@ -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: diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index 8928822f..79e55697 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -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)