[Fix]修复持仓价格计算可能出错的bug
This commit is contained in:
parent
7e62a7cf2f
commit
f6a2623720
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user