0

I am working with Python and when I recall the price of all the coins available pretty often I get an error that I cannot filter "[ERROR] There is no data for the symbol XXX"

The code is as follows:

import requests
import datetime
import cryptocompare
import datetime
coin_list = cryptocompare.get_coin_list(format=False)
date_today = datetime.datetime.now()
for coin, data in coin_list.items():
        nowprice = cryptocompare.get_historical_price(coin, 'USD', date_today)
        print (nowprice)

Why I am getting this error? Is there a way to avoid it? And how can I filter the error so it doesn't show on the screen?

Thanks!!!

Gonzalo
  • 189
  • 1
  • 2
  • 15

1 Answers1

1

This is because the API you are using (https://www.cryptocompare.com/api/) doesn't have historical information for some of the currencies E.g. https://www.cryptocompare.com/coins/nvst/overview. There's nothing you can do about this other than ignore those currencies.

You'll have to edit cryptocompare.py (https://stackoverflow.com/a/12950101/5270506) and change the query_cryptocompare function to:

def query_cryptocompare(url,errorCheck=True):
    try:
        response = requests.get(url).json()
    except Exception as e:
        print('Error getting coin information. %s' % str(e))
        return None
    if errorCheck and 'Response' in response.keys():
        if "There is no data for the symbol" not in response['Message']:
            print('[ERROR] %s' % response['Message'])
        return None
    return response
Farhan.K
  • 3,425
  • 2
  • 15
  • 26