coinmarketcap

How to request list of specific coins from coinmarketcap API? Trying to access one ranked over 5000


Right now the way I have it set up it pulls the from 1-5000, but I don't know how to access coins ranked past 5000. I'm trying to pull the price for GBTC

    'X-CMC_PRO_API_KEY' : KEY,
    'Accepts': 'application/json'
}

params = {
    'start':'1',
    'limit' : '5000',
    'convert' : 'USD'
}

url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
json = requests.get(url, params=params, headers=headers).json()
coins = json['data']

current_price = {}
for coin in coins:
    if coin['symbol'] == 'BTC' or coin['symbol'] == 'ETH' or coin['symbol'] == 'GBTC':
        current_price[coin['symbol']] = coin['quote']['USD']['price']```

Solution

  • If you want to only access a pre-defined list of coins use quotes/latest instead of listings/latest (which gives you all coins), use the "v1/cryptocurrency/quotes/latest" (check https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyQuotesLatest)