diff --git a/freqtrade/util/coin_gecko.py b/freqtrade/util/coin_gecko.py index c39721c00..47b80875b 100644 --- a/freqtrade/util/coin_gecko.py +++ b/freqtrade/util/coin_gecko.py @@ -16,10 +16,11 @@ class FtCoinGeckoApi(CoinGeckoAPI): # Doint' pass api_key to parent, instead set the header on the session directly self._api_key = api_key - if api_key and is_demo: - # Use demo api key - self.api_base_url = self.__API_URL_BASE - self.session.params.update({"x_cg_demo_api_key": api_key}) - else: + if api_key and not is_demo: self.api_base_url = self.__PRO_API_URL_BASE self.session.params.update({"x_cg_pro_api_key": api_key}) + else: + # Use demo api key + self.api_base_url = self.__API_URL_BASE + if api_key: + self.session.params.update({"x_cg_demo_api_key": api_key}) diff --git a/tests/rpc/test_fiat_convert.py b/tests/rpc/test_fiat_convert.py index 4d502b32b..75b6fd0b4 100644 --- a/tests/rpc/test_fiat_convert.py +++ b/tests/rpc/test_fiat_convert.py @@ -8,6 +8,7 @@ import pytest from requests.exceptions import RequestException from freqtrade.rpc.fiat_convert import CryptoToFiatConverter +from freqtrade.util.coin_gecko import FtCoinGeckoApi from tests.conftest import log_has, log_has_re @@ -201,3 +202,18 @@ def test_convert_amount(mocker): crypto_amount="1.23", crypto_symbol="BTC", fiat_symbol="BTC" ) assert result == 1.23 + + +def test_FtCoinGeckoApi(): + ftc = FtCoinGeckoApi() + assert ftc._api_key == "" + assert ftc.api_base_url == "https://api.coingecko.com/api/v3/" + + # defaults to demo + ftc = FtCoinGeckoApi(api_key="123456") + assert ftc._api_key == "123456" + assert ftc.api_base_url == "https://api.coingecko.com/api/v3/" + + ftc = FtCoinGeckoApi(api_key="123456", is_demo=False) + assert ftc._api_key == "123456" + assert ftc.api_base_url == "https://pro-api.coingecko.com/api/v3/"