From 633135b9dade99e7b54ac84e6a4f18dc562bce65 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Wed, 26 Oct 2016 18:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DgetStrategyVar=20=E5=92=8Cget?= =?UTF-8?q?StrategyParam=E7=9A=84bug=EF=BC=9A=E8=8B=A5=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E7=9A=84=E5=8F=82=E6=95=B0=E5=92=8C=E8=A7=82?= =?UTF-8?q?=E6=B5=8B=E5=80=BC=E5=8F=98=E9=87=8F=E4=B8=8D=E5=90=8C=EF=BC=8C?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E7=AD=96=E7=95=A5=E6=97=B6=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E5=B7=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctaAlgo/ctaEngine.py | 42 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/vn.trader/ctaAlgo/ctaEngine.py b/vn.trader/ctaAlgo/ctaEngine.py index fb9dc229..317e8f1f 100644 --- a/vn.trader/ctaAlgo/ctaEngine.py +++ b/vn.trader/ctaAlgo/ctaEngine.py @@ -319,13 +319,19 @@ class CtaEngine(object): # 修正,交易日期不一定是OpenDate dt = datetime.now() - if (ctaTick.datetime - dt).seconds > 10: + if ctaTick.datetime > dt and (ctaTick.datetime - dt).seconds > 100: today = dt.strftime('%Y%m%d') - if today != tick.date: - ctaTick.datetime = dt + self.writeCtaLog(u'fix tick{0},{1}'.format(ctaTick.datetime.strftime(' %Y%m%d %H:%M:%S.%f'), dt.strftime('%Y%m%d %H:%M:%S.%f'))) + if today != ctaTick.date: + # 当前日期不等于交易日,ctaTick.date修正为当日,保留ctaTick.tradingDay + ctaTick.date = today + # 重新计算时间 + ctaTick.datetime = datetime.strptime(' '.join([ctaTick.date, ctaTick.time]), '%Y%m%d %H:%M:%S.%f') else: - ctaTick.datetime = datetime.strptime(' '.join([tick.date, tick.time]), '%Y%m%d %H:%M:%S.%f') - + # 修正出现偏差的时间 + ctaTick.datetime = dt + self.writeCtaLog(u'fix 修正出现偏差的时间') + # 逐个推送到策略实例中 l = self.tickStrategyDict[tick.vtSymbol] for strategy in l: @@ -610,7 +616,8 @@ class CtaEngine(object): varDict = OrderedDict() for key in strategy.varList: - varDict[key] = strategy.__getattribute__(key) + if hasattr(strategy,key): + varDict[key] = strategy.__getattribute__(key) return varDict else: @@ -625,8 +632,9 @@ class CtaEngine(object): strategy = self.strategyDict[name] paramDict = OrderedDict() - for key in strategy.paramList: - paramDict[key] = strategy.__getattribute__(key) + for key in strategy.paramList: + if hasattr(strategy, key): + paramDict[key] = strategy.__getattribute__(key) return paramDict else: @@ -647,6 +655,24 @@ class CtaEngine(object): """ return self.mainEngine.getAccountInfo() + # --------------------------------------------------------------------- + def saveStrategyData(self): + """保存策略的数据""" + + # 1.判断策略名称是否存在字典中 + for key in self.strategyDict.keys(): + + # 2.提取策略 + strategy = self.strategyDict[key] + + if strategy is None: + continue + + # 3.判断策略是否运行 + if strategy.inited and strategy.trading: + + # 5.保存策略数据 + strategy.saveBar() ########################################################################