CoinMarketCap API – An Introductory Guide

8 min read

Get 10-day Free Algo Trading Course

Last Updated on June 23, 2021

Table of contents:

  1. What is CoinMarketCap?
  2. Is CoinMarketCap API free?
  3. Why should I use CoinMarketCap?
  4. Why shouldn’t I use the CoinMarketCap?
  5. What are the alternatives to using CoinMarketCap?
  6. What coding languages/clients are available for CoinMarketCap?
  7. How to get started with CoinMarketCap API?
  8. What are the CoinMarketCap API cryptocurrency functions?
  9. What are the CoinMarketCap API exchange functions?
  10. How to get global-metrics using CoinMarketCap API?
  11. How to use the CoinMarketCap API price conversion tool?
  12. How to use partners endpoints in CoinMarketCap API?
  13. How to use CoinMarketCap API in Google Sheets?
  14. More about CoinMarketCap
  15. Full code

What is the CoinMarketCap API?

The CoinMarketCap API is a method to retrieve cryptocurrency data such as price, volume, market cap, and exchange data from CoinMarketCap using code.

We will demonstrate this in this article using Python.

CoinMarketCap is one of the most popular websites used for tracking various cryptocurrencies and obtaining data about them.

Is the CoinMarketCap API free?

The website of the CMC is free to use and the payment is necessary if you want more API functions.

CoinMarketCap API offers a free plan among the other 4 available ones. With the free plan you have access to the 9 market data endpoints:

  • Crypto referential and info logo and logo assets
  • Latest Global Market cap, volume and stats
  • Latest crypto rankings and market quotes
  • Latest crypto and flat currency conversions
  • Partner data access

The STARTUP plan which is 79$ per month, gives you access to 14 market endpoints like historical data and OHLCV. On the other hand the STANDARD and PROFESSIONAL plans give you access to 22 market endpoints.

The number of free CMC API call credits per month is 10k and, with the other paid packages, it can even go up to 3 million or more.

In my opinion, the free plan is at a huge disadvantage compared to the premium plans and there are other websites similar to CMC that give you free access to the endpoints that CMC doesn’t give you. For example, check out our CoinGecko article:

You can see the other available plans from the picture below:

Why should I use CoinMarketCap?

  • Has a free plan
  • Easy to use
  • Informative
  • Tracks a great number of coins and exchanges
  • Has a mobile APP
  • Good API

Why shouldn’t I use the CoinMarketCap?

  • Doesn’t offer enough metrics
  • Isn’t always precise
  • The free plan is severely limited
  • There are some suspicions that CMC favors its parent (Binance) company when it comes to rankings.

What are the alternatives to using CoinMarketCap?

CoinMarketCap can be replaced with other websites that can be more suitable for you needs. Here are some of them:

  • CoinGecko
  • Blockchain wallet
  • Coinsflare
  • Coincodex
  • ViewBase
  • CryptoCompare
  • Blockfolio
  • Wallmine
  • Coincheckup
  • Cesium
  • Cryptonaut

What coding languages/clients are available for CoinMarketCap API?

You can use the CMC API with the following clients:

  • Python
  • Node.js
  • Java
  • PHP
  • C#
  • Go
  • Google Sheets
  • Excel

How to get started with CoinMarketCap API?

In order to get started with the CoinMarketCap API you’ll need to obtain your API key from the following link:

https://coinmarketcap.com/api/

Click on the “GET YOUR API KEY NOW” button and fill up the sign-up information. After you input the relevant data, go over to your email to confirm it. After that, you’ll be taken to the following screen:

As you can see you can easily disable and generate new API keys.

For this tutorial we’ll be using Python, so let’s go over and install the CoinMarketCap library with the following command:

pip install python-coinmarketcap

Have in mind that for most of the next chapters we’ll be using the Jupyter Notebook.

What are the CoinMarketCap API cryptocurrency functions?

The main cryptocurrency endpoints that the CMC offers us are the following:

  • Metadata
  • Historical listings
  • Historical quotes
  • Historical OHLCV
  • CMC ID Map
  • Latest Quotes
  • Latest Listings
  • Latest Market Pairs
  • Latest OHLCV
  • Price performance stats

We’ll cover all of the free plan endpoints in the following chapters.

How to obtain metadata using CoinMarketCap API?

The CMC metadata endpoint returns all the static data that is available for the specified cryptocurrency. The information obtained contains the following: logo, description, website URL, various social links and other.

In order to obtain crypto metadata, we’ll need to import the CMC library and set the client up.

import coinmarketcapapi
cmc = coinmarketcapapi.CoinMarketCapAPI(‘YOUR API KEY’)

Now, let’s make a call that will provide is with the overall data for the Bitcoin cryptocurrency.

data = cmc.cryptocurrency_info(symbol='BTC')
data

How to get the ID Map data with CoinMarketCap API?

The CMC ID Map endpoint obtains a mapping of all currencies with their unique ID’s. Each currency obtained by this endpoint will return standard identifiers as name, symbol and token address.

This endpoint will return crpytocurrencies that have actively tracked markets on supported exchanges by default. The data obtained will also provide the first and last historical data timestamps.

In order to obtain this endpoint, after validating your API Key, do the following:

data_id_map = cmc.cryptocurrency_map()

You may want to make the data more readable by putting it into a pandas data frame. For this, you need to do the following:

import pandas as pd
pd = pd.DataFrame(data_id_map.data, columns =['name','symbol'])
pd.set_index('symbol',inplace=True)
print(pd)

How to get quote data using CoinMarketCap API?

The CMC quote data endpoint returns the latest market quote for a specified cryptocurrency. Moreover, we can convert this data easily into a wanted currency. All we need to do is the following:

data_quote = cmc.cryptocurrency_quotes_latest(symbol='ETH', convert='USD')

If you want to create this into a Pandas data frame you can check out our previous ID Map example.

How to get the latest listing data using CoinMarketCap API?

The CMC latest listings endpoint obtains a list of all active cryptocurrencies with their latest market data.

Like in our previous example, we can convert the data into a preferred currency and rank it differently if we wish to:

data_listing = cmc.cryptocurrency_listings_latest()

How to get Fiat data using CoinMarketCap API?

According to Investopedia, Fiat money is a government-issued currency that is not backed by a physical commodity, such as gold or silver, but rather by the government that issued it.

Firstly, let’s import the relevant library, authenticate the API Key and call our endpoint:

from coinmarketcapapi import CoinMarketCapAPI
cmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')
fiat = cmc.fiat_map()

What are the CoinMarketCap exchange functions API?

The CMC has 7 Exchange options and none of the are available for the basic plan:

  • CMC ID map
  • Metadata
  • Latest Listings
  • Latest Quotes
  • Historical Listings
  • Historical Quotes

How to get global-metrics using CoinMarketCap API?

The CMC global-metrics option has 2 endpoints (historical and latest quotes). The latest quotes one is the only one available for the basic plan so let’s see what it does.

Let’s import he relevant library, authenticate the API Key and call our endpoint:

from coinmarketcapapi import CoinMarketCapAPI
cmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')
global_quote = cmc.globalmetrics_quotes_latest()

How to use the CoinMarketCap API price conversion tool?

The CMC price conversion tool endpoint allows us to convert a specified amount of one cryptocurrency or fiat currency into other currencies by utilizing the latest market rate for each of them.

In this example we’ll convert the BTC currency to USD with a specified amount (20).

Let’s import the relevant library, authenticate the API Key, and call our endpoint:

from coinmarketcapapi import CoinMarketCapAPI
cmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')
tool=cmc.tools_priceconversion(amount=20, symbol='BTC',convert='USD')
tool

How to use partners endpoints in CoinMarketCap API?

The CMC partners endpoints provides us with the FCAS latest listings and quotes.

FCAS stands for The Fundamental Crypto Asset Score, which is a comparative metric used to determine the fundamental health of the crypto project.

In CMC the FCAS endpoint returns a paginated list of FCAS scores for all cryptocurrencies. Let’s import he relevant library, authenticate the API Key and call our endpoints

from coinmarketcapapi import CoinMarketCapAPI
cmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')

FCAS_listing = cmc.partners_flipsidecrypto_fcas_listings_latest()
FCAS_quote = cmc.partners_flipsidecrypto_fcas_quotes_latest(symbol='LTC')

How to use CoinMarketCap API in Google Sheets?

CMC can be easily integrated into Google Sheets. Let us go over the steps together and pull some data into our Google Sheets.

The first thing we need to do is to navigate ourselves to the “Script Editor” menu that is located on the main tool ribbon.

After that, we will start the building process of our script. Firstly, we will make a variable that will pull the data onto a specified sheet.

  var sh1 =SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');

For this example, we will want the latest quotes for the Etherium cryptocurrency that is converted to USD. Let’s code our request:

var requestOptions = {
  method: ‘GET’,
  uri: ‘https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest’,
  qs: {
   start: 1,
   limit: 4000,
   convert: ‘USD’
  },
  headers: {
    ‘X-CMC_PRO_API_KEY’ : ‘YOUR API KEY HERE’
  },
  json: true,
  gzip: true
};

The next step is to create a variable that will access the URL for our API request:

var url=https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=ETH;

The next thing we need to specify is a function that will obtain all the data from the JSON file. So let us create a result variable:

var result= UrlFetchApp.fetch(url, requestOptions);

As the data wouldn’t be useful in the JSON modality we will want to convert it to a string. That being said, out next step is to create a function that will put it into a txt format:

var txt= result.getContentText();

As we need to make the data readable, we will parse the data into different Javascript objects. Let us create another variable that does that:

var d=JSON.parse(txt); 
sh1.getRange(1, 2).setValue(d.data.ETH.quote.USD.price)
}

We’re ready! Let’s save the function and click “Run”. After that, be sure to authorize the function.

After you run the function you should see the data in your second column. I’ll write the word Etherium next to it.

More about CoinMarketCap

CoinMarketCap (CMC) was founded in 2013, and one of the primary tasks that it has set for itself is to add transparency and accountability when it comes to cryptocurrencies and aggregation of the Market data.

Moreover, they offer a holistic approach to data aggregation and state that it is better to overprovide data than to censor or police the information.

Binance, a leading cryptocurrency exchange, has acquired CMC in April of 2020 for $400 million dollars.

Lately, CMC is looking to expand its horizons by adding educational content that could inspire and educate a whole new generation of crypto traders. They decided to call this expansion “CMC Alexandria” which is a reference to the ancient Library of Alexandria.

When it comes to cryptocurrencies, CMC tracks over 7 thousand of them. On the other hand, the number of markets the CMC tracks is over 33 thousand.

CMC also provides three ways of ratings for exchanges:

  • Top 100 By Adjusted Volume – provides volumes of spot trading platforms
  • Top 100 By Reported Volume – provides volumes of all spot trading platforms, no matter what trading models they use
  • By Liquidity – shows all trading platforms by liquidity

CMC has a listings criteria as they deem the quality of their data of utmost importance. They state 3 main principles of data admissibility and they are the following:

  1. Credibility: Is the requester able to substantiate his/her case with supporting evidence?
  2. Verification: Are we able to verify the information from credible and independently verifiable sources?
  3. Methodology: Is this request in accordance with our methodology?

You can read more about the said criteria on the following link:

https://support.coinmarketcap.com/hc/en-us/articles/360043659351-Listings-Criteria

As the CMC provides us with the minute updates of all market data it provides, all data is run through several cleaning and verification algorithms.

One raises a question in what way do these algorithms work and how are the following metrics calculated:

  • Price
  • Volume
  • Market Capitalization
  • Liquidity Score
  • Web Traffic Factor
  • Supply and more.

Good news that the CMC shares the methodology behind the mentioned metrics which can be read on the following link:

https://support.coinmarketcap.com/hc/en-us/sections/360008888252-Metric-Methodologies

The CMC API is a powerful tool that is built on a high-performance RESTful JSON endpoints.

CMC even excludes markets with no fees as there could be malicious activities going behind them. For example, a trader or bot can trade back and forth with himself and make a lot of illusory volume. This volume could deceive others.

We should also have in mind that the CMC doesn’t offer a way to purchase a cryptocurrency. Their main role is to only provide data on it.

CMC offers us a mobile app that is available for iOS & Android. With it, we can track crypto and exchange ranking data, build our portfolio and watchlist, obtain crypto price alerts, get cryptocurrency and blockchain news, and get global stats that are ready for conversion.

CMC also has a blockchain explorer which you can check out on the following link:

https://blockchain.coinmarketcap.com/?utm_source=coinmarketcap&utm_content=footer

Full code

Github link

Igor Radovanovic