(My) Overview: Coin Market Cap API

Victor Fernandez
5 min readApr 25, 2022

--

Photo by Emile Perron on Unsplash

The problem:

I want to get information about some specific Cryptocurrencies, without being exposed to so much advertisement and distractive content.

The solution:

Get the information need it from a reputable API and later use it in a python project ( The information can be delivered later by Telegram Bot)

The Implementation:

This will be the initial step to the solution. Later I will write a script to request the information to the API and parse it in the way I want. In the future, I will use some delivery methods like google sheets or a Telegram bot.

There are two main websites I consider trustworthy. Coin Market Cap and Coin Gecko.

This article will explore Coin Market Cap.

Photo by André François McKenzie on Unsplash

Credentials

For CMC, we will need just the API key, and to get this API key:

1. Navigate to https://coinmarketcap.com/api/.
2. Create an account (in case we do not have one already).
3. Get an API key (you will find the link asking you if you want to get the API key).
4. You will be redirected to https://pro.coinmarketcap.com/account.

Coin Market Cap API Dashboard

Remember that CMC provides a different package to work with their API, some endpoints are just for pro members, but you can get along with the free package.

Authentication

You can provide the API key in two ways:

1. Via headers ( X-CMC_PRO_API_KEY )
2. As a parameter in the query string ( string parameter CMC_PRO_API_KEY)

The recommended method is via headers. Honestly, it is the easiest way.
Here is the example provided by CMC:

From the code above, please notice:

1. There is a variable called headers. Here we added the key X-CMC_PRO_API_KEY and the value. This value will be the API key we already generate.
2. the other step is just an API call using requests .

Each plan will have a maximum of daily and monthly calls to the API, each endpoint will have a credit cost.

CMC explains it really well in the session API Key Usage Credits.

Endpoints Overview

Here CMC shows the skill by explaining in detail and few words how the API was designed, here is the main point:

  1. There are 8 endpoints each one will provide some type of information.
  2. Additional to the endpoint will be some patterns. These patterns will match the type of information provided. For example, if you want the latest market price, the pattern needs will include /latest, now if what you want is the historical data the pattern will include /historical.

This table is the same in the documentation.

Endpoints

CMC API Endpoint Lis

Here are a couple of notes:

1. The endpoint I use the most is /cryptocurrency/* it provides more than enough data.
2. The Endpoint /tools/* useful and convenient, if combined with /cryptocurrency/* will give you all the information you need.
3. CMC IDs is a mapping system by CMC for the different currencies and projects, for example, BTC, CMC ID will be 1.

Patterns

Both endpoints cryptocurrency and exchange will provide two ways to access the data, the first one as listing */listing/* which can be filtered and sorted. Second, as ID-based resources with */quotes/* and */market-pairs/* .

Standards and Conventions

Each HTTP request must contain a header with the following information:

  1. Accept: application/json
  2. Accept-Encoding: deflate,gzip

Endpoint Response and Payload Format

The information returned will be under the key data if the call is successful.

The keystatus is almost always present, and it will contain:
1. timestamp when the call was done.
2. credit_count the number of credits used.
3. elapsed the time that took to process the request.
4. if an error is encountered error_code and error_message.

Bellow the link to the Error and Rate limit page:

but here is a quick summary:

  • 400 Bad request.
  • 401 Unauthorized.
  • 402 Payment Required.
  • 403 Forbidden.
  • 429 To Many Request.
  • 500 Internal Service Error.

Date and Time Format

The timestamp follows the format ISO-8601 (2022–04–04T01:40:40Z) or Unix time (1528249600).

The ISO-8601 format will display the date as YYYY-mm-ddThh:mm:ss.mmmZ

  • Z represents the UTC time.
  • The last three ‘m’ represent milliseconds, not all APIs will provide that value.

Best Practice

The documentation provides a series of tips and recommendations, This will make it easier to work with the API. ( also show the dedication of the CMC team)

1. Use CMC ID instead of the Cryptocurrency symbol.
2. Use the right Endpoint for the job. For general consultation use cryptocurrency/listing/latest. For a more selective consultation cryptocurrency/quotes/latest
3. Implement a caching strategy to avoid repetitive calls.

A general description of the Endpoint

The documentation provides more detailed information about each endpoint. Here I present just an overview.

cryptocurrency

It has 17 endpoints

Some Endpoints are not available for the free tiers

- Airdrop and Airdrops
- Listing historical
- listing new
- Trending Gainers & Losers
- Trending Latest
- Trending Most Visit
- Market pairs Laters (v2)
- OHLCV historical
- OHLCV latest (v2)
- Price Performance status (v2)
- Quote historical (v2)

fiat

One Endpoint.

exchange

Information about exchanges.

Contain 7 EndPoints.

Some Endpoints are not available for the free tiers:

- Listing Latest.
- Market Pairs Latest.
- Quote Historical.
- Quote Latest.

global-metrics

Global Aggregated data.

Two Endpoints.

One Endpoint is not available for the Free tier:

- Quote Historical

tools

Convenient utilities including price conversion.

One EndPoint.

Blockchain

General information about the BlockChain

One Endpoint.

This EndPoint is not supported in the free tier.

key

This Endpoint will provide information about the API usage, like credits remaining.

One Endpoint.

Target domain and Request example.

All requests must be targeted to:

https://pro-api.coinmarketcap.com

however, there is a sandbox domain that we can use for testing

https://sandbox-api.coinmarketcap.com

And here is a request example:

Example: Request to CMC API

Response

Final Thoughts

  1. The free tier of the API provides all the information that I need, so i will work with that version.
  2. The endpoint I will use are cryptocurrency and tools .
  3. This is not an official document nor do I speak in behave of coinmarketcap.com, this is just my overview of a great API.

Victor Fernandez

--

--

Victor Fernandez
Victor Fernandez

Written by Victor Fernandez

I’m Victor, I’m a Field Application Engineer for a CCTV manufacturer. I love Raspberry Pi, Python, and Microcontrollers and I write about my personal projects.

No responses yet