diff --git a/freqtrade/rpc/fiat_convert.py b/freqtrade/rpc/fiat_convert.py index 53440eb15..4e404ed8d 100644 --- a/freqtrade/rpc/fiat_convert.py +++ b/freqtrade/rpc/fiat_convert.py @@ -10,7 +10,7 @@ from typing import Any, Dict, List from cachetools import TTLCache from requests.exceptions import RequestException -from freqtrade.constants import SUPPORTED_FIAT +from freqtrade.constants import SUPPORTED_FIAT, Config from freqtrade.mixins.logging_mixin import LoggingMixin from freqtrade.util.CoinGecko import FtCoinGeckoApi @@ -40,7 +40,7 @@ class CryptoToFiatConverter(LoggingMixin): """ __instance = None - _coingecko: FtCoinGeckoApi = None + _coinlistings: List[Dict] = [] _backoff: float = 0.0 @@ -50,18 +50,18 @@ class CryptoToFiatConverter(LoggingMixin): """ if not cls.__instance: cls.__instance = super().__new__(cls) - try: - # Limit retires to 1 (0 and 1) - # otherwise we risk bot impact if coingecko is down. - cls._coingecko = FtCoinGeckoApi(retries=1) - except BaseException: - cls._coingecko = None return cls.__instance - def __init__(self) -> None: + def __init__(self, config: Config) -> None: # Timeout: 6h self._pair_price: TTLCache = TTLCache(maxsize=500, ttl=6 * 60 * 60) + coingecko_config = config.get("coingecko", {}) + self._coingecko = FtCoinGeckoApi( + api_key=coingecko_config.get("api_key", ""), + is_demo=coingecko_config.get("is_demo", True), + retries=1, + ) LoggingMixin.__init__(self, logger, 3600) self._load_cryptomap() diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index fd75da917..4cafa12ad 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -107,7 +107,7 @@ class RPC: self._freqtrade = freqtrade self._config: Config = freqtrade.config if self._config.get("fiat_display_currency"): - self._fiat_converter = CryptoToFiatConverter() + self._fiat_converter = CryptoToFiatConverter(self._config) @staticmethod def _rpc_show_config(