rotki / rotki

A portfolio tracking, analytics, accounting and management application that protects your privacy
https://rotki.com
GNU Affero General Public License v3.0
2.79k stars 513 forks source link

NANO cryptocurrency: no price for a given timestamp exception #273

Closed rakanalh closed 5 years ago

rakanalh commented 5 years ago

Problem Definition

Using Rotkehlchen, i was able to import my binance/bittrex accounts and then tried generating a tax report. Apparently, the issue was because NANO was rebranding at some point from Raiblocks (XRB symbol) and cryptocompare does not provide the price of NANO before the rebrand has happened.

The process failed with the following exception:

28/01/2019 12:56:56 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1445587200
28/01/2019 12:56:56 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1452787200
28/01/2019 12:56:57 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1459987200
28/01/2019 12:56:57 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1467187200
28/01/2019 12:56:57 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1474387200
28/01/2019 12:56:58 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1481587200
28/01/2019 12:56:58 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1488787200
28/01/2019 12:56:58 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1495987200
28/01/2019 12:56:59 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1503187200
28/01/2019 12:56:59 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1510387200
28/01/2019 12:56:59 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1517587200
28/01/2019 12:56:59 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1524787200
28/01/2019 12:57:00 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1531987200
28/01/2019 12:57:01 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1539187200
28/01/2019 12:57:01 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1546387200
28/01/2019 12:57:01 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for hourly historical price from_asset=NANO, to_asset=BTC, cryptocompare_hourquerylimit=2000, end_date=1553587200
28/01/2019 12:57:02 CET -- INFO:rotkehlchen.history:Updating price history cache filename=/home/rakan/.rotkehlchen/price_history_NANO_BTC.json, from_asset=NANO, to_asset=BTC
28/01/2019 12:57:02 CET -- INFO:rotkehlchen.history:Writting history file filepath=/home/rakan/.rotkehlchen/price_history_NANO_BTC.json, start_time=1438387200, end_time=1548676616
28/01/2019 12:57:02 CET -- DEBUG:rotkehlchen.history:Coudn't find historical price from NANO to BTC. Attempting to get daily price...
28/01/2019 12:57:02 CET -- DEBUG:rotkehlchen.history:Querying cryptocompare for daily historical price from_asset=NANO, to_asset=BTC, timestamp=1524605511
28/01/2019 12:57:02 CET -- ERROR:rotkehlchen.server:Greenlet for task 4 dies with exception: Unable to query a historical price for "NANO" to "BTC" at 24/04/2018, 21:31:51.
Exception Name: <class 'rotkehlchen.history.NoPriceForGivenTimestamp'>
Exception Info: Unable to query a historical price for "NANO" to "BTC" at 24/04/2018, 21:31:51
Traceback:
   File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/server.py", line 118, in _query_async
    result = getattr(self, command)(**kwargs)
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/server.py", line 231, in process_trade_history
    result, error_or_empty = self.rotkehlchen.process_history(start_ts, end_ts)
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/rotkehlchen.py", line 494, in process_history
    eth_transactions,
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/accounting/accountant.py", line 348, in process_history
    ) = self.process_action(action, end_ts, prev_time, count)
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/accounting/accountant.py", line 486, in process_action
    fee_in_profit_currency=self.get_fee_in_profit_currency(trade),
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/accounting/accountant.py", line 186, in get_fee_in_profit_currency
    trade.timestamp,
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/accounting/accountant.py", line 166, in query_historical_price
    price = self.price_historian.query_historical_price(from_asset, to_asset, timestamp)
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/history.py", line 510, in query_historical_price
    asset_btc_price = self.query_historical_price(from_asset, 'BTC', timestamp)
  File "/home/rakan/Code/Python/rotkehlchen/rotkehlchen/history.py", line 567, in query_historical_price
    tsToDate(timestamp, formatstr='%d/%m/%Y, %H:%M:%S'),

Potential solution is to fallback to requesting XRB's price before the time of the rebrand.

Rotkehlchen also logs debug information to the rotkehlchen.log file. Please attach it to the issue as it may help us find the source of the issue faster.

System Description

Running Rotkehlchen from source. Commit: c0b8d42fce8a8833014867db3df8487c5e7d15c3

LefterisJP commented 5 years ago

As we discussed offline this is due to cryptocompare not having a price for the requested timestamp for NANO. It seems that NANO used to be XRB and that cryptocompare treats them as 2 different coins.

There is prices for a historical period for XRB and then when it rebranded there are only prices for NANO and not for XRB.

So the solution to this is to handle known rebrandings like this in a way that will guarantee a correct price will always be returned.

LefterisJP commented 5 years ago

Was fixed by https://github.com/rotkehlchenio/rotkehlchen/pull/281. Thank you @rakanalh