Don't fail if fetchTickers is not availlable

This commit is contained in:
Matthias 2022-10-13 04:58:02 +00:00
parent a6f6a17393
commit 39c27cfc37
2 changed files with 8 additions and 0 deletions

View File

@ -1427,6 +1427,8 @@ class Exchange:
:return: fetch_tickers result :return: fetch_tickers result
""" """
tickers: Tickers tickers: Tickers
if not self.exchange_has('fetchTickers'):
return {}
if cached: if cached:
with self._cache_lock: with self._cache_lock:
tickers = self._fetch_tickers_cache.get('fetch_tickers') # type: ignore tickers = self._fetch_tickers_cache.get('fetch_tickers') # type: ignore

View File

@ -1834,6 +1834,7 @@ def test_get_tickers(default_conf, mocker, exchange_name):
'last': 41, 'last': 41,
} }
} }
mocker.patch('freqtrade.exchange.exchange.Exchange.exchange_has', return_value=True)
api_mock.fetch_tickers = MagicMock(return_value=tick) api_mock.fetch_tickers = MagicMock(return_value=tick)
api_mock.fetch_bids_asks = MagicMock(return_value={}) api_mock.fetch_bids_asks = MagicMock(return_value={})
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name) exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
@ -1883,6 +1884,11 @@ def test_get_tickers(default_conf, mocker, exchange_name):
assert api_mock.fetch_tickers.call_count == 1 assert api_mock.fetch_tickers.call_count == 1
assert api_mock.fetch_bids_asks.call_count == (1 if exchange_name == 'binance' else 0) assert api_mock.fetch_bids_asks.call_count == (1 if exchange_name == 'binance' else 0)
api_mock.fetch_tickers.reset_mock()
api_mock.fetch_bids_asks.reset_mock()
mocker.patch('freqtrade.exchange.exchange.Exchange.exchange_has', return_value=False)
assert exchange.get_tickers() == {}
@pytest.mark.parametrize("exchange_name", EXCHANGES) @pytest.mark.parametrize("exchange_name", EXCHANGES)
def test_fetch_ticker(default_conf, mocker, exchange_name): def test_fetch_ticker(default_conf, mocker, exchange_name):