Пример #1
0
def run_smoke(algo, before_run_hook=None, pipeline_hook=None):
    fake_clock = clock.FaketimeClock()
    # fake_clock.rollback(1)
    be = backend.Backend(clock=fake_clock)

    a = Algorithm(
        initialize=getattr(algo, 'initialize', noop),
        handle_data=getattr(algo, 'handle_data', noop),
        before_trading_start=getattr(algo, 'before_trading_start', noop),
        backend=be,
    )

    if pipeline_hook is not None:

        def _pipeline_output(name):
            return pipeline_hook.output(a, name)

        a.pipeline_output = _pipeline_output

    with LiveTraderAPI(a), \
            patch('pylivetrader.executor.executor.RealtimeClock') as rc:

        def make_clock(*args, **kwargs):
            # may want to reconfigure clock
            return fake_clock

        rc.side_effect = make_clock

        if before_run_hook is not None:
            before_run_hook(a, be)
        a.run()
Пример #2
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()