From 56e697acf5987811e62f09ee737f95de521ae078 Mon Sep 17 00:00:00 2001 From: xmatthias Date: Mon, 21 May 2018 20:01:41 +0200 Subject: [PATCH 1/2] Fix error initializing coinmarketcap --- freqtrade/fiat_convert.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/freqtrade/fiat_convert.py b/freqtrade/fiat_convert.py index 7e74adcd2..17882f51a 100644 --- a/freqtrade/fiat_convert.py +++ b/freqtrade/fiat_convert.py @@ -8,6 +8,7 @@ import time from typing import Dict from coinmarketcap import Market +from requests.exceptions import RequestException logger = logging.getLogger(__name__) @@ -94,8 +95,8 @@ class CryptoToFiatConverter(object): coinlistings = self._coinmarketcap.listings() self._cryptomap = dict(map(lambda coin: (coin["symbol"], str(coin["id"])), coinlistings["data"])) - except ValueError: - logger.error("Could not load FIAT Cryptocurrency map") + except (ValueError, RequestException) as e: + logger.error("Could not load FIAT Cryptocurrency map for the following problem: %s", e) def convert_amount(self, crypto_amount: float, crypto_symbol: str, fiat_symbol: str) -> float: """ From e2efd7c6ec12dcef187864053c71d088bd34b7e8 Mon Sep 17 00:00:00 2001 From: xmatthias Date: Mon, 21 May 2018 20:03:25 +0200 Subject: [PATCH 2/2] add test to verify network exception is cought on init of coinmarketcap --- freqtrade/tests/test_fiat_convert.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/freqtrade/tests/test_fiat_convert.py b/freqtrade/tests/test_fiat_convert.py index f5be9daf0..b37ca0f5c 100644 --- a/freqtrade/tests/test_fiat_convert.py +++ b/freqtrade/tests/test_fiat_convert.py @@ -6,6 +6,8 @@ from unittest.mock import MagicMock import pytest +from requests.exceptions import RequestException + from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter from freqtrade.tests.conftest import patch_coinmarketcap @@ -133,6 +135,21 @@ def test_loadcryptomap(mocker): assert fiat_convert._cryptomap["BTC"] == "1" +def test_fiat_init_network_exception(mocker): + # Because CryptoToFiatConverter is a Singleton we reset the listings + listmock = MagicMock(side_effect=RequestException) + mocker.patch.multiple( + 'freqtrade.fiat_convert.Market', + listings=listmock, + ) + # with pytest.raises(RequestEsxception): + fiat_convert = CryptoToFiatConverter() + fiat_convert._cryptomap = {} + fiat_convert._load_cryptomap() + + assert len(fiat_convert._cryptomap) == 0 + + def test_fiat_convert_without_network(): # Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap