Merge pull request #5500 from freqtrade/clarify_exchange_error

Clarify exception on load when markets could not be loaded
This commit is contained in:
Matthias 2021-08-29 09:42:17 +02:00 committed by GitHub
commit a6b4b8bfd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -352,9 +352,16 @@ class Exchange:
def validate_stakecurrency(self, stake_currency: str) -> None: def validate_stakecurrency(self, stake_currency: str) -> None:
""" """
Checks stake-currency against available currencies on the exchange. Checks stake-currency against available currencies on the exchange.
Only runs on startup. If markets have not been loaded, there's been a problem with
the connection to the exchange.
:param stake_currency: Stake-currency to validate :param stake_currency: Stake-currency to validate
:raise: OperationalException if stake-currency is not available. :raise: OperationalException if stake-currency is not available.
""" """
if not self._markets:
raise OperationalException(
'Could not load markets, therefore cannot start. '
'Please investigate the above error for more details.'
)
quote_currencies = self.get_quote_currencies() quote_currencies = self.get_quote_currencies()
if stake_currency not in quote_currencies: if stake_currency not in quote_currencies:
raise OperationalException( raise OperationalException(

View File

@ -557,7 +557,7 @@ def test_reload_markets_exception(default_conf, mocker, caplog):
@pytest.mark.parametrize("stake_currency", ['ETH', 'BTC', 'USDT']) @pytest.mark.parametrize("stake_currency", ['ETH', 'BTC', 'USDT'])
def test_validate_stake_currency(default_conf, stake_currency, mocker, caplog): def test_validate_stakecurrency(default_conf, stake_currency, mocker, caplog):
default_conf['stake_currency'] = stake_currency default_conf['stake_currency'] = stake_currency
api_mock = MagicMock() api_mock = MagicMock()
type(api_mock).load_markets = MagicMock(return_value={ type(api_mock).load_markets = MagicMock(return_value={
@ -571,7 +571,7 @@ def test_validate_stake_currency(default_conf, stake_currency, mocker, caplog):
Exchange(default_conf) Exchange(default_conf)
def test_validate_stake_currency_error(default_conf, mocker, caplog): def test_validate_stakecurrency_error(default_conf, mocker, caplog):
default_conf['stake_currency'] = 'XRP' default_conf['stake_currency'] = 'XRP'
api_mock = MagicMock() api_mock = MagicMock()
type(api_mock).load_markets = MagicMock(return_value={ type(api_mock).load_markets = MagicMock(return_value={
@ -587,6 +587,13 @@ def test_validate_stake_currency_error(default_conf, mocker, caplog):
'Available currencies are: BTC, ETH, USDT'): 'Available currencies are: BTC, ETH, USDT'):
Exchange(default_conf) Exchange(default_conf)
type(api_mock).load_markets = MagicMock(side_effect=ccxt.NetworkError('No connection.'))
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
with pytest.raises(OperationalException,
match=r'Could not load markets, therefore cannot start\. Please.*'):
Exchange(default_conf)
def test_get_quote_currencies(default_conf, mocker): def test_get_quote_currencies(default_conf, mocker):
ex = get_patched_exchange(mocker, default_conf) ex = get_patched_exchange(mocker, default_conf)