enhance check_exchange
This commit is contained in:
parent
50c7a2445b
commit
676e730013
@ -13,7 +13,8 @@ from jsonschema import Draft4Validator, validators
|
|||||||
from jsonschema.exceptions import ValidationError, best_match
|
from jsonschema.exceptions import ValidationError, best_match
|
||||||
|
|
||||||
from freqtrade import OperationalException, constants
|
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.misc import deep_merge_dicts
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
|
|
||||||
@ -375,22 +376,44 @@ class Configuration(object):
|
|||||||
|
|
||||||
return self.config
|
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
|
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()
|
logger.info("Checking exchange...")
|
||||||
if not is_exchange_supported(exchange):
|
|
||||||
|
|
||||||
exception_msg = f'Exchange "{exchange}" not supported.\n' \
|
exchange = config.get('exchange', {}).get('name').lower()
|
||||||
f'The following exchanges are supported: ' \
|
if not is_exchange_known(exchange):
|
||||||
f'{", ".join(supported_exchanges())}'
|
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)
|
logger.critical(exception_msg)
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
exception_msg
|
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
|
return True
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from freqtrade.exchange.exchange import Exchange # noqa: F401
|
from freqtrade.exchange.exchange import Exchange # noqa: F401
|
||||||
from freqtrade.exchange.exchange import (is_exchange_supported, # noqa: F401
|
from freqtrade.exchange.exchange import (is_exchange_bad, # noqa: F401
|
||||||
supported_exchanges)
|
is_exchange_known,
|
||||||
|
is_exchange_officially_supported,
|
||||||
|
known_exchanges)
|
||||||
from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401
|
from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401
|
||||||
timeframe_to_minutes,
|
timeframe_to_minutes,
|
||||||
timeframe_to_msecs)
|
timeframe_to_msecs)
|
||||||
|
@ -156,8 +156,8 @@ class Exchange(object):
|
|||||||
# Find matching class for the given exchange name
|
# Find matching class for the given exchange name
|
||||||
name = exchange_config['name']
|
name = exchange_config['name']
|
||||||
|
|
||||||
if not is_exchange_supported(name, ccxt_module):
|
# if not is_exchange_supported(name, ccxt_module):
|
||||||
raise OperationalException(f'Exchange {name} is not supported')
|
# raise OperationalException(f'Exchange {name} is not supported')
|
||||||
|
|
||||||
ex_config = {
|
ex_config = {
|
||||||
'apiKey': exchange_config.get('key'),
|
'apiKey': exchange_config.get('key'),
|
||||||
@ -722,11 +722,19 @@ class Exchange(object):
|
|||||||
raise OperationalException(e)
|
raise OperationalException(e)
|
||||||
|
|
||||||
|
|
||||||
def is_exchange_supported(exchange: str, ccxt_module=None) -> bool:
|
def is_exchange_bad(exchange: str) -> bool:
|
||||||
return exchange in supported_exchanges(ccxt_module)
|
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
|
return ccxt_module.exchanges if ccxt_module is not None else ccxt.exchanges
|
||||||
|
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ def test_check_exchange(default_conf, caplog) -> None:
|
|||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
OperationalException,
|
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)
|
configuration.check_exchange(default_conf)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user