enhance check_exchange

This commit is contained in:
hroff-1902 2019-06-11 13:18:35 +03:00
parent 50c7a2445b
commit 676e730013
4 changed files with 50 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)