From 239f335900e4897c968d6e21577df865e3d4c3f2 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 20 Sep 2017 14:26:16 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E4=BF=AE=E6=94=B9convertOrderReq=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=94=81=E4=BB=93=E4=BA=A4=E6=98=93=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=E5=BC=80=E4=BB=93=E8=87=AA=E5=8A=A8=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=B9=B3=E6=98=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/vtEngine.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 3977a144..ddcde64f 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -778,16 +778,16 @@ class PositionDetail(object): #---------------------------------------------------------------------- def convertOrderReq(self, req): """转换委托请求""" - # 开仓无需转换 - if req.offset is OFFSET_OPEN: - return [req] - # 普通模式无需转换 - elif self.mode is self.MODE_NORMAL: + if self.mode is self.MODE_NORMAL: return [req] # 上期所模式拆分今昨,优先平今 elif self.mode is self.MODE_SHFE: + # 开仓无需转换 + if req.offset is OFFSET_OPEN: + return [req] + # 多头 if req.direction is DIRECTION_LONG: posAvailable = self.shortPos - self.shortPosFrozen @@ -829,18 +829,20 @@ class PositionDetail(object): td = self.longTd ydAvailable = self.longYd - self.longYdFrozen - # 如果有今仓,则只能锁仓 + # 这里针对开仓和平仓委托均使用一套逻辑 + + # 如果有今仓,则只能开仓(或锁仓) if td: req.offset = OFFSET_OPEN return [req] # 如果平仓量小于昨可用,全部平昨 elif req.volume <= ydAvailable: - req.offset = OFFSET_CLOSEYESTERDAY + req.offset = OFFSET_CLOSE # OFFSET_CLOSE在上期所等于平昨 return [req] # 平仓量大于昨可用,平仓再反向开仓 else: reqClose = copy(req) - reqClose.offset = OFFSET_CLOSEYESTERDAY + reqClose.offset = OFFSET_CLOSE reqClose.volume = ydAvailable reqOpen = copy(req)