Exemple #1
0
def process_shell_params(
        ctx,
        file,
        backend,
        backend_config,
        algofile=None,
        ):
    if file:
        algofile = file
    if algofile is None or algofile == '':
        ctx.fail("must specify algo file with '-f' ")

    if not (Path(algofile).exists() and Path(algofile).is_file()):
        ctx.fail("couldn't find algofile '{}'".format(algofile))

    algomodule = get_algomodule_by_path(algofile)

    backend_options = None
    if backend_config is not None:
        backend_options = configloader.load_config(backend_config)

    algorithm = Algorithm(
        backend=backend,
        backend_options=backend_options,
    )
    ctx.algorithm = algorithm
    ctx.algomodule = algomodule
    # ctx.retry = retry
    return ctx
Exemple #2
0
def process_algo_params(ctx, file, algofile, backend, backend_config,
                        data_frequency, statefile, retry):
    if len(algofile) > 0:
        algofile = algofile[0]
    elif file:
        algofile = file
    else:
        algofile = None

    if algofile is None or algofile == '':
        ctx.fail("must specify algo file with '-f' ")

    if not (Path(algofile).exists() and Path(algofile).is_file()):
        ctx.fail("couldn't find algofile '{}'".format(algofile))

    algomodule = get_algomodule_by_path(algofile)
    functions = get_api_functions(algomodule)

    backend_options = None
    if backend_config is not None:
        backend_options = configloader.load_config(backend_config)

    algorithm = Algorithm(
        backend=backend,
        backend_options=backend_options,
        data_frequency=data_frequency,
        algoname=extract_filename(algofile),
        statefile=statefile,
        **functions,
    )
    ctx.algorithm = algorithm
    ctx.algomodule = algomodule
    ctx.retry = retry
    return ctx
def test_load_config():
    files = ['config.yml', 'config.json']
    for f in files:
        o = load_config(get_config(f))
        print('xxx', list(o.items()))
        assert o['api_key_id'] == 'key_id'
        assert o['api_secret'] == 'secret'
Exemple #4
0
def run(ctx, algofile, backend, backend_config, data_frequency, statefile,
        zipline):
    if algofile is None or algofile == '':
        ctx.fail("must specify algo file with '-f' ")

    if not (Path(algofile).exists() and Path(algofile).is_file()):
        ctx.fail("couldn't find algofile '{}'".format(algofile))

    functions = get_functions_by_path(algofile, use_translate=zipline)

    backend_options = None
    if backend_config is not None:
        backend_options = configloader.load_config(backend_config)

    algorithm = Algorithm(
        backend=backend,
        backend_options=backend_options,
        data_frequency=data_frequency,
        algoname=extract_filename(algofile),
        statefile=statefile,
        **functions,
    )

    with LiveTraderAPI(algorithm):

        algorithm.run()