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)