diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index 1619aac5..3d07c562 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -1422,6 +1422,8 @@ class PositionBuffer(object): self.ydPosition = EMPTY_INT self.todayPositionCost = EMPTY_FLOAT self.ydPositionCost = EMPTY_FLOAT + self.todayProfit = EMPTY_INT + self.ydProfit = EMPTY_INT # 通过提前创建持仓数据对象并重复使用的方式来降低开销 pos = VtPositionData() @@ -1440,13 +1442,16 @@ class PositionBuffer(object): if data['YdPosition']: self.ydPosition = data['Position'] self.ydPositionCost = data['PositionCost'] + self.ydProfit = data['PositionProfit'] else: self.todayPosition = data['Position'] self.todayPositionCost = data['PositionCost'] + self.todayProfit = data['PositionProfit'] # 持仓的昨仓和今仓相加后为总持仓 self.pos.position = self.todayPosition + self.ydPosition self.pos.ydPosition = self.ydPosition + self.pos.positionProfit = self.todayProfit + self.ydProfit # 如果手头还有持仓,则通过加权平均方式计算持仓均价 if self.todayPosition or self.ydPosition: @@ -1464,6 +1469,7 @@ class PositionBuffer(object): # 其他交易所并不区分今昨,因此只关心总仓位,昨仓设为0 self.pos.position = data['Position'] self.pos.ydPosition = 0 + self.pos.positionProfit = data['PositionProfit'] if data['Position']: self.pos.price = data['PositionCost'] / (data['Position'] * size) diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index e551f7f1..f7f4eb63 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -587,6 +587,7 @@ class PositionMonitor(BasicMonitor): d['ydPosition'] = {'chinese':u'昨持仓', 'cellType':BasicCell} d['frozen'] = {'chinese':u'冻结量', 'cellType':BasicCell} d['price'] = {'chinese':u'价格', 'cellType':BasicCell} + d['positionProfit'] = {'chinese':u'持仓盈亏', 'cellType':BasicCell} d['gatewayName'] = {'chinese':u'接口', 'cellType':BasicCell} self.setHeaderDict(d) diff --git a/vn.trader/vtGateway.py b/vn.trader/vtGateway.py index cf1c30ef..b6670783 100644 --- a/vn.trader/vtGateway.py +++ b/vn.trader/vtGateway.py @@ -292,6 +292,7 @@ class VtPositionData(VtBaseData): self.price = EMPTY_FLOAT # 持仓均价 self.vtPositionName = EMPTY_STRING # 持仓在vt系统中的唯一代码,通常是vtSymbol.方向 self.ydPosition = EMPTY_INT # 昨持仓 + self.positionProfit = EMPTY_FLOAT # 持仓盈亏 ########################################################################