• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Rakuten RapidAPI Blog

The World's Largest API Marketplace

  • Enterprise
    • Product
    • eBooks
    • Contact Us
  • Marketplace
    • Product
    • Sign Up
    • Docs
  • Resources
    • API Blog
    • API Tutorial
    • Developer Showcase
  • EnglishEnglish
    • 日本語日本語
You are here: Home / API Tutorial / API Tutorial: Using CoinMarketCap API to analyze cryptocurrencies market

API Tutorial: Using CoinMarketCap API to analyze cryptocurrencies market

February 22, 2019 By rakuten Leave a Comment

Table of Contents

  • 1 CoinMarketCap API
  • 2 Setup
    • 2.1 Getting the Javascript Code
    • 2.2 Start with Signing Up to Rakuten RapidApi
  • 3 CoinMarketCap API Overview
  • 4 Making sense of the cryptocurrency market
    • 4.1 Listing cryptocurrencies
    • 4.2 Get a cryptocurrency
    • 4.3 Listing all aggregate market metrics
  • 5 That’s It
  • 6 About Rakuten RapidAPI
    • 6.1 Share this:

CoinMarketCap API

CoinMarketCap is a website offering cryptocurrency market capitalizations with many graphs, charts, and other useful data to help you make educated cryptocurrency trading and investment decisions. It offers live, as well as historical data going back as far as 2013.

CoinMarketCap is a popular service, which receives monthly more than 78 Million estimated visits according to Similarweb:

CoinMarketCap API traffic statistics

In this tutorial, we will cover how to leverage the CoinMarketCap API to list cryptocurrencies and get global aggregated market metrics via the CoinMarketCap API using javascript and node.js.

CoinMarketCap cryptocurrency market API with Rakuten RapidAPI

Setup

To get started you’ll need

  1. Javascript editor and npm unirest package that will speed up code writing
  2. Rakuten RapidApi account and the API key that comes with it

Getting the Javascript Code

Rakuten RapidApi got you covered and packaged all the javascript code you need to work with the API in an easy unirest SDK, which is a library to simplify HTTP REST requests and save you time writing code.

Get started by installing the unirest package with the following command:

npm install unirest --save

As soon as that’s done, you can start exploring the API. It’s safe to ignore the npm warn messages at this point if you see any.

Start with Signing Up to Rakuten RapidApi

About Rakuten RapidAPI

Rakuten RapidAPI is the world’s largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!

We’ve also got you covered with free CoinMarketCap API access. You can try it, without leaving the browser, on the CoinMarketCap API page. You’ll need to sign up to get the API keys and make requests to the API. With these keys you’ll be able to make and authenticate the requests, so we will know they come from you.

CoinMarketCap API page with Rakuten rapidAPI

As soon as you sign-in with your account, the view above will be replaced with another view, where you can see your API keys (X-RapidAPI-Key) in the Request Headers section and a ready to copy snippet of code at the right side.

CoinMarketCap API Overview

CoinMarketCap provides through Rakuten RapidAPI 3 endpoints, each of which covers a specific feature that you can use:

  • getCryptocurrenciesList: Endpoint that returns data around cryptocurrencies such as ordered cryptocurrency lists or price and volume data.
  • getCryptocurrency: Endpoints that return data around cryptocurrency exchanges such as ordered exchange lists and market pair data.
  • getGlobalData: Endpoints that return aggregate market data such as global market cap and BTC dominance.

Making sense of the cryptocurrency market

Before we can start trading or investing in the different cryptocurrencies, we need to understand the market, analyze how each currency fluctuates, and determine the best time to make our purchase/sale.

We’re going to tackle this problem by using the CoinMarketCap API to retrieve the relevant market data.

Let’s get started.

Listing cryptocurrencies

The first endpoint we will be covering allows listing the cryptocurrency market data.

These are the parameters we need to set:

Query Params:

start integer The offset of the first item of the page
limit integer The maximum number of items to return for the page
convert string Return price, 24h volume, and market cap in terms of another currency.

Upon successful completion, the CoinMarketCap API returns the following response body which contains a callback key indicating the status of the request, and a contextWrites.to key which is an array of objects each representing a cryptocurrency:

Response body:

{

 "callback": "success",

 "contextWrites": {

     "to": [ // Array of cryptocurrencies

         {

             "id": "bitcoin",

             "name": "Bitcoin",

             "symbol": "BTC",

             "rank": "1",

             "price_usd": "3482.03529556", // Price in USD

             "price_btc": "1.0", // Price in BTC

             "24h_volume_usd": "5936542451.41",

             "market_cap_usd": "60971176217.0", // Market cap in specified currency

             "available_supply": "17510212.0",

             "total_supply": "17510212.0", // Approx. number of coins in existence

             "max_supply": "21000000.0", // Max number of coins to be available

             "percent_change_1h": "0.03", // Percent of change in the last 1h

             "percent_change_24h": "0.76", // Percent of change in the last 24h

             "percent_change_7d": "-2.97", // Percent of change in the last 7 days

             "last_updated": "1548883704"

         },

         ...

     ]

 }

}

Code snippet:

const unirest = require('unirest');

const API_KEY = "YOUR_API_KEY_HERE";

unirest.post("https://CoinMarketCapzakutynskyV1.p.rapidapi.com/getCryptocurrenciesList")

.header("X-RapidAPI-Key", API_KEY)

.header("Content-Type", "application/x-www-form-urlencoded")

.end(function (result) {

 console.log(result.status, result.headers, result.body);

});

 

Get a cryptocurrency

This endpoint allows retrieving the data for one cryptocurrency. In this example, we’re going to retrieve the Bitcoin data, identified by the id bitcoin.

Query Params:

id string The id of the cryptocurrency wanted
convert string Return price, 24h volume, and market cap in terms of another currency.

Upon successful completion, the CoinMarketCap API returns the following response body that contains bitcoin related data:

Response body:

{

 "callback": "success",

 "contextWrites": {

     "to": {

             "id": "bitcoin",

             "name": "Bitcoin",

             "symbol": "BTC",

             "rank": "1",

             "price_usd": "3482.03529556", // Price in USD

             "price_btc": "1.0", // Price in BTC

             "24h_volume_usd": "5936542451.41",

             "market_cap_usd": "60971176217.0", // Market cap in specified currency

             "available_supply": "17510212.0",

             "total_supply": "17510212.0", // Approx. number of coins in existence

             "max_supply": "21000000.0", // Max number of coins to be available

             "percent_change_1h": "0.03", // Percent of change in the last 1h

             "percent_change_24h": "0.76", // Percent of change in the last 24h

             "percent_change_7d": "-2.97", // Percent of change in the last 7 days

             "last_updated": "1548883704"

         }

 }

}

Code snippet:

const unirest = require('unirest');

const API_KEY = "YOUR_API_KEY";

unirest.post("https://CoinMarketCapzakutynskyV1.p.rapidapi.com/getCryptocurrency")

.header("X-RapidAPI-Key", API_KEY)

.header("Content-Type", "application/x-www-form-urlencoded")

.send("id=bitcoin")

.end(function (result) {

console.log(JSON.stringify(result.body, null, 4));

});

 

Listing all aggregate market metrics

This final endpoint allows retrieving global aggregated market metrics.

Query Params:

convert string Comma-separated list of up to 40 currencies to be used for market quotes calculations

Upon successful completion, the CoinMarketCap API returns the following response body:

Response body:

{

 "callback": "success",

 "contextWrites": {

     "to": {

         "total_market_cap_usd": 120743650384, // Total market cap

         "total_24h_volume_usd": 18125459038,  // Total market volume for last 24h

         "bitcoin_percentage_of_market_cap": 52.99, // Percentage of market cap for bitcoin

         "active_currencies": 846, // Number of active currencies

         "active_assets": 1216, // Number of active assets

         "active_markets": 16011, // Number of active markets

         "last_updated": 1549815742 // Last updated timestamp for the global data

     }

 }

}

 

Code snippet:

const unirest = require('unirest');

const API_KEY = "YOUR_API_KEY_HERE";

unirest.post("https://CoinMarketCapzakutynskyV1.p.rapidapi.com/getGlobalData")

.header("X-RapidAPI-Key", API_KEY)

.header("Content-Type", "application/x-www-form-urlencoded")

.end(function (result) {

 console.log(JSON.stringify(result.body, null, 4));

});

 

That’s It

You are ready to start analyzing the cryptocurrencies market and make better trading and investments decisions. Feel free to use the code in your production applications and check out APIs on Rakuten RapidAPI to enhance your application even further.

About Rakuten RapidAPI

pasted image 0 36

Rakuten RapidAPI is the world’s largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!

Check out some of the world’s best APIs including Microsoft, Sendgrid, Crunchbase, and Skyscanner.

Facebook | LinkedIn | Twitter

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)

Filed Under: API Tutorial

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Accelerate tech modernization

To compete in the digital age, Rakuten RapidAPI helps enterprises deploy scalable and flexible IT systems to allow for ongoing experimentation and iteration at speed.

Learn More
Try Rakuten RapidAPI for free
  • Enterprise
  • Marketplace
  • Resources
  • EnglishEnglish

© 2022 Rakuten RapidAPI. All rights reserved.