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)