示例#1
0
def run(ctx, algofile, algotext, define, data_frequency, capital_base, bundle,
        bundle_timestamp, start, end, output, print_algo, local_namespace,
        exchange_name, algo_namespace, base_currency):
    """Run a backtest for the given algorithm.
    """

    if (algotext is not None) == (algofile is not None):
        ctx.fail(
            "must specify exactly one of '-f' / '--algofile' or"
            " '-t' / '--algotext'", )

    # check that the start and end dates are passed correctly
    if start is None and end is None:
        # check both at the same time to avoid the case where a user
        # does not pass either of these and then passes the first only
        # to be told they need to pass the second argument also
        ctx.fail(
            "must specify dates with '-s' / '--start' and '-e' / '--end'", )
    if start is None:
        ctx.fail("must specify a start date with '-s' / '--start'")
    if end is None:
        ctx.fail("must specify an end date with '-e' / '--end'")

    if exchange_name is None:
        ctx.fail("must specify an exchange name '-x'")

    perf = _run(initialize=None,
                handle_data=None,
                before_trading_start=None,
                analyze=None,
                algofile=algofile,
                algotext=algotext,
                defines=define,
                data_frequency=data_frequency,
                capital_base=capital_base,
                data=None,
                bundle=bundle,
                bundle_timestamp=bundle_timestamp,
                start=start,
                end=end,
                output=output,
                print_algo=print_algo,
                local_namespace=local_namespace,
                environ=os.environ,
                live=False,
                exchange=exchange_name,
                algo_namespace=algo_namespace,
                base_currency=base_currency,
                live_graph=False)

    if output == '-':
        click.echo(str(perf))
    elif output != os.devnull:  # make the catalyst magic not write any data
        perf.to_pickle(output)

    return perf
示例#2
0
def live(ctx, algofile, algotext, define, output, print_algo, local_namespace,
         exchange_name, algo_namespace, base_currency, live_graph):
    """Trade live with the given algorithm.
    """
    if (algotext is not None) == (algofile is not None):
        ctx.fail(
            "must specify exactly one of '-f' / '--algofile' or"
            " '-t' / '--algotext'", )

    if exchange_name is None:
        ctx.fail("must specify an exchange name '-x'")
    if algo_namespace is None:
        ctx.fail("must specify an algorithm name '-n' in live execution mode")
    if base_currency is None:
        ctx.fail("must specify a base currency '-c' in live execution mode")

    perf = _run(initialize=None,
                handle_data=None,
                before_trading_start=None,
                analyze=None,
                algofile=algofile,
                algotext=algotext,
                defines=define,
                data_frequency=None,
                capital_base=None,
                data=None,
                bundle=None,
                bundle_timestamp=None,
                start=None,
                end=None,
                output=output,
                print_algo=print_algo,
                local_namespace=local_namespace,
                environ=os.environ,
                live=True,
                exchange=exchange_name,
                algo_namespace=algo_namespace,
                base_currency=base_currency,
                live_graph=live_graph)

    if output == '-':
        click.echo(str(perf))
    elif output != os.devnull:  # make the catalyst magic not write any data
        perf.to_pickle(output)

    return perf
示例#3
0
def live(ctx,
         algofile,
         capital_base,
         algotext,
         define,
         output,
         print_algo,
         local_namespace,
         exchange_name,
         algo_namespace,
         base_currency,
         end,
         live_graph,
         auth_aliases,
         simulate_orders):
    """Trade live with the given algorithm.
    """
    if (algotext is not None) == (algofile is not None):
        ctx.fail(
            "must specify exactly one of '-f' / '--algofile' or"
            " '-t' / '--algotext'",
        )

    if exchange_name is None:
        ctx.fail("must specify an exchange name '-x'")

    if algo_namespace is None:
        ctx.fail("must specify an algorithm name '-n' in live execution mode")

    if base_currency is None:
        ctx.fail("must specify a base currency '-c' in live execution mode")

    if capital_base is None:
        ctx.fail("must specify a capital base with '--capital-base'")

    if simulate_orders:
        click.echo('Running in paper trading mode.', sys.stdout)

    else:
        click.echo('Running in live trading mode.', sys.stdout)

    perf = _run(
        initialize=None,
        handle_data=None,
        before_trading_start=None,
        analyze=None,
        algofile=algofile,
        algotext=algotext,
        defines=define,
        data_frequency=None,
        capital_base=capital_base,
        data=None,
        bundle=None,
        bundle_timestamp=None,
        start=None,
        end=end,
        output=output,
        print_algo=print_algo,
        local_namespace=local_namespace,
        environ=os.environ,
        live=True,
        exchange=exchange_name,
        algo_namespace=algo_namespace,
        base_currency=base_currency,
        live_graph=live_graph,
        analyze_live=None,
        simulate_orders=simulate_orders,
        auth_aliases=auth_aliases,
        stats_output=None,
    )

    if output == '-':
        click.echo(str(perf), sys.stdout)
    elif output != os.devnull:  # make the catalyst magic not write any data
        perf.to_pickle(output)

    return perf
示例#4
0
def live(ctx, algofile, capital_base, algotext, define, output, print_algo,
         local_namespace, exchange_name, algo_namespace, quote_currency, start,
         end, live_graph, auth_aliases, simulate_orders):
    """Trade live with the given algorithm.
    """
    if (algotext is not None) == (algofile is not None):
        ctx.fail(
            "must specify exactly one of '-f' / '--algofile' or"
            " '-t' / '--algotext'", )

    if exchange_name is None:
        ctx.fail("must specify an exchange name '-x'")

    if algo_namespace is None:
        ctx.fail("must specify an algorithm name '-n' in live execution mode")

    if quote_currency is None:
        ctx.fail("must specify a quote currency '-c' in live execution mode")

    if capital_base is None:
        ctx.fail("must specify a capital base with '--capital-base'")

    if simulate_orders:
        click.echo('Running in paper trading mode.', sys.stdout)

    else:
        click.echo('Running in live trading mode.', sys.stdout)

    perf = _run(
        initialize=None,
        handle_data=None,
        before_trading_start=None,
        analyze=None,
        algofile=algofile,
        algotext=algotext,
        defines=define,
        data_frequency=None,
        capital_base=capital_base,
        data=None,
        bundle=None,
        bundle_timestamp=None,
        start=start,
        end=end,
        output=output,
        print_algo=print_algo,
        local_namespace=local_namespace,
        environ=os.environ,
        live=True,
        exchange=exchange_name,
        algo_namespace=algo_namespace,
        quote_currency=quote_currency,
        live_graph=live_graph,
        analyze_live=None,
        simulate_orders=simulate_orders,
        auth_aliases=auth_aliases,
        stats_output=None,
    )

    if output == '-':
        click.echo(str(perf), sys.stdout)
    elif output != os.devnull:  # make the catalyst magic not write any data
        perf.to_pickle(output)

    return perf
示例#5
0
def run(ctx,
        algofile,
        algotext,
        define,
        data_frequency,
        capital_base,
        bundle,
        bundle_timestamp,
        start,
        end,
        output,
        print_algo,
        local_namespace,
        exchange_name,
        algo_namespace,
        base_currency):
    """Run a backtest for the given algorithm.
    """

    if (algotext is not None) == (algofile is not None):
        ctx.fail(
            "must specify exactly one of '-f' / '--algofile' or"
            " '-t' / '--algotext'",
        )

    # check that the start and end dates are passed correctly
    if start is None and end is None:
        # check both at the same time to avoid the case where a user
        # does not pass either of these and then passes the first only
        # to be told they need to pass the second argument also
        ctx.fail(
            "must specify dates with '-s' / '--start' and '-e' / '--end'"
            " in backtest mode",
        )
    if start is None:
        ctx.fail("must specify a start date with '-s' / '--start'"
                 " in backtest mode")
    if end is None:
        ctx.fail("must specify an end date with '-e' / '--end'"
                 " in backtest mode")

    if exchange_name is None:
        ctx.fail("must specify an exchange name '-x'")

    if base_currency is None:
        ctx.fail("must specify a base currency with '-c' in backtest mode")

    if capital_base is None:
        ctx.fail("must specify a capital base with '--capital-base'")

    click.echo('Running in backtesting mode.', sys.stdout)

    perf = _run(
        initialize=None,
        handle_data=None,
        before_trading_start=None,
        analyze=None,
        algofile=algofile,
        algotext=algotext,
        defines=define,
        data_frequency=data_frequency,
        capital_base=capital_base,
        data=None,
        bundle=bundle,
        bundle_timestamp=bundle_timestamp,
        start=start,
        end=end,
        output=output,
        print_algo=print_algo,
        local_namespace=local_namespace,
        environ=os.environ,
        live=False,
        exchange=exchange_name,
        algo_namespace=algo_namespace,
        base_currency=base_currency,
        analyze_live=None,
        live_graph=False,
        simulate_orders=True,
        auth_aliases=None,
        stats_output=None,
    )

    if output == '-':
        click.echo(str(perf), sys.stdout)
    elif output != os.devnull:  # make the catalyst magic not write any data
        perf.to_pickle(output)

    return perf