From 711265c70a75e535cca33208efede3534505a43b Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 17 Oct 2017 16:57:35 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E6=B7=BB=E5=8A=A0=E5=AF=B9OFFSET=5FCLOSE?= =?UTF-8?q?=E5=9C=A8=E4=B8=8D=E5=90=8C=E4=BA=A4=E6=98=93=E6=89=80=E7=9A=84?= =?UTF-8?q?=E5=8C=BA=E5=88=AB=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/vtEngine.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 45ccf025..52085e8a 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -654,14 +654,18 @@ class PositionDetail(object): # 平昨 elif trade.offset is OFFSET_CLOSEYESTERDAY: self.shortYd -= trade.volume - # 平仓(非上期所,优先平今) + # 平仓 elif trade.offset is OFFSET_CLOSE: - self.shortTd -= trade.volume - - if self.shortTd < 0: - self.shortYd += self.shortTd - self.shortTd = 0 - + # 上期所等同于平昨 + if self.exchange is EXCHANGE_SHFE: + self.shortYd -= trade.volume + # 非上期所,优先平今 + else: + self.shortTd -= trade.volume + + if self.shortTd < 0: + self.shortYd += self.shortTd + self.shortTd = 0 # 空头 elif trade.direction is DIRECTION_SHORT: # 开仓 @@ -675,11 +679,16 @@ class PositionDetail(object): self.longYd -= trade.volume # 平仓 elif trade.offset is OFFSET_CLOSE: - self.longTd -= trade.volume - - if self.longTd < 0: - self.longYd += self.longTd - self.longTd = 0 + # 上期所等同于平昨 + if self.exchange is EXCHANGE_SHFE: + self.longYd -= trade.volume + # 非上期所,优先平今 + else: + self.longTd -= trade.volume + + if self.longTd < 0: + self.longYd += self.longTd + self.longTd = 0 # 汇总今昨 self.calculatePosition()