Merge pull request #733 from xmatthias/fix_fiat_init
Fix fiat initialization
This commit is contained in:
commit
0837f3f9f3
@ -8,6 +8,7 @@ import time
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from coinmarketcap import Market
|
from coinmarketcap import Market
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -94,8 +95,8 @@ class CryptoToFiatConverter(object):
|
|||||||
coinlistings = self._coinmarketcap.listings()
|
coinlistings = self._coinmarketcap.listings()
|
||||||
self._cryptomap = dict(map(lambda coin: (coin["symbol"], str(coin["id"])),
|
self._cryptomap = dict(map(lambda coin: (coin["symbol"], str(coin["id"])),
|
||||||
coinlistings["data"]))
|
coinlistings["data"]))
|
||||||
except ValueError:
|
except (ValueError, RequestException) as e:
|
||||||
logger.error("Could not load FIAT Cryptocurrency map")
|
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:
|
def convert_amount(self, crypto_amount: float, crypto_symbol: str, fiat_symbol: str) -> float:
|
||||||
"""
|
"""
|
||||||
|
@ -6,6 +6,8 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter
|
from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter
|
||||||
from freqtrade.tests.conftest import patch_coinmarketcap
|
from freqtrade.tests.conftest import patch_coinmarketcap
|
||||||
|
|
||||||
@ -133,6 +135,21 @@ def test_loadcryptomap(mocker):
|
|||||||
assert fiat_convert._cryptomap["BTC"] == "1"
|
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():
|
def test_fiat_convert_without_network():
|
||||||
# Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap
|
# Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user