From e3598be7e06cf7e2ff9c9d3196b301f85f91d8bd Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Mon, 24 Apr 2017 22:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CTA=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8A=A0=E8=BD=BD=E7=AD=96=E7=95=A5=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E6=8D=95=E6=8D=89=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctaStrategy/strategy/__init__.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vn.trader/ctaStrategy/strategy/__init__.py b/vn.trader/ctaStrategy/strategy/__init__.py index 03cb970e..4ba01490 100644 --- a/vn.trader/ctaStrategy/strategy/__init__.py +++ b/vn.trader/ctaStrategy/strategy/__init__.py @@ -6,7 +6,7 @@ import os import importlib - +import traceback # 用来保存策略类的字典 STRATEGY_CLASS = {} @@ -23,10 +23,15 @@ for root, subdirs, files in os.walk(path): moduleName = 'ctaStrategy.strategy.' + name.replace('.py', '') # 使用importlib动态载入模块 - module = importlib.import_module(moduleName) - - # 遍历模块下的对象,只有名称中包含'Strategy'的才是策略类 - for k in dir(module): - if 'Strategy' in k: - v = module.__getattribute__(k) - STRATEGY_CLASS[k] = v + try: + module = importlib.import_module(moduleName) + + # 遍历模块下的对象,只有名称中包含'Strategy'的才是策略类 + for k in dir(module): + if 'Strategy' in k: + v = module.__getattribute__(k) + STRATEGY_CLASS[k] = v + except: + print '-' * 20 + print ('Failed to import strategy file %s:' %moduleName) + traceback.print_exc()