增加持仓盈亏字段
This commit is contained in:
parent
cbcf781d20
commit
21ce611ccd
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 # 持仓盈亏
|
||||
|
||||
|
||||
########################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user