From f6a26237200a1cd31e5ea08fcd5d9afc77f0bb1a Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 17 Jan 2018 10:48:13 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=E4=BF=AE=E5=A4=8D=E6=8C=81=E4=BB=93?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=E5=8F=AF=E8=83=BD=E5=87=BA?= =?UTF-8?q?=E9=94=99=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/vtEngine.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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):