From c6bd7a6d1ac3086dfe461b7d822f3bfb16ddb698 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 26 Jan 2018 10:46:27 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]Close=20#716=EF=BC=8CSpreadTrading?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=BD=93=E4=BB=B7=E5=B7=AE=E6=9F=90=E6=9D=A1?= =?UTF-8?q?=E8=85=BF=E8=A1=8C=E6=83=85=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=A6=81=E6=AD=A2=E4=BA=A4=E6=98=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/app/spreadTrading/stBase.py | 8 ++++++++ vnpy/trader/app/spreadTrading/stEngine.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vnpy/trader/app/spreadTrading/stBase.py b/vnpy/trader/app/spreadTrading/stBase.py index bead63f4..517538f0 100644 --- a/vnpy/trader/app/spreadTrading/stBase.py +++ b/vnpy/trader/app/spreadTrading/stBase.py @@ -98,6 +98,14 @@ class StSpread(object): # 遍历价差腿列表 for n, leg in enumerate(self.allLegs): + # 过滤有某条腿尚未初始化的情况(无挂单量) + if not leg.bidVolume or not leg.askVolume: + self.bidPrice = EMPTY_FLOAT + self.askPrice = EMPTY_FLOAT + self.askVolume = EMPTY_INT + self.bidVolume = EMPTY_INT + return + # 计算价格 if leg.multiplier > 0: self.bidPrice += leg.bidPrice * leg.multiplier diff --git a/vnpy/trader/app/spreadTrading/stEngine.py b/vnpy/trader/app/spreadTrading/stEngine.py index 5829323f..1473b06e 100644 --- a/vnpy/trader/app/spreadTrading/stEngine.py +++ b/vnpy/trader/app/spreadTrading/stEngine.py @@ -239,7 +239,6 @@ class StDataEngine(object): event2.dict_['data'] = spread self.eventEngine.put(event2) - #---------------------------------------------------------------------- def registerEvent(self): """""" @@ -309,6 +308,10 @@ class StAlgoEngine(object): """处理价差行情事件""" spread = event.dict_['data'] + # 若价差的买卖价均为0,则意味着尚未初始化,直接返回 + if not spread.bidPrice and not spread.askPrice: + return + algo = self.algoDict.get(spread.name, None) if algo: algo.updateSpreadTick(spread)