CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (2024)

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.

Link: https://coinmarketcap.com

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:

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (1)

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:

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (2)

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
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (3)

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

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 coinmarketcapapicmc = 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
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (4)

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()
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (5)

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 pdpd = pd.DataFrame(data_id_map.data, columns =['name','symbol'])pd.set_index('symbol',inplace=True)print(pd)
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (6)

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 CoinMarketCapAPIcmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')fiat = cmc.fiat_map()
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (7)

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 CoinMarketCapAPIcmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')tool=cmc.tools_priceconversion(amount=20, symbol='BTC',convert='USD')tool
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (8)

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 CoinMarketCapAPIcmc = CoinMarketCapAPI('b44c1fd8-1c05-45b9-8df7-380a409f9b69')FCAS_listing = cmc.partners_flipsidecrypto_fcas_listings_latest()FCAS_quote = cmc.partners_flipsidecrypto_fcas_quotes_latest(symbol='LTC')
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (9)

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.

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (10)

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)}
CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (11)

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

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (12)

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

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (13)

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.

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (14)

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.

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (15)

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

CoinMarketCap API - An Introductory Guide - AlgoTrading101 Blog (2024)
Top Articles
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 5361

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.