From 676e7300132e15aa55a8cdb844e2f3b582140184 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Tue, 11 Jun 2019 13:18:35 +0300 Subject: [PATCH] enhance check_exchange --- freqtrade/configuration.py | 41 +++++++++++++++++++++------ freqtrade/exchange/__init__.py | 6 ++-- freqtrade/exchange/exchange.py | 18 ++++++++---- freqtrade/tests/test_configuration.py | 2 +- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/freqtrade/configuration.py b/freqtrade/configuration.py index c19580c36..90393cae2 100644 --- a/freqtrade/configuration.py +++ b/freqtrade/configuration.py @@ -13,7 +13,8 @@ from jsonschema import Draft4Validator, validators from jsonschema.exceptions import ValidationError, best_match from freqtrade import OperationalException, constants -from freqtrade.exchange import is_exchange_supported, supported_exchanges +from freqtrade.exchange import (is_exchange_bad, is_exchange_known, + is_exchange_officially_supported, known_exchanges) from freqtrade.misc import deep_merge_dicts from freqtrade.state import RunMode @@ -375,22 +376,44 @@ class Configuration(object): return self.config - def check_exchange(self, config: Dict[str, Any]) -> bool: + def check_exchange(self, config: Dict[str, Any], check_for_bad: bool = True) -> bool: """ Check if the exchange name in the config file is supported by Freqtrade - :return: True or raised an exception if the exchange if not supported + :param check_for_bad: if True, check the exchange against the list of known 'bad' + exchanges + :return: False if exchange is 'bad', i.e. is known to work with the bot with + critical issues or does not work at all, crashes, etc. True otherwise. + raises an exception if the exchange if not supported by ccxt + and thus is not known for the Freqtrade at all. """ - exchange = config.get('exchange', {}).get('name').lower() - if not is_exchange_supported(exchange): + logger.info("Checking exchange...") - exception_msg = f'Exchange "{exchange}" not supported.\n' \ - f'The following exchanges are supported: ' \ - f'{", ".join(supported_exchanges())}' + exchange = config.get('exchange', {}).get('name').lower() + if not is_exchange_known(exchange): + exception_msg = f'Exchange "{exchange}" is not supported by ccxt ' \ + f'and not known for the bot.\n' \ + f'The following exchanges are supported by ccxt: ' \ + f'{", ".join(known_exchanges())}' logger.critical(exception_msg) raise OperationalException( exception_msg ) - logger.debug('Exchange "%s" supported', exchange) + logger.info(f'Exchange "{exchange}" is supported by ccxt and known for the bot.') + + if is_exchange_officially_supported(exchange): + logger.info(f'Exchange "{exchange}" is officially supported ' + f'by the Freqtrade development team.') + else: + logger.warning(f'Exchange "{exchange}" is not officially supported ' + f'by the Freqtrade development team. ' + f'It may work with serious issues or not work at all. ' + f'Use it at your own discretion.') + + if check_for_bad and is_exchange_bad(exchange): + logger.warning(f'Exchange "{exchange}" is known to not work with Freqtrade yet. ' + f'Use it only for development and testing purposes.') + return False + return True diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 3c90e69ee..29e50e29c 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -1,6 +1,8 @@ from freqtrade.exchange.exchange import Exchange # noqa: F401 -from freqtrade.exchange.exchange import (is_exchange_supported, # noqa: F401 - supported_exchanges) +from freqtrade.exchange.exchange import (is_exchange_bad, # noqa: F401 + is_exchange_known, + is_exchange_officially_supported, + known_exchanges) from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401 timeframe_to_minutes, timeframe_to_msecs) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index ea6996efb..1196f5efe 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -156,8 +156,8 @@ class Exchange(object): # Find matching class for the given exchange name name = exchange_config['name'] - if not is_exchange_supported(name, ccxt_module): - raise OperationalException(f'Exchange {name} is not supported') +# if not is_exchange_supported(name, ccxt_module): +# raise OperationalException(f'Exchange {name} is not supported') ex_config = { 'apiKey': exchange_config.get('key'), @@ -722,11 +722,19 @@ class Exchange(object): raise OperationalException(e) -def is_exchange_supported(exchange: str, ccxt_module=None) -> bool: - return exchange in supported_exchanges(ccxt_module) +def is_exchange_bad(exchange: str) -> bool: + return exchange in ['bitmex'] -def supported_exchanges(ccxt_module=None) -> List[str]: +def is_exchange_known(exchange: str, ccxt_module=None) -> bool: + return exchange in known_exchanges(ccxt_module) + + +def is_exchange_officially_supported(exchange: str) -> bool: + return exchange in ['bittrex', 'binance'] + + +def known_exchanges(ccxt_module=None) -> List[str]: return ccxt_module.exchanges if ccxt_module is not None else ccxt.exchanges diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index aee0dfadd..03f0c004c 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -484,7 +484,7 @@ def test_check_exchange(default_conf, caplog) -> None: with pytest.raises( OperationalException, - match=r'.*Exchange "unknown_exchange" not supported.*' + match=r'.*Exchange "unknown_exchange" is not supported by ccxt and not known for the bot.*' ): configuration.check_exchange(default_conf)