0

I have tested this and has implemented it into my High charts javascript file. The caveat is that when I reload the page twice it will crash due to an error.

@app.route('/') def cryptodashboard():
    # Get historical price data for Bitcoin, Ethereum, and Ripple

        btc_data = requests.get(
            'https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=365').json()['prices']
        eth_data = requests.get(
            'https://api.coingecko.com/api/v3/coins/ethereum/market_chart?vs_currency=usd&days=365').json()['prices']
        xrp_data = requests.get(
            'https://api.coingecko.com/api/v3/coins/ripple/market_chart?vs_currency=usd&days=365').json()['prices']

        # Get live data for Bitcoin, Ethereum, and Ripple
        btc_live = requests.get(
            'https://api.coingecko.com/api/v3/coins/bitcoin').json()
        eth_live = requests.get(
            'https://api.coingecko.com/api/v3/coins/ethereum').json()
        xrp_live = requests.get(
            'https://api.coingecko.com/api/v3/coins/ripple').json()

        # Get market cap data for Bitcoin, Ethereum, and Ripple
        btc_market_cap = btc_live['market_data']['market_cap']['usd']
        eth_market_cap = eth_live['market_data']['market_cap']['usd']
        xrp_market_cap = xrp_live['market_data']['market_cap']['usd']
        return render_template('index.html', btc_data=(btc_data), eth_data=(eth_data), xrp_data=(xrp_data), btc_live=(btc_live), eth_live=(eth_live), xrp_live=(xrp_live), btc_market_cap=(btc_market_cap), eth_market_cap=(eth_market_cap), xrp_market_cap=(xrp_market_cap))

This is the error in the Flask Debugger, KeyError: 'prices'.

When I look at the website https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=365 it tells me that I have reached the API limit hence it is not able to show the price array. What I have done is try to change the days=365 in the API to days=2 but the problem still persists.

Please advise me how to fix this problem.

  • You did not post the error message, but most likely you are using the free API plan(?) and you have reached the maximum number of requests per minute. Does the error message say, that you have exceeded the _Rate Limit_? – MSpiller Jan 19 '23 at 10:04
  • It does not show in the Flask debugger but yes it does say that upon visiting that link to check why is it not retrieving the prices. – noobcodersan Jan 19 '23 at 10:09
  • So you either have to throttle your calls to less than 10 calls per minute or pay for using the API. – MSpiller Jan 19 '23 at 10:11

0 Answers0