Add test, invert logic

This commit is contained in:
Matthias 2024-05-20 15:14:15 +02:00
parent 9e0ccb1cf4
commit 94e0a808b7
2 changed files with 22 additions and 5 deletions

View File

@ -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})

View File

@ -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/"