Coin Market Cap¶
Coin market cap provides quality information about cryptocurrency and blockchain technologies. As part of their products they have a blog, portfolio management, and API, etc. The coin market cap API provides a RESTful JSON endpoint with the latest information about the prices, airdrops, chain supported, and project information.
Credentials¶
For CMC, we will need just the API key, and to get this API key:
- Navigate to https://coinmarketcap.com/api/
- Create an account ( in case we do not have one already)
- Get an API key (you will find the link asking you if you want to get the API key)
- 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:
- Via headers (
X-CMC_PRO_API_KEY
) - 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:
- 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. - the other step is just an API call using
requests
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 it 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¶
Endpoint Category | Description |
---|---|
/cryptocurrency/* | Endpoints that return data about the cryptocurrencies include price, ranking, etc. |
/exchange/* | Endpoints that return data about the cryptocurrency exchanges |
/global-metrics/* | Endpoints that return aggregate market data such as global market cap and BTC dominance. |
/tools/* | Useful utilities such as cryptocurrency and fiat price conversions. |
/blockchain/* | Endpoints that return block explorer-related data for blockchains. |
/fiat/* | Endpoints that return data around fiats currencies including mapping to CMC IDs. |
/partners/* | Endpoints for convenient access to 3rd party crypto data. |
/key/* | API key administration endpoints to review and manage your usage. |
Here are a couple of notes:
- The endpoint I use the most is
/cryptocurrency/*
it provides more than enough data. - The Endpoint
/tools/*
useful and convenient, if combined with/cryptocurrency/*
will give you all the information you need. - CMC IDs is a mapping system by CMC for the different currencies and projects, for example,
BTC
CMC ID
will be1
.
Patterns¶
End path | End path tab | Description |
---|---|---|
*/latest | latest market data | The latest market quote average from the exchanges |
*/historical | historical market data | OHLCV data or data for charting libraries |
*/info | Metadata | Metadata cryptocurrency exchange URLs or logos |
*/map | ID map | Utility endpoint to get the map for resources to CMC IDs |
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. -
status
key is almost always added to successful and not successful calls, and it will contain:timestamp
when the call was done.credit_count
the number of credits used.elapsed
time that took to process the request.- if and error is encounter
error_code
anderror_message
Bellow the link to the Error and Rate limit page:
but here a quick summary:
HTTP Status code | Description |
---|---|
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).
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)
- Use CMC ID instead of the Cryptocurrency symbol.
- Use the right Endpoint for the job. For general consultation use
cryptocurrency/listing/latest
. For a more selective consultationcryptocurrency/quotes/latest
- 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 - Provide the CMC mapping for CMC ID and cryptocurrency
- /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:
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:
Response