[Fix]修复持仓价格计算可能出错的bug

This commit is contained in:
vn.py 2018-01-17 10:48:13 +08:00
parent 7e62a7cf2f
commit f6a2623720

View File

@ -819,12 +819,18 @@ class PositionDetail(object):
cost = self.longPrice * self.longPos
cost += trade.volume * trade.price
newPos = self.longPos + trade.volume
self.longPrice = cost / newPos
if newPos:
self.longPrice = cost / newPos
else:
self.longPrice = 0
else:
cost = self.shortPrice * self.shortPos
cost += trade.volume * trade.price
newPos = self.shortPos + trade.volume
self.shortPrice = cost / newPos
if newPos:
self.shortPrice = cost / newPos
else:
self.shortPrice = 0
#----------------------------------------------------------------------
def calculatePosition(self):