Profile picture

Co-founder @ RMOTR

Coinmarketcap Live API Docs

Last updated: December 10th, 20182018-12-10Project preview

Coinmarketcap has a nicely documented and broad API with multiple endpoints available. It has a free tier (10K requests per month), but the number of endpoints available for the free tier is incredibly limited. Only some summary values.

Nevertheless, here are those methods with examples for you to use:

In [8]:
import os

import requests
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

As we've done with other services, you must get a free API Key in order to query the API. To get the key you'll have to sign up in this page. Once you've received your Key, set it as an environment variable or replace it below:

In [4]:
API_KEY = os.environ.get('COINMARKETCAP_KEY', 'YOUR-API-KEY')  # Replace with your key
In [5]:
assert API_KEY != 'YOUR-API-KEY'
In [7]:
headers = {
    'X-CMC_PRO_API_KEY': API_KEY
}
In [6]:
API_ENDPOINT = 'https://pro.coinmarketcap.com/v1/'

Endpoints

Here are the most important endpoints exposed by Coinamarketcap with some examples included.

/cryptocurrency/info: Metadata about cryptos

Provides some info for the requested cryptos. From this endpoint you can get the ID given by coinmarketcap to each crypto.

In [25]:
resp = requests.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/info', headers=headers, params={
    'symbol': 'BTC,LTC,ETH'
})
In [26]:
resp
Out[26]:
<Response [200]>
In [28]:
doc = resp.json()
In [29]:
doc['status']
Out[29]:
{'timestamp': '2018-12-09T21:46:10.546Z',
 'error_code': 0,
 'error_message': None,
 'elapsed': 4,
 'credit_count': 1}
In [37]:
doc['data'].keys()
Out[37]:
dict_keys(['BTC', 'ETH', 'LTC'])
In [38]:
doc['data']['BTC']
Out[38]:
{'urls': {'website': ['https://bitcoin.org/'],
  'twitter': [],
  'reddit': ['https://reddit.com/r/bitcoin'],
  'message_board': ['https://bitcointalk.org'],
  'announcement': [],
  'chat': [],
  'explorer': ['https://blockchain.info/',
   'https://live.blockcypher.com/btc/',
   'https://blockchair.com/bitcoin/blocks'],
  'source_code': ['https://github.com/bitcoin/']},
 'logo': 'https://s2.coinmarketcap.com/static/img/coins/64x64/1.png',
 'id': 1,
 'name': 'Bitcoin',
 'symbol': 'BTC',
 'slug': 'bitcoin',
 'date_added': '2013-04-28T00:00:00.000Z',
 'tags': ['mineable'],
 'platform': None,
 'category': 'coin'}
In [35]:
pd.DataFrame.from_dict(doc['data'], orient='index')
Out[35]:
urls logo id name symbol slug date_added tags platform category
BTC {'website': ['https://bitcoin.org/'], 'twitter... https://s2.coinmarketcap.com/static/img/coins/... 1 Bitcoin BTC bitcoin 2013-04-28T00:00:00.000Z [mineable] None coin
ETH {'website': ['https://www.ethereum.org/'], 'tw... https://s2.coinmarketcap.com/static/img/coins/... 1027 Ethereum ETH ethereum 2015-08-07T00:00:00.000Z [mineable] None coin
LTC {'website': ['https://litecoin.com'], 'twitter... https://s2.coinmarketcap.com/static/img/coins/... 2 Litecoin LTC litecoin 2013-04-28T00:00:00.000Z [mineable] None coin

/cryptocurrency/listing/latest: Market data

This endpoint provides a "summary" of the current market for each crypto. It's not possible to filter per-crypto, it returns a paginated list to scan. You can provide pagination parameters like start and limit (default 100) along with a "type" filter to get info about tokens, coins or just all listings (default).

In [44]:
resp = requests.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', headers=headers, params={
    'start': 1,
    'limit': 3,
    'convert': 'USD'
})
In [45]:
resp
Out[45]:
<Response [200]>
In [46]:
doc = resp.json()
In [47]:
doc['status']
Out[47]:
{'timestamp': '2018-12-09T22:20:36.247Z',
 'error_code': 0,
 'error_message': None,
 'elapsed': 5,
 'credit_count': 1}

Using a pandas DataFrame:

In [48]:
df = pd.DataFrame.from_dict(doc['data'])
df.set_index('symbol', inplace=True)
df['price'] = df['quote'].apply(lambda dt: dt['USD']['price'])
df['market cap'] = df['price'] * df['circulating_supply']
df[['id', 'name', 'price', 'market cap', 'circulating_supply']]
Out[48]:
id name price market cap circulating_supply
symbol
BTC 1 Bitcoin 3598.831256 6.267333e+10 1.741491e+07
XRP 52 XRP 0.312750 1.279990e+10 4.092696e+10
ETH 1027 Ethereum 94.738807 9.824471e+09 1.037006e+08

Using the cryptocurrency_type filter to get only tokens:

In [39]:
resp = requests.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', headers=headers, params={
    'start': 1,
    'limit': 3,
    'convert': 'USD',
    'cryptocurrency_type': 'tokens'
})
In [40]:
resp
Out[40]:
<Response [200]>
In [41]:
doc = resp.json()
In [42]:
doc['status']
Out[42]:
{'timestamp': '2018-12-09T22:19:50.126Z',
 'error_code': 0,
 'error_message': None,
 'elapsed': 5,
 'credit_count': 1}
In [43]:
df = pd.DataFrame.from_dict(doc['data'])
df.set_index('symbol', inplace=True)
df['price'] = df['quote'].apply(lambda dt: dt['USD']['price'])
df['market cap'] = df['price'] * df['circulating_supply']
df[['id', 'name', 'price', 'market cap', 'circulating_supply']]
Out[43]:
id name price market cap circulating_supply
symbol
USDT 825 Tether 1.017075 1.888120e+09 1.856422e+09
BNB 1839 Binance Coin 4.805213 6.285185e+08 1.307993e+08
MKR 1518 Maker 350.195856 2.550223e+08 7.282278e+05

Quotes

/cryptocurrency/quotes/latest: Market data for symbols

This endpoint is similar to /listing, but let's you filter by the specified symbol:

In [58]:
resp = requests.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest', headers=headers, params={
    'symbol': 'BTC,ETH,LTC',
    'convert': 'USD'
})
In [59]:
resp
Out[59]:
<Response [200]>
In [60]:
doc = resp.json()
In [61]:
doc['status']
Out[61]:
{'timestamp': '2018-12-09T22:23:31.412Z',
 'error_code': 0,
 'error_message': None,
 'elapsed': 21,
 'credit_count': 1}
In [62]:
df = pd.DataFrame.from_dict(doc['data'], orient='index')
df.set_index('symbol', inplace=True)
df['price'] = df['quote'].apply(lambda dt: dt['USD']['price'])
df['market cap'] = df['price'] * df['circulating_supply']
df[['id', 'name', 'price', 'market cap', 'circulating_supply']]
Out[62]:
id name price market cap circulating_supply
symbol
BTC 1 Bitcoin 3598.741996 6.267178e+10 1.741491e+07
ETH 1027 Ethereum 94.762166 9.826893e+09 1.037006e+08
LTC 2 Litecoin 25.933379 1.543077e+09 5.950159e+07
Notebooks AI
Notebooks AI Profile20060