Пример #1
0
def test_check_exchange(default_conf, caplog) -> None:
    configuration = Configuration(Namespace())

    # Test an officially supported by Freqtrade team exchange
    default_conf.get('exchange').update({'name': 'BITTREX'})
    assert configuration.check_exchange(default_conf)
    assert log_has_re(
        r"Exchange .* is officially supported by the Freqtrade development team\.",
        caplog.record_tuples)
    caplog.clear()

    # Test an officially supported by Freqtrade team exchange
    default_conf.get('exchange').update({'name': 'binance'})
    assert configuration.check_exchange(default_conf)
    assert log_has_re(
        r"Exchange .* is officially supported by the Freqtrade development team\.",
        caplog.record_tuples)
    caplog.clear()

    # Test an available exchange, supported by ccxt
    default_conf.get('exchange').update({'name': 'kraken'})
    assert configuration.check_exchange(default_conf)
    assert log_has_re(
        r"Exchange .* is supported by ccxt and .* not officially supported "
        r"by the Freqtrade development team\. .*", caplog.record_tuples)
    caplog.clear()

    # Test a 'bad' exchange, which known to have serious problems
    default_conf.get('exchange').update({'name': 'bitmex'})
    assert not configuration.check_exchange(default_conf)
    assert log_has_re(
        r"Exchange .* is known to not work with the bot yet\. "
        r"Use it only for development and testing purposes\.",
        caplog.record_tuples)
    caplog.clear()

    # Test a 'bad' exchange with check_for_bad=False
    default_conf.get('exchange').update({'name': 'bitmex'})
    assert configuration.check_exchange(default_conf, False)
    assert log_has_re(
        r"Exchange .* is supported by ccxt and .* not officially supported "
        r"by the Freqtrade development team\. .*", caplog.record_tuples)
    caplog.clear()

    # Test an invalid exchange
    default_conf.get('exchange').update({'name': 'unknown_exchange'})
    configuration.config = default_conf

    with pytest.raises(
            OperationalException,
            match=r'.*Exchange "unknown_exchange" is not supported by ccxt '
            r'and therefore not available for the bot.*'):
        configuration.check_exchange(default_conf)
Пример #2
0
def test_setup_configuration_without_arguments(mocker, default_conf,
                                               caplog) -> None:
    patched_configuration_load_config_file(mocker, default_conf)

    args = [
        '--config', 'config.json', '--strategy', 'DefaultStrategy',
        'backtesting'
    ]

    config = setup_configuration(get_args(args), RunMode.BACKTEST)
    assert 'max_open_trades' in config
    assert 'stake_currency' in config
    assert 'stake_amount' in config
    assert 'exchange' in config
    assert 'pair_whitelist' in config['exchange']
    assert 'datadir' in config
    assert log_has('Using data directory: {} ...'.format(config['datadir']),
                   caplog)
    assert 'ticker_interval' in config
    assert not log_has_re('Parameter -i/--ticker-interval detected .*', caplog)

    assert 'position_stacking' not in config
    assert not log_has('Parameter --enable-position-stacking detected ...',
                       caplog)

    assert 'refresh_pairs' not in config
    assert not log_has('Parameter -r/--refresh-pairs-cached detected ...',
                       caplog)

    assert 'timerange' not in config
    assert 'export' not in config
    assert 'runmode' in config
    assert config['runmode'] == RunMode.BACKTEST
Пример #3
0
def test_setup_hyperopt_configuration_without_arguments(
        mocker, default_conf, caplog) -> None:
    mocker.patch('freqtrade.configuration.open',
                 mocker.mock_open(read_data=json.dumps(default_conf)))

    args = ['--config', 'config.json', 'hyperopt']

    config = setup_configuration(get_args(args), RunMode.HYPEROPT)
    assert 'max_open_trades' in config
    assert 'stake_currency' in config
    assert 'stake_amount' in config
    assert 'exchange' in config
    assert 'pair_whitelist' in config['exchange']
    assert 'datadir' in config
    assert log_has('Using data folder: {} ...'.format(config['datadir']),
                   caplog.record_tuples)
    assert 'ticker_interval' in config
    assert not log_has_re('Parameter -i/--ticker-interval detected .*',
                          caplog.record_tuples)

    assert 'live' not in config
    assert not log_has('Parameter -l/--live detected ...',
                       caplog.record_tuples)

    assert 'position_stacking' not in config
    assert not log_has('Parameter --enable-position-stacking detected ...',
                       caplog.record_tuples)

    assert 'refresh_pairs' not in config
    assert not log_has('Parameter -r/--refresh-pairs-cached detected ...',
                       caplog.record_tuples)

    assert 'timerange' not in config
    assert 'runmode' in config
    assert config['runmode'] == RunMode.HYPEROPT
Пример #4
0
def test_add_indicators(default_conf, caplog):
    pair = "UNITTEST/BTC"
    timerange = TimeRange(None, 'line', 0, -1000)

    data = history.load_pair_history(pair=pair, ticker_interval='1m',
                                     datadir=None, timerange=timerange)
    indicators1 = ["ema10"]
    indicators2 = ["macd"]

    # Generate buy/sell signals and indicators
    strat = DefaultStrategy(default_conf)
    data = strat.analyze_ticker(data, {'pair': pair})
    fig = generage_empty_figure()

    # Row 1
    fig1 = add_indicators(fig=deepcopy(fig), row=1, indicators=indicators1, data=data)
    figure = fig1.layout.figure
    ema10 = find_trace_in_fig_data(figure.data, "ema10")
    assert isinstance(ema10, go.Scatter)
    assert ema10.yaxis == "y"

    fig2 = add_indicators(fig=deepcopy(fig), row=3, indicators=indicators2, data=data)
    figure = fig2.layout.figure
    macd = find_trace_in_fig_data(figure.data, "macd")
    assert isinstance(macd, go.Scatter)
    assert macd.yaxis == "y3"

    # No indicator found
    fig3 = add_indicators(fig=deepcopy(fig), row=3, indicators=['no_indicator'], data=data)
    assert fig == fig3
    assert log_has_re(r'Indicator "no_indicator" ignored\..*', caplog)
Пример #5
0
def test_load_staticmethod_importerror(mocker, caplog):
    mocker.patch("freqtrade.resolvers.strategy_resolver.import_strategy", Mock(
        side_effect=TypeError("can't pickle staticmethod objects")))
    with pytest.raises(ImportError,
                       match=r"Impossible to load Strategy 'DefaultStrategy'."
                             r" This class does not exist or contains Python code errors"):
        StrategyResolver()
    assert log_has_re(r".*Error: can't pickle staticmethod objects", caplog.record_tuples)
Пример #6
0
def test_load_strategy_invalid_directory(result, caplog):
    resolver = StrategyResolver()
    extra_dir = Path.cwd() / 'some/path'
    resolver._load_strategy('TestStrategy', config={}, extra_dir=extra_dir)

    assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist',
                      caplog.record_tuples)

    assert 'adx' in resolver.strategy.advise_indicators(
        result, {'pair': 'ETH/BTC'})
Пример #7
0
def test_load_strategy_base64(result, caplog, default_conf):
    with open("user_data/strategies/test_strategy.py", "rb") as file:
        encoded_string = urlsafe_b64encode(file.read()).decode("utf-8")
    default_conf.update({'strategy': 'TestStrategy:{}'.format(encoded_string)})

    resolver = StrategyResolver(default_conf)
    assert 'adx' in resolver.strategy.advise_indicators(
        result, {'pair': 'ETH/BTC'})
    # Make sure strategy was loaded from base64 (using temp directory)!!
    assert log_has_re(
        r"Using resolved strategy TestStrategy from '" +
        tempfile.gettempdir() + r"/.*/TestStrategy\.py'\.\.\.", caplog)