diff --git a/freqtrade/configuration/__init__.py b/freqtrade/configuration/__init__.py index 730a4e47f..dee42d535 100644 --- a/freqtrade/configuration/__init__.py +++ b/freqtrade/configuration/__init__.py @@ -1,6 +1,5 @@ # flake8: noqa: F401 -from freqtrade.configuration.check_exchange import check_exchange from freqtrade.configuration.config_setup import setup_utils_configuration from freqtrade.configuration.config_validation import validate_config_consistency from freqtrade.configuration.configuration import Configuration diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 76105cc4d..5e6da4178 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -8,7 +8,6 @@ from pathlib import Path from typing import Any, Callable, Dict, List, Optional from freqtrade import constants -from freqtrade.configuration.check_exchange import check_exchange from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings from freqtrade.configuration.directory_operations import create_datadir, create_userdata_dir from freqtrade.configuration.environment_vars import enironment_vars_to_dict @@ -100,6 +99,9 @@ class Configuration: self._process_freqai_options(config) + # Import check_exchange here to avoid import cycle problems + from freqtrade.exchange.check_exchange import check_exchange + # Check if the exchange set by the user is supported check_exchange(config, config.get('experimental', {}).get('block_bad_exchanges', True)) diff --git a/freqtrade/configuration/check_exchange.py b/freqtrade/exchange/check_exchange.py similarity index 100% rename from freqtrade/configuration/check_exchange.py rename to freqtrade/exchange/check_exchange.py diff --git a/tests/exchange/test_exchange_utils.py b/tests/exchange/test_exchange_utils.py new file mode 100644 index 000000000..a454b37d0 --- /dev/null +++ b/tests/exchange/test_exchange_utils.py @@ -0,0 +1,69 @@ +# pragma pylint: disable=missing-docstring, protected-access, invalid-name + +import pytest + +from freqtrade.enums import RunMode +from freqtrade.exceptions import OperationalException +from freqtrade.exchange.check_exchange import check_exchange +from tests.conftest import log_has_re + + +def test_check_exchange(default_conf, caplog) -> None: + # Test an officially supported by Freqtrade team exchange + default_conf['runmode'] = RunMode.DRY_RUN + default_conf.get('exchange').update({'name': 'BITTREX'}) + assert check_exchange(default_conf) + assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.", + caplog) + caplog.clear() + + # Test an officially supported by Freqtrade team exchange + default_conf.get('exchange').update({'name': 'binance'}) + assert check_exchange(default_conf) + assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.", + caplog) + caplog.clear() + + # Test an available exchange, supported by ccxt + default_conf.get('exchange').update({'name': 'huobipro'}) + assert check_exchange(default_conf) + assert log_has_re(r"Exchange .* is known to the the ccxt library, available for the bot, " + r"but not officially supported " + r"by the Freqtrade development team\. .*", caplog) + caplog.clear() + + # Test a 'bad' exchange, which known to have serious problems + default_conf.get('exchange').update({'name': 'bitmex'}) + with pytest.raises(OperationalException, + match=r"Exchange .* will not work with Freqtrade\..*"): + check_exchange(default_conf) + caplog.clear() + + # Test a 'bad' exchange with check_for_bad=False + default_conf.get('exchange').update({'name': 'bitmex'}) + assert check_exchange(default_conf, False) + assert log_has_re(r"Exchange .* is known to the the ccxt library, available for the bot, " + r"but not officially supported " + r"by the Freqtrade development team\. .*", caplog) + caplog.clear() + + # Test an invalid exchange + default_conf.get('exchange').update({'name': 'unknown_exchange'}) + with pytest.raises( + OperationalException, + match=r'Exchange "unknown_exchange" is not known to the ccxt library ' + r'and therefore not available for the bot.*' + ): + check_exchange(default_conf) + + # Test no exchange... + default_conf.get('exchange').update({'name': ''}) + default_conf['runmode'] = RunMode.PLOT + assert check_exchange(default_conf) + + # Test no exchange... + default_conf.get('exchange').update({'name': ''}) + default_conf['runmode'] = RunMode.UTIL_EXCHANGE + with pytest.raises(OperationalException, + match=r'This command requires a configured exchange.*'): + check_exchange(default_conf) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 99edf0233..2336e3585 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -11,7 +11,7 @@ import pytest from jsonschema import ValidationError from freqtrade.commands import Arguments -from freqtrade.configuration import Configuration, check_exchange, validate_config_consistency +from freqtrade.configuration import Configuration, validate_config_consistency from freqtrade.configuration.config_validation import validate_config_schema from freqtrade.configuration.deprecated_settings import (check_conflicting_settings, process_deprecated_setting, @@ -584,67 +584,6 @@ def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None: assert config['runmode'] == RunMode.HYPEROPT -def test_check_exchange(default_conf, caplog) -> None: - # Test an officially supported by Freqtrade team exchange - default_conf['runmode'] = RunMode.DRY_RUN - default_conf.get('exchange').update({'name': 'BITTREX'}) - assert check_exchange(default_conf) - assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.", - caplog) - caplog.clear() - - # Test an officially supported by Freqtrade team exchange - default_conf.get('exchange').update({'name': 'binance'}) - assert check_exchange(default_conf) - assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.", - caplog) - caplog.clear() - - # Test an available exchange, supported by ccxt - default_conf.get('exchange').update({'name': 'huobipro'}) - assert check_exchange(default_conf) - assert log_has_re(r"Exchange .* is known to the the ccxt library, available for the bot, " - r"but not officially supported " - r"by the Freqtrade development team\. .*", caplog) - caplog.clear() - - # Test a 'bad' exchange, which known to have serious problems - default_conf.get('exchange').update({'name': 'bitmex'}) - with pytest.raises(OperationalException, - match=r"Exchange .* will not work with Freqtrade\..*"): - check_exchange(default_conf) - caplog.clear() - - # Test a 'bad' exchange with check_for_bad=False - default_conf.get('exchange').update({'name': 'bitmex'}) - assert check_exchange(default_conf, False) - assert log_has_re(r"Exchange .* is known to the the ccxt library, available for the bot, " - r"but not officially supported " - r"by the Freqtrade development team\. .*", caplog) - caplog.clear() - - # Test an invalid exchange - default_conf.get('exchange').update({'name': 'unknown_exchange'}) - with pytest.raises( - OperationalException, - match=r'Exchange "unknown_exchange" is not known to the ccxt library ' - r'and therefore not available for the bot.*' - ): - check_exchange(default_conf) - - # Test no exchange... - default_conf.get('exchange').update({'name': ''}) - default_conf['runmode'] = RunMode.PLOT - assert check_exchange(default_conf) - - # Test no exchange... - default_conf.get('exchange').update({'name': ''}) - default_conf['runmode'] = RunMode.UTIL_EXCHANGE - with pytest.raises(OperationalException, - match=r'This command requires a configured exchange.*'): - check_exchange(default_conf) - - def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None: patched_configuration_load_config_file(mocker, default_conf)