2019-07-11 18:23:23 +00:00
|
|
|
import logging
|
|
|
|
|
2022-09-18 11:20:36 +00:00
|
|
|
from freqtrade.constants import Config
|
2021-06-08 19:20:35 +00:00
|
|
|
from freqtrade.enums import RunMode
|
2019-12-30 14:02:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2022-10-04 17:28:57 +00:00
|
|
|
from freqtrade.exchange import available_exchanges, is_exchange_known_ccxt, validate_exchange
|
|
|
|
from freqtrade.exchange.common import MAP_EXCHANGE_CHILDCLASS, SUPPORTED_EXCHANGES
|
2019-07-11 18:23:23 +00:00
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2019-07-11 18:23:23 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-09-18 11:20:36 +00:00
|
|
|
def check_exchange(config: Config, check_for_bad: bool = True) -> bool:
|
2019-07-11 18:23:23 +00:00
|
|
|
"""
|
|
|
|
Check if the exchange name in the config file is supported by Freqtrade
|
|
|
|
: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.
|
|
|
|
"""
|
2019-08-31 13:15:30 +00:00
|
|
|
|
2024-05-12 14:58:33 +00:00
|
|
|
if config["runmode"] in [
|
|
|
|
RunMode.PLOT,
|
|
|
|
RunMode.UTIL_NO_EXCHANGE,
|
|
|
|
RunMode.OTHER,
|
|
|
|
] and not config.get("exchange", {}).get("name"):
|
2019-08-31 13:15:30 +00:00
|
|
|
# Skip checking exchange in plot mode, since it requires no exchange
|
|
|
|
return True
|
2019-07-11 18:23:23 +00:00
|
|
|
logger.info("Checking exchange...")
|
|
|
|
|
2024-05-12 14:58:33 +00:00
|
|
|
exchange = config.get("exchange", {}).get("name", "").lower()
|
2019-09-21 09:24:51 +00:00
|
|
|
if not exchange:
|
|
|
|
raise OperationalException(
|
2024-05-13 17:49:15 +00:00
|
|
|
f"This command requires a configured exchange. You should either use "
|
|
|
|
f"`--exchange <exchange_name>` or specify a configuration file via `--config`.\n"
|
|
|
|
f"The following exchanges are available for Freqtrade: "
|
2019-09-21 09:24:51 +00:00
|
|
|
f'{", ".join(available_exchanges())}'
|
|
|
|
)
|
|
|
|
|
2019-09-30 21:33:33 +00:00
|
|
|
if not is_exchange_known_ccxt(exchange):
|
2019-07-11 18:23:23 +00:00
|
|
|
raise OperationalException(
|
2021-08-06 22:19:36 +00:00
|
|
|
f'Exchange "{exchange}" is not known to the ccxt library '
|
2024-05-13 17:49:15 +00:00
|
|
|
f"and therefore not available for the bot.\n"
|
|
|
|
f"The following exchanges are available for Freqtrade: "
|
2021-08-06 22:19:36 +00:00
|
|
|
f'{", ".join(available_exchanges())}'
|
2019-07-11 18:23:23 +00:00
|
|
|
)
|
|
|
|
|
2024-07-03 11:34:00 +00:00
|
|
|
valid, reason, _ = validate_exchange(exchange)
|
2021-04-06 18:16:29 +00:00
|
|
|
if not valid:
|
|
|
|
if check_for_bad:
|
2024-05-12 14:58:33 +00:00
|
|
|
raise OperationalException(
|
|
|
|
f'Exchange "{exchange}" will not work with Freqtrade. ' f"Reason: {reason}"
|
|
|
|
)
|
2021-04-06 18:16:29 +00:00
|
|
|
else:
|
|
|
|
logger.warning(f'Exchange "{exchange}" will not work with Freqtrade. Reason: {reason}')
|
2019-07-11 18:23:23 +00:00
|
|
|
|
2022-10-04 17:28:57 +00:00
|
|
|
if MAP_EXCHANGE_CHILDCLASS.get(exchange, exchange) in SUPPORTED_EXCHANGES:
|
2024-05-12 14:58:33 +00:00
|
|
|
logger.info(
|
|
|
|
f'Exchange "{exchange}" is officially supported ' f"by the Freqtrade development team."
|
|
|
|
)
|
2019-07-11 18:23:23 +00:00
|
|
|
else:
|
2024-05-12 14:58:33 +00:00
|
|
|
logger.warning(
|
|
|
|
f'Exchange "{exchange}" is known to the ccxt library, '
|
|
|
|
f"available for the bot, but not officially supported "
|
|
|
|
f"by the Freqtrade development team. "
|
|
|
|
f"It may work flawlessly (please report back) or have serious issues. "
|
|
|
|
f"Use it at your own discretion."
|
|
|
|
)
|
2019-07-11 18:23:23 +00:00
|
|
|
|
|
|
|
return True
|