Repository: rotki/rotki

Issue:
Make sure cryptocompare does not query for custom tokens without symbol
## Problem Definition

This happens now when you have a custom token. Does not crash the app in any way, just kills a querying task. So it's nothing serious. But the querying task should not have existed in the first place.

```
2021-03-09T16:01:22.605Z: Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/externalapis/cryptocompare.py", line 995, in get_historical_data
    to_timestamp=Timestamp(0),
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/externalapis/cryptocompare.py", line 775, in _get_histohour_data_for_range
    to_timestamp=end_date,
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/externalapis/cryptocompare.py", line 511, in query_endpoint_histohour
    result = self._api_query(path=query_path)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/externalapis/cryptocompare.py", line 402, in _api_query
    raise RemoteError(error_message)
rotkehlchen.errors.RemoteError: Failed to query cryptocompare for: "https://min-api.cryptocompare.com/data/v2/histohour?fsym=_CETH_0X48FB253446873234F2FEBBF9BDEAA72D9D387F94&tsym=EUR&limit=2000&toTs=1615303777". Error: fsym param is invalid. (fsym length is higher than maxlength: 30)
```

## Task

Fix it by:

- [ ] Make sure no cryptocompare query task is made for custom tokens without a symbol
- [ ] Check what  is used if cryptocompare identifier is missing. Is it asset identifier, or asset symbol? Enforce symbol. If there is no symbol do nothing.


Discussion:

Resolving patch:
diff --git a/rotkehlchen/assets/asset.py b/rotkehlchen/assets/asset.py
--- a/rotkehlchen/assets/asset.py
+++ b/rotkehlchen/assets/asset.py
@@ -276,9 +276,9 @@ def to_cryptocompare(self) -> str:
         May raise:
             - UnsupportedAsset() if the asset is not supported by cryptocompare
         """
-        cryptocompare_str = self.identifier if self.cryptocompare is None else self.cryptocompare
+        cryptocompare_str = self.symbol if self.cryptocompare is None else self.cryptocompare
         # There is an asset which should not be queried in cryptocompare
-        if cryptocompare_str == '':
+        if cryptocompare_str is None or cryptocompare_str == '':
             raise UnsupportedAsset(f'{self.identifier} is not supported by cryptocompare')
 
         # Seems cryptocompare capitalizes everything. So cDAI -> CDAI
diff --git a/rotkehlchen/externalapis/cryptocompare.py b/rotkehlchen/externalapis/cryptocompare.py
--- a/rotkehlchen/externalapis/cryptocompare.py
+++ b/rotkehlchen/externalapis/cryptocompare.py
@@ -238,13 +238,13 @@ def _check_hourly_data_sanity(
 
 
 def _get_cache_key(from_asset: Asset, to_asset: Asset) -> Optional[PairCacheKey]:
-    try:
-        from_cc_asset = from_asset.to_cryptocompare()
-        to_cc_asset = to_asset.to_cryptocompare()
+    try:  # first see if they both support cryptocompare
+        from_asset.to_cryptocompare()
+        to_asset.to_cryptocompare()
     except UnsupportedAsset:
         return None
 
-    return PairCacheKey(from_cc_asset + '_' + to_cc_asset)
+    return PairCacheKey(from_asset.identifier + '_' + to_asset.identifier)
 
 
 def _write_history_data_in_file(
diff --git a/rotkehlchen/tasks/manager.py b/rotkehlchen/tasks/manager.py
--- a/rotkehlchen/tasks/manager.py
+++ b/rotkehlchen/tasks/manager.py
@@ -109,6 +109,9 @@ def _prepare_cryptocompare_queries(self) -> None:
             if asset.cryptocompare == '' or main_currency.cryptocompare == '':
                 continue  # not supported in cryptocompare
 
+            if asset.cryptocompare is None and asset.symbol is None:
+                continue  # type: ignore  # asset.symbol may be None for auto generated underlying tokens # noqa: E501
+
             data = self.cryptocompare.get_cached_data_metadata(
                 from_asset=asset,
                 to_asset=main_currency,


Test patch: