Catch all exceptions from fiat-convert api calls

This commit is contained in:
Matthias 2018-07-21 19:50:38 +02:00
parent 6f7898809a
commit 66af41192a
2 changed files with 20 additions and 3 deletions

View File

@ -7,7 +7,6 @@ import logging
import time
from typing import Dict, List
from requests.exceptions import RequestException
from coinmarketcap import Market
from freqtrade.constants import SUPPORTED_FIAT
@ -90,10 +89,10 @@ class CryptoToFiatConverter(object):
coinlistings = self._coinmarketcap.listings()
self._cryptomap = dict(map(lambda coin: (coin["symbol"], str(coin["id"])),
coinlistings["data"]))
except (ValueError, RequestException) as exception:
except (BaseException) as exception:
logger.error(
"Could not load FIAT Cryptocurrency map for the following problem: %s",
exception
type(exception).__name__
)
def convert_amount(self, crypto_amount: float, crypto_symbol: str, fiat_symbol: str) -> float:

View File

@ -183,6 +183,24 @@ def test_fiat_convert_without_network(mocker):
CryptoToFiatConverter._coinmarketcap = cmc_temp
def test_fiat_invalid_response(mocker, caplog):
# Because CryptoToFiatConverter is a Singleton we reset the listings
listmock = MagicMock(return_value="{'novalidjson':DEADBEEFf}")
mocker.patch.multiple(
'freqtrade.fiat_convert.Market',
listings=listmock,
)
# with pytest.raises(RequestEsxception):
fiat_convert = CryptoToFiatConverter()
fiat_convert._cryptomap = {}
fiat_convert._load_cryptomap()
length_cryptomap = len(fiat_convert._cryptomap)
assert length_cryptomap == 0
assert log_has('Could not load FIAT Cryptocurrency map for the following problem: TypeError',
caplog.record_tuples)
def test_convert_amount(mocker):
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter.get_price', return_value=12345.0)