diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index b3c0482e..41430b44 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -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):