From ccbec40abed858a91ff3c52ba1b193888cb2f838 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 9 Jan 2018 21:50:49 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]CtaEngine=E6=94=B9=E4=B8=BA=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E8=AE=A2=E9=98=85=E8=A1=8C=E6=83=85=E6=8E=A8=E9=80=81?= =?UTF-8?q?=EF=BC=8CClose=20#678?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/app/ctaStrategy/ctaEngine.py | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 57abbaf9..3773752a 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -416,20 +416,23 @@ class CtaEngine(object): self.tickStrategyDict[strategy.vtSymbol] = l l.append(strategy) - # 订阅合约 - contract = self.mainEngine.getContract(strategy.vtSymbol) - if contract: - req = VtSubscribeReq() - req.symbol = contract.symbol - req.exchange = contract.exchange - - # 对于IB接口订阅行情时所需的货币和产品类型,从策略属性中获取 - req.currency = strategy.currency - req.productClass = strategy.productClass - - self.mainEngine.subscribe(req, contract.gatewayName) - else: - self.writeCtaLog(u'%s的交易合约%s无法找到' %(name, strategy.vtSymbol)) + #---------------------------------------------------------------------- + def subscribeMarketData(self, strategy): + """订阅行情""" + # 订阅合约 + contract = self.mainEngine.getContract(strategy.vtSymbol) + if contract: + req = VtSubscribeReq() + req.symbol = contract.symbol + req.exchange = contract.exchange + + # 对于IB接口订阅行情时所需的货币和产品类型,从策略属性中获取 + req.currency = strategy.currency + req.productClass = strategy.productClass + + self.mainEngine.subscribe(req, contract.gatewayName) + else: + self.writeCtaLog(u'%s的交易合约%s无法找到' %(strategy.name, strategy.vtSymbol)) #---------------------------------------------------------------------- def initStrategy(self, name): @@ -441,6 +444,7 @@ class CtaEngine(object): strategy.inited = True self.callStrategyFunc(strategy, strategy.onInit) self.loadSyncData(strategy) # 初始化完成后加载同步数据 + self.subscribeMarketData(strategy) # 加载同步数据后再订阅行情 else: self.writeCtaLog(u'请勿重复初始化策略实例:%s' %name) else: