ricequant / rqalpha-mod-tushare

Make Tushare compatible with RQAlpha
Apache License 2.0
185 stars 32 forks source link

assert broker is not None,Mod Import Error #2

Closed fswzb closed 7 years ago

fswzb commented 7 years ago

C:\Python35\python.exe C:/www/huice/rqalpha/rqalpha run -f C:\www\huice\rqalpha\rqalpha\examples\golden_cross.py --stock-starting-cash 100000 -s 2015-01-01 -e 2016-08-09 -mc tushare1.enable True [2017-04-08 21:46:34.427020] ERROR: system_log: ** [2017-04-08 21:46:34.427020] ERROR: system_log: Mod Import Error: [2017-04-08 21:46:34.427020] ERROR: system_log: No module named 'tushare1' [2017-04-08 21:46:34.427020] ERROR: system_log: ** 0000-00-00 ERROR [2017-04-08 21:46:34.786387] ERROR: system_log: 策略运行产生异常 Traceback (most recent call last): File "C:/www/huice/rqalpha/rqalpha\main.py", line 208, in run assert broker is not None AssertionError

Process finished with exit code 0

Cuizi7 commented 7 years ago

可否把您使用 mod 的情况贴一下,主要是如何使用的以及rqalpha 的版本等。

fswzb commented 7 years ago

from rqalpha.interface import AbstractMod

from .data_source import TushareKDataSource

from rqalpha.simulation_broker import SimulationBroker

from rqalpha.signal_broker import SignalBroker

class TushareMod(AbstractMod): def init(self): pass

def start_up(self, env, mod_config):
    bundle_path = env.config.base.data_bundle_path
    env.set_data_source(TushareKDataSource(bundle_path))

def tear_down(self, code, exception=None):
    pass

def load_mod():

from .mod import TushareMod

return TushareMod()

rqalpha2.07

tushare1: lib: 'rqalpha.mod.tushare1'#rqalpha.mod. enabled: True priority: 100

fswzb commented 7 years ago

多谢指导,设置rqalpha.mod.rqalpha_mod_tushare1后还有问题: C:\Python35\python.exe C:/www/huice/rqalpha/rqalpha run -f C:\www\huice\rqalpha\rqalpha\examples\buy_and_hold.py --stock-starting-cash 100000 -s 2015-01-01 -e 2016-08-09 -mc tushare1.enable True 0000-00-00 ERROR dict must be set to a dictionary, not a 'set' [2017-04-08 23:15:05.855694] ERROR: system_log: 策略运行产生异常 Traceback (most recent call last): File "C:/www/huice/rqalpha/rqalpha\main.py", line 190, in run mod_handler.set_env(env) File "C:\www\huice\rqalpha\rqalpha\mod__init.py", line 57, in set_env mod_config = RqAttrDict(copy.deepcopy(getattr(mod_module, "config", {}))) File "C:\www\huice\rqalpha\rqalpha\utils__init.py", line 50, in init self.dict = d if d is not None else dict() TypeError: dict must be set to a dictionary, not a 'set' Traceback (most recent call last): File "C:\Python35\lib\runpy.py", line 170, in _run_module_as_main "main", mod_spec) File "C:\Python35\lib\runpy.py", line 85, in _run_code exec(code, run_globals) �� �� {'package': '', 'generate_config': <click.core.Command object at 0x05181530>, 'update_bundle': <click.core.Command object at... �� <code object at 0x0076C750, file "C:/www/huice/rqalpha/rqalpha\main.py", line 17> File "C:/www/huice/rqalpha/rqalpha\main.py", line 327, in entry_point() �� <function entry_point at 0x00772660> File "C:/www/huice/rqalpha/rqalpha\main__.py", line 68, in entry_point cli(obj={}) �� <click.core.Group object at 0x05175CB0> File "C:\Python35\lib\site-packages\click\core.py", line 722, in call return self.main(args, kwargs) �� �� �� {'obj': {'VERBOSE': 0}} �� �� () �� <click.core.Group object at 0x05175CB0> File "C:\Python35\lib\site-packages\click\core.py", line 697, in main rv = self.invoke(ctx) �� �� <click.core.Context object at 0x05181990> �� <click.core.Group object at 0x05175CB0> File "C:\Python35\lib\site-packages\click\core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) �� �� �� <click.core.Context object at 0x0519AEF0> �� �� <click.core.Context object at 0x0519AEF0> �� <function MultiCommand.invoke.._process_result at 0x05185390> File "C:\Python35\lib\site-packages\click\core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) �� �� �� <click.core.Context object at 0x0519AEF0> �� �� <click.core.Command object at 0x05181310> �� <click.core.Context object at 0x0519AEF0> File "C:\Python35\lib\site-packages\click\core.py", line 535, in invoke return callback(args, **kwargs) �� �� �� {'mod_configs': (('tushare1.enable', 'True'),), 'config_path': None, 'basebenchmark': None, 'baserun_type': 'b', 'base_end... �� �� () �� <function run at 0x05185540> File "C:/www/huice/rqalpha/rqalpha__main.py", line 120, in run main.run(parse_config(kwargs, config_path)) �� �� �� �� None �� �� �� {'modtushare1__enable': True, 'config_path': None, 'basebenchmark': None, 'baserun_type': 'b', 'base__end_date': Timestamp... �� �� <function parse_config at 0x0517DC00> �� <module 'main' from 'C:/www/huice/rqalpha/rqalpha\main.py'> File "C:/www/huice/rqalpha/rqalpha\main.py", line 321, in run mod_handler.tear_down(code, user_exc) �� �� �� CustomException(dict__ must be set to a dictionary, not a 'set',) �� �� EXIT_CODE.EXIT_INTERNAL_ERROR �� <rqalpha.mod.ModHandler object at 0x0554FC30> File "C:\www\huice\rqalpha\rqalpha\mod__init.py", line 72, in tear_down ret = self._mod_dict[mod_name].tear_down(*args) �� �� �� (EXIT_CODE.EXIT_INTERNAL_ERROR, CustomException(dict__ must be set to a dictionary, not a 'set',)) �� �� 'tushare1' �� <rqalpha.mod.ModHandler object at 0x0554FC30> KeyError: 'tushare1'

fswzb commented 7 years ago

在./rqalpha/mod_config.yml 修改添加: tushare1: lib: 'rqalpha.mod.rqalpha_mod_tushare1'#rqalpha.mod. enabled: True priority: 100 测试不能导入tushare1的问题解决,谢谢@宝可梦的狗的指导