Repository: rotki/rotki

Issue:
Initial dashboard loading is slow
## Problem Definition

The initial loading of the dashboard has gotten slower. It takes some time before the first data is shown in the dashboard. Find out why and fix it.

## Task

After some searching I am sure this is because we are still using both https://free.currencyconverterapi.com/ and https://exchangeratesapi.io/ as a fallback. But right now the first (free currency converter) requires an API key and as such all requests fail.

Perhaps the right way is to reverse the queries and query the exchangeratesapi first and input a fallback api key in rotkehlchen for the free currency converter.



Discussion:

Resolving patch:
diff --git a/rotkehlchen/constants.py b/rotkehlchen/constants.py
--- a/rotkehlchen/constants.py
+++ b/rotkehlchen/constants.py
@@ -48,6 +48,8 @@
 EV_INTEREST_PAYMENT = typing.EventType('interest_rate_payment')
 EV_MARGIN_CLOSE = typing.EventType('margin_position_close')
 
+CURRENCYCONVERTER_API_KEY = '7ad371210f296db27c19'
+
 
 ZERO = FVal(0)
 
diff --git a/rotkehlchen/inquirer.py b/rotkehlchen/inquirer.py
--- a/rotkehlchen/inquirer.py
+++ b/rotkehlchen/inquirer.py
@@ -8,6 +8,7 @@
 import requests
 
 from rotkehlchen.constants import (
+    CURRENCYCONVERTER_API_KEY,
     FIAT_CURRENCIES,
     S_BCHSV,
     S_BQX,
@@ -124,8 +125,11 @@ def _query_currency_converterapi(base: FiatAsset, quote: FiatAsset) -> Optional[
         base_currency=base,
         quote_currency=quote,
     )
-    pair = '{}_{}'.format(base, quote)
-    querystr = 'https://free.currencyconverterapi.com/api/v5/convert?q={}'.format(pair)
+    pair = f'{base}_{quote}'
+    querystr = (
+        f'https://free.currencyconverterapi.com/api/v6/convert?'
+        f'q={pair}&apiKey={CURRENCYCONVERTER_API_KEY}'
+    )
     try:
         resp = request_get_dict(querystr)
         return FVal(resp['results'][pair]['val'])
@@ -291,9 +295,9 @@ def query_fiat_pair(self, base: FiatAsset, quote: FiatAsset) -> FVal:
         if price:
             return price
 
-        price = _query_currency_converterapi(base, quote)
+        price = _query_exchanges_rateapi(base, quote)
         if not price:
-            price = _query_exchanges_rateapi(base, quote)
+            price = _query_currency_converterapi(base, quote)
 
         if not price:
             # Search the cache for any price in the last month


Test patch:
diff --git a/rotkehlchen/tests/test_inquirer.py b/rotkehlchen/tests/test_inquirer.py
--- a/rotkehlchen/tests/test_inquirer.py
+++ b/rotkehlchen/tests/test_inquirer.py
@@ -15,7 +15,7 @@
     reason='some of these APIs frequently become unavailable',
 )
 @pytest.mark.parametrize('use_clean_caching_directory', [True])
-def test_query_realtieme_price_apis(inquirer):
+def test_query_realtime_price_apis(inquirer):
     result = _query_currency_converterapi('USD', 'EUR')
     assert result and isinstance(result, FVal)
     result = _query_exchanges_rateapi('USD', 'GBP')
@@ -29,14 +29,14 @@ def test_switching_to_backup_api(inquirer):
     count = 0
     original_get = requests.get
 
-    def mock_currency_converter_fail(uri):
+    def mock_exchanges_rateapi_fail(uri):
         nonlocal count
         count += 1
-        if 'currencyconverterapi' in uri:
+        if 'exchangeratesapi' in uri:
             return MockResponse(501, '{"msg": "some error")')
         return original_get(uri)
 
-    with patch('requests.get', side_effect=mock_currency_converter_fail):
+    with patch('requests.get', side_effect=mock_exchanges_rateapi_fail):
         result = inquirer.query_fiat_pair('USD', 'EUR')
         assert result and isinstance(result, FVal)
         assert count > 1, 'requests.get should have been called more than once'