示例#1
0
def run_func(**kwargs):
    from rqrobot.utils import dummy_func
    from rqrobot.utils.py2 import clear_all_cached_functions
    from rqrobot.utils.config import parse_config
    from rqrobot import main

    config = kwargs.get('config', kwargs.get('__config__', None))

    user_funcs = {
        'init': kwargs.get('init', dummy_func),
        'handle_bar': kwargs.get('handle_bar', dummy_func),
        'handle_tick': kwargs.get('handle_tick', dummy_func),
        'before_trading': kwargs.get('before_trading', dummy_func),
        'after_trading': kwargs.get('after_trading', dummy_func)
    }
    if config is None:
        config = {}
    else:
        assert isinstance(config, dict)
        try:
            del config["base"]["strategy_file"]
        except:
            pass
    config = parse_config(config, user_funcs=user_funcs)
    clear_all_cached_functions()
    return main.run(config, user_funcs=user_funcs)
示例#2
0
def run(config, source_code=None):
    # [Deprecated]
    from rqrobot.utils.config import parse_config
    from rqrobot import main

    config = parse_config(config, source_code=source_code)
    return main.run(config, source_code=source_code)
示例#3
0
def run(**kwargs):
    """
    Start to run a strategy
    """
    config_path = kwargs.get('config_path', None)
    if config_path is not None:
        config_path = os.path.abspath(config_path)
        kwargs.pop('config_path')
    if not kwargs.get('base__securities', None):
        kwargs.pop('base__securities', None)

    from rqrobot import main
    source_code = kwargs.get("base__source_code")
    cfg = parse_config(kwargs, config_path=config_path, click_type=True, source_code=source_code)
    source_code = cfg.base.source_code
    results = main.run(cfg, source_code=source_code)

    # store results into ipython when running in ipython
    from rqrobot.utils import is_run_from_ipython
    if results is not None and is_run_from_ipython():
        import IPython
        from rqrobot.utils import RqAttrDict
        ipy = IPython.get_ipython()
        report = results.get("sys_analyser", {})
        ipy.user_global_ns["results"] = results
        ipy.user_global_ns["report"] = RqAttrDict(report)

    if results is None:
        sys.exit(1)
示例#4
0
def run_code(code, config=None):
    from rqrobot.utils.config import parse_config
    from rqrobot.utils.py2 import clear_all_cached_functions
    from rqrobot import main

    if config is None:
        config = {}
    else:
        assert isinstance(config, dict)
        try:
            del config["base"]["strategy_file"]
        except:
            pass
    config = parse_config(config, source_code=code)
    clear_all_cached_functions()
    return main.run(config, source_code=code)
示例#5
0
def run_file(strategy_file_path, config=None):
    from rqrobot.utils.config import parse_config
    from rqrobot.utils.py2 import clear_all_cached_functions
    from rqrobot import main

    if config is None:
        config = {"base": {"strategy_file": strategy_file_path}}
    else:
        assert isinstance(config, dict)
        if "base" in config:
            config["base"]["strategy_file"] = strategy_file_path
        else:
            config["base"] = {"strategy_file": strategy_file_path}
    config = parse_config(config)
    clear_all_cached_functions()
    return main.run(config)