Repository: rotki/rotki

Issue:
Since kraken removed ICN we get a crash
## Problem Definition

Kraken [delisted](https://support.kraken.com/hc/en-us/articles/360001423706-Delisting-of-Iconomi-ICN-) ICN and rotkehlchen is not handling this gracefully.

```
Traceback (most recent call last):
  File "/home/lefteris/.virtualenvs/rotkehlchen/bin/zerorpc", line 11, in <module>
    sys.exit(main())
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/cli.py", line 310, in main
    return run_client(args)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/cli.py", line 269, in run_client
    results = client(args.command, *call_args)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/core.py", line 270, in __call__
    return self._process_response(request_event, bufchan, timeout)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/core.py", line 238, in _process_response
    reply_event, self._handle_remote_error)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/patterns.py", line 45, in process_answer
    raise exception
zerorpc.exceptions.RemoteError: Traceback (most recent call last):
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/core.py", line 153, in _async_task
    functor.pattern.process_call(self._context, bufchan, event, functor)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/patterns.py", line 30, in process_call
    result = functor(*req_event.args)
  File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.7/site-packages/zerorpc/decorators.py", line 44, in __call__
    return self._functor(*args, **kargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/server.py", line 238, in query_balances
    result = self.rotkehlchen.query_balances(save_data)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/rotkehlchen.py", line 489, in query_balances
    exchange_balances, msg = getattr(self, exchange).query_balances()
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils.py", line 97, in wrapper
    result = f(wrappingobj, *args)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/kraken.py", line 439, in query_balances
    entry['usd_value'] = v * self.find_fiat_price(k)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/kraken.py", line 401, in find_fiat_price
    'Could not find a BTC tradeable pair in kraken for "{}"'.format(asset)
ValueError: Could not find a BTC tradeable pair in kraken for "XICN"
```

### Task

Solve this


Discussion:

Resolving patch:
diff --git a/rotkehlchen/inquirer.py b/rotkehlchen/inquirer.py
--- a/rotkehlchen/inquirer.py
+++ b/rotkehlchen/inquirer.py
@@ -41,6 +41,41 @@ def world_to_cryptocompare(asset):
     return asset
 
 
+def query_cryptocompare_for_fiat_price(asset: typing.Asset) -> FVal:
+    log.debug('Get usd price from cryptocompare', asset=asset)
+    asset = world_to_cryptocompare(asset)
+    resp = retry_calls(
+        5,
+        'find_usd_price',
+        'requests.get',
+        requests.get,
+        u'https://min-api.cryptocompare.com/data/price?'
+        'fsym={}&tsyms=USD'.format(asset)
+    )
+
+    if resp.status_code != 200:
+        raise RemoteError('Cant reach cryptocompare to get USD value of {}'.format(asset))
+
+    resp = rlk_jsonloads(resp.text)
+
+    # If there is an error in the response skip this token
+    if 'USD' not in resp:
+        error_message = ''
+        if resp['Response'] == 'Error':
+            error_message = resp['Message']
+
+        log.error(
+            'Cryptocompare usd price query failed',
+            asset=asset,
+            error=error_message,
+        )
+        return FVal(0)
+
+    price = FVal(resp['USD'])
+    log.debug('Got usd price from cryptocompare', asset=asset, price=price)
+    return price
+
+
 class Inquirer(object):
     def __init__(self, kraken=None):  # TODO: Add type after fixing cyclic dependency
         self.kraken = kraken
@@ -65,35 +100,4 @@ def find_usd_price(
             log.debug('Get usd price from kraken', asset=asset, price=price)
             return price
 
-        log.debug('Get usd price from cryptocompare', asset=asset)
-        asset = world_to_cryptocompare(asset)
-        resp = retry_calls(
-            5,
-            'find_usd_price',
-            'requests.get',
-            requests.get,
-            u'https://min-api.cryptocompare.com/data/price?'
-            'fsym={}&tsyms=USD'.format(asset)
-        )
-
-        if resp.status_code != 200:
-            raise RemoteError('Cant reach cryptocompare to get USD value of {}'.format(asset))
-
-        resp = rlk_jsonloads(resp.text)
-
-        # If there is an error in the response skip this token
-        if 'USD' not in resp:
-            error_message = ''
-            if resp['Response'] == 'Error':
-                error_message = resp['Message']
-
-            log.error(
-                'Cryptocompare usd price query failed',
-                asset=asset,
-                error=error_message,
-            )
-            return FVal(0)
-
-        price = FVal(resp['USD'])
-        log.debug('Got usd price from cryptocompare', asset=asset, price=price)
-        return price
+        return query_cryptocompare_for_fiat_price(asset)
diff --git a/rotkehlchen/kraken.py b/rotkehlchen/kraken.py
--- a/rotkehlchen/kraken.py
+++ b/rotkehlchen/kraken.py
@@ -16,6 +16,7 @@
 from rotkehlchen.errors import RecoverableRequestError, RemoteError
 from rotkehlchen.exchange import Exchange
 from rotkehlchen.fval import FVal
+from rotkehlchen.inquirer import query_cryptocompare_for_fiat_price
 from rotkehlchen.logging import RotkehlchenLogsAdapter
 from rotkehlchen.order_formatting import AssetMovement, Trade
 from rotkehlchen.utils import (
@@ -386,6 +387,12 @@ def find_fiat_price(self, asset: typing.Asset) -> FVal:
             self.usdprice['USDT'] = price
             return price
 
+        if asset == 'XICN':
+            # ICN has been delisted by kraken at 31/10/2018 and withdrawals
+            # will only last until 31/11/2018. For this period of time there
+            # can be ICN in Kraken -- so use crypto compare for price info
+            return query_cryptocompare_for_fiat_price('ICN')
+
         # TODO: This is pretty ugly. Find a better way to check out kraken pairs
         # without this ugliness.
         pair = asset + 'XXBT'


Test patch: