From 4b1af5e10ecf7fb93e3e911a2f6489b7d43b1aef Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 16 Oct 2017 14:41:06 +0800 Subject: [PATCH] [Fix]Fix #543 --- vnpy/trader/app/ctaStrategy/ctaEngine.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 7065964d..dff400de 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -219,7 +219,9 @@ class CtaEngine(object): del self.workingStopOrderDict[stopOrderID] # 从策略委托号集合中移除 - self.strategyOrderDict[strategy.name].remove(stopOrderID) + s = self.strategyOrderDict[strategy.name] + if stopOrderID in s: + s.remove(stopOrderID) # 通知策略 strategy.onStopOrder(so) @@ -251,7 +253,9 @@ class CtaEngine(object): del self.workingStopOrderDict[so.stopOrderID] # 从策略委托号集合中移除 - self.strategyOrderDict[so.strategy.name].remove(so.stopOrderID) + s = self.strategyOrderDict[so.strategy.name] + if so.stopOrderID in s: + s.remove(so.stopOrderID) # 更新停止单状态,并通知策略 so.status = STOPORDER_TRIGGERED @@ -285,12 +289,16 @@ class CtaEngine(object): """处理委托推送""" order = event.dict_['data'] - if order.vtOrderID in self.orderStrategyDict: - strategy = self.orderStrategyDict[order.vtOrderID] + vtOrderID = order.vtOrderID + + if vtOrderID in self.orderStrategyDict: + strategy = self.orderStrategyDict[vtOrderID] # 如果委托已经完成(拒单、撤销、全成),则从活动委托集合中移除 if order.status in self.STATUS_FINISHED: - self.strategyOrderDict[strategy.name].remove(order.vtOrderID) + s = self.strategyOrderDict[strategy.name] + if vtOrderID in s: + s.remove(vtOrderID) self.callStrategyFunc(strategy, strategy.onOrder, order)