(My) Overview: Coin Market Cap API
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.
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.
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:
- There are 8 endpoints each one will provide some type of information.
- 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
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:
Accept: application/json
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
- /v1/cryptocurrency/map — CoinMarketCap ID map
- /v1/cryptocurrency/info — Metadata
- /v1/cryptocurrency/listings/latest — Latest listings
- /v1/cryptocurrency/listings/historical — Historical listings
- /v1/cryptocurrency/quotes/latest — Latest quotes
- /v1/cryptocurrency/quotes/historical — Historical quotes
- /v1/cryptocurrency/market-pairs/latest — Latest market pairs
- /v1/cryptocurrency/ohlcv/latest — Latest OHLCV
- /v1/cryptocurrency/ohlcv/historical — Historical OHLCV
- /v1/cryptocurrency/price-performance-stats/latest — Price performance Stats
- /v1/cryptocurrency/categories — Categories
- /v1/cryptocurrency/category — Category
- /v1/cryptocurrency/airdrops — Airdrops
- /v1/cryptocurrency/airdrop — Airdrop
- /v1/cryptocurrency/trending/latest — Trending Latest
- /v1/cryptocurrency/trending/most-visited — Trending Most Visited
- /v1/cryptocurrency/trending/gainers-losers — Trending Gainers & Losers
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.
- /v1/fiat/map — CoinMarketCap ID map
exchange
Information about exchanges.
Contain 7 EndPoints.
- /v1/exchange/map — CoinMarketCap ID map
- /v1/exchange/info — Metadata
- /v1/exchange/listings/latest — Latest listings
- /v1/exchange/quotes/latest — Latest quotes
- /v1/exchange/quotes/historical — Historical quotes
- /v1/exchange/market-pairs/latest — Latest market pairs
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.
- /v1/global-metrics/quotes/latest — Latest global metrics
- /v1/global-metrics/quotes/historical — Historical global metrics
One Endpoint is not available for the Free tier:
- Quote Historical
tools
Convenient utilities including price conversion.
One EndPoint.
- /v1/tools/price-conversion — Price conversion tool
Blockchain
General information about the BlockChain
One Endpoint.
- /v1/blockchain/statistics/latest — Latest statistics
This EndPoint is not supported in the free tier.
key
This Endpoint will provide information about the API usage, like credits remaining.
One Endpoint.
- /v1/key/info — Key Info
Target domain and Request example.
All requests must be targeted to:
however, there is a sandbox domain that we can use for testing
And here is a request example:
Response
Final Thoughts
- The free tier of the API provides all the information that I need, so i will work with that version.
- The endpoint I will use are
cryptocurrency
andtools
. - This is not an official document nor do I speak in behave of coinmarketcap.com, this is just my overview of a great API.