CoinGecko API – A Complete Guide

9 min read

Get 10-day Free Algo Trading Course

Loading

Last Updated on April 3, 2023

Table of contents:

  1. What is the CoinGecko API?
  2. Why should I use CoinGecko?
  3. Why shouldn’t I use the CoinGecko?
  4. What are the alternatives to using CoinGecko?
  5. What Coding Languages/Clients are available for the CoinGecko API?
  6. How to get started with the the CoinGecko API?
  7. How to obtain price data with the CoinGecko API?
  8. How to get historical data with the CoinGecko API?
  9. What are the the CoinGecko API coin functions?
  10. What is the CoinGecko Trust Score?
  11. What are the CoinGecko API exchange functions?
  12. How to get derivatives using CoinGecko API?
  13. How to get events using the CoinGecko API?
  14. How to import CoinGecko data into Google Sheets?
  15. What widgets does CoinGecko offer?
  16. More about CoinGecko
  17. Full code

What is the CoinGecko API?

The CoinGecko API allows us to retrieve cryptocurrency data such as price, volume, market cap, and exchange data from CoinGecko using code.

We will demonstrate this in this article using Python.

CoinGecko is a data provider and crypto tracking website for live pricings, tickers, historical data, exchanges, events, trading volumes, global markets, coin info, and more.

Link: https://www.coingecko.com

Why should I use CoinGecko?

  • It’s completely free
  • No listing fees – CoinGecko doesn’t charge the listing of coins. Rather, the coins must fulfill some ordinary requirements to be listed.
  • Has multi-language support – Their website supports many languages like English, German, Italian, Spanish, French, and more.
  • Transparency – CoinGecko is open about their coin ranking methodology and workflow.
  • Has mobile apps for iOS and Android
  • Has a Google Chrome Extension
  • Provides crypto updates and news – On the CoinGecko website, we can find a plethora of crypto news, analysis, updates, and research.
  • Has a great amount of data and available coins
  • Has a good ranking algorithm
  • Easy to use and beginner-friendly

Why shouldn’t I use the CoinGecko?

  • GoinGecko isn’t always accurate
  • The API needs more endpoints
  • Doesn’t have official libraries

What are the alternatives to using CoinGecko?

CoinGecko can be replaced with other websites that can be more suitable for you needs. Here are some of them:

  • CoinMarketCap
  • Blockchain wallet
  • Coinsflare
  • Coincodex
  • CryptoCompare
  • Blockfolio
  • Wallmine
  • Coincheckup
  • Cesium
  • Cryptonaut

What Coding Languages/Clients are available for the CoinGecko API?

CoinGecko doesn’t feature official clients but the unofficial ones are the following:

  • NodeJs
  • Go
  • .Net
  • Python
  • Java
  • Kotlin
  • Google Sheets
  • Cryptosheets
  • PHP
  • WordPress Plugin

How to get started with the CoinGecko API?

In order to get started with CoinGecko we will go over to their website that is found on the following link:

https://www.coingecko.com/en

In the top right corner there is a Sing Up button so let’s go ahead and click it. After that, we’ll input our email and password in order to create an account.

A confirmation email will be sent that will take us straight to the CoinGecko website when confirmed.

As we’ll be mostly focusing on the CoinGecko API let’s go ahead and install it with Python.

pip install pycoingecko

In our next chapters we’ll explore the CoinGecko API functions using Python and Google Sheets. If you want to play with it some more you can freely use the CoinGecko API tester that is found on the following link:

https://www.coingecko.com/api/documentations/v3

How to obtain price data with the CoinGecko API?

CoinGecko allows us many ways to obtain price data and we will cover most of them. Firstly, let’s import the CoinGecko library and set the client up.

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

Firstly, we will do a simple API call by asking for the BTC/USD price data:

cg.get_price(ids='bitcoin', vs_currencies='usd')

If you want to obtain the price data for multiple cryptocurrencies for the USD, you can write the following code:

cg.get_price(ids=['bitcoin', 'ethereum','litecoin'], vs_currencies='usd')

We can also ask for the same thing in a different way:

cg.get_price(ids='bitcoin,litecoin,ethereum', vs_currencies='usd')

If we want to update the data with more parameters like the 24 hour change and volume or market cap, we can write the following code:

cg.get_price(ids='bitcoin', vs_currencies='usd', include_market_cap='true', include_24hr_vol='true', include_24hr_change='true', include_last_updated_at='true')

How to get historical data with the CoinGecko API?

For this example we will ask for the Historical Data of Bitcoin for a given date of 10.11.2020. The data will provide us with the market data, market cap, total volume, community data and developer data for the given coin.

Firstly, let’s input the relevant library and create the client:

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

The next step is to pass a call for the historical data endpoint with a specific currency and date.

data = cg.get_coin_history_by_id(id='bitcoin',date='10-11-2020', localization='false')

If we want to obtain historical data with a 24h volume or more we will simply write the following:

cg.get_coin_market_chart_by_id(id='bitcoin',vs_currency='usd',days='3')

If you want to obtain historical data with a precise UNIX timestamp range do the following:

cg.get_coin_market_chart_range_by_id(id='bitcoin',vs_currency='usd',from_timestamp='1605096000',to_timestamp='1605099600')

What are the the CoinGecko API coin functions?

In CoinGecko there are several ways through which we can obtain the coin data. In this example, we’ll cover most of them ranked by the simplest to more complex and informative ones.

Have in mind that some examples will be placed into a data frame for easier observation. For a look into the full code, click here.

How to get a list of coins using the CoinGecko API?

If you want to get a list of available coins using CoinGecko all you need to do is the following:

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
cg.get_coins_list()

In order to list all the supported coins prices, volume, market caps and related data for a specific currency (USD), we can write the following:

cg.get_coins_markets(vs_currency='usd')

If you want to get the current data for a specific coin (BTC) aka spot price data, write the following:

cg.get_coin_by_id(id=’bitcoin’)

Have in mind that this call will give you plethora of information from which you need to discriminate what you exactly need.

In order to get all the tickers for a specific coin (BTC) we can write the following:

cg.get_coin_ticker_by_id(id=’bitcoin’)

How to get status updates for a specific coin using the CoinGecko API?

In order to get status updates for a specific coin (Litecoin) using CoinGecko, write the following:

cg.get_coin_status_updates_by_id(id=’bitcoin’)

How to obtain the trending coins using the CoinGecko API?

In order to obtain the trending coins using CoinGecko, write the following:

cg.get_search_trending()

What is the CoinGecko Trust Score?

In the cryptocurrency market many unregulated exchanges exist that engage in things like wash trading and deviant behavior in order to inflate the trading volume. Thus, the high trading volume can’t be equated to high liquidity of the market.

CoinGecko demised a plan to combat the described behavior by implementing a new ranking algorithm called the “Trust Score”.

Exchanges and trading pairs aren’t anymore ranked by their report but by various metrics that, when pondered, create a holistic Trust Score.

The trust score measures many characteristics of a cryptocurrency and some of them are: trading activity, cybersecurity, web traffic, order book spread and depth, liquidity, technical expertise and more.

If you want to take a deeper look into the methodology behind the Trust Score be sure to visit the following link: https://www.coingecko.com/en/methodology

What are the the CoinGecko API exchange functions?

In CoinGecko there are six ways through which we can obtain the exchange data. In this example, we’ll cover all of them ranked by the simplest to more complex and informative ones.

Firstly, let’s input the relevant library and create the client:

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

How to get the exchange list using the CoinGecko API?

Now, let’s ask CoinGecko to give as a full list of all exchanges it carries.

cg.get_exchanges_list()

As we can see, it gives us details like the trust score, trust score rank and the 24h trading volume. As the information can seem a bit cluttered, let’s make a pandas data frame with the trust score and trust score rank of each exchange.

import pandas as pd
df =pd.DataFrame(data, columns=['name', 'trust_score','trust_score_rank'])
df.set_index('name',inplace=True)
df.head()

Let’s show the first 5 and last 5 exchanges by their trust score:

The next example will show us a list of all supported markets with their id and name. Have in mind that I’ll put them into a pandas DataFrame for a better view:

data_id=cg.get_exchanges_id_name_list()
df_id = pd.DataFrame(data_id, columns=['id', 'name'])
df_id.set_index('id',inplace=True)
df_id.tail()

How to get exchange volume in BTC with the top 100 tickers using the CoinGecko API?

In this example, we’ll ask for a specific exchange that will give us its exchange volume in BTC and the top 100 tickers.

I’ll ask for Binance and arrange it into a pandas data frame while asking for the top and bottom five tickers.

data_binance=cg.get_exchanges_by_id('binance')
df_binance =pd.DataFrame(data_binance['tickers'], columns=['base','target','volume'])
df_binance.head()
df_binance.tail()

Speaking of Binance, you can find an article about their API on our website:

How to get volume chart data with the CoinGecko API?

If we want to get the tickers for a specific exchange (i.e. Coinbase Pro) that are paginated we can write the following:

cg.get_exchanges_tickers_by_id(id='gdax')

I’ll go ahead and arrange it:

data_coinbase_pro=cg.get_exchanges_tickers_by_id(id='gdax')
df_coinbase_pro = pd.DataFrame(data_coinbase_pro['tickers'], columns=['base', 'target','volume'])
df_coinbase_pro.set_index('base',inplace=True)
df_coinbase_pro

How to get Status updates with the CoinGecko API?

The next thing one might look for is obtaining the status updates for a given exchange or volume chart data. Let’s cover these and move to our next chapter:

How to get derivatives using the CoinGecko API?

In CoinGecko there are four ways through which we can obtain the derivates data. In this example, we’ll cover all of them ranked by the simplest to more complex and informative ones.

Have in mind that some examples will be placed into a data frame for easier observation. For a look into the full code, click here.

Let’s obtain a full list of available derivatives:

cg.get_derivatives()

In order to get all of the derivative exchange data we do the following:

cg.get_derivatives_exchanges()

If you want to do the same but with an id do this:

cg.get_derivatives_exchanges_by_id(id=’bitmex’)

To get a list of all derivatives exchanges write the following:

cg.get_derivatives_exchanges_list()

How to get events using the CoinGecko API?

In CoinGecko there are three types of events functions:

  • Basic events function – Obtains events paginated by 100
  • Countries events – Obtains a list of event countries
  • Event types – Obtains a list of event types

Let’s invoke all three of them:

cg.get_events()
data_countries=cg.get_events_countries()
cg.get_events_types()

How to import CoinGecko data into Google Sheets?

CoinGecko can be used in Google Sheets. For this, go to the “Tools” button and select the script editor option. In a newly opened window paste the following code and select the run arrow.

/**
* Imports JSON data to your spreadsheet
* @param url URL of your JSON data as string
* @param xpath simplified xpath as string
* @customfunction
*/
function IMPORTJSON(url,xpath){

try{
// /rates/EUR
var res = UrlFetchApp.fetch(url);
var content = res.getContentText();
var json = JSON.parse(content);

var patharray = xpath.split(".");
//Logger.log(patharray);

for(var i=0;i<patharray.length;i++){
json = json[patharray[i]];
}

//Logger.log(typeof(json));

if(typeof(json) === "undefined"){
return "Node Not Available";
} else if(typeof(json) === "object"){
var tempArr = [];

for(var obj in json){
tempArr.push([obj,json[obj]]);
}
return tempArr;
} else if(typeof(json) !== "object") {
return json;
}
}
catch(err){
return "Error getting data"; 
}
}

Be sure to save the code as “ImportJSON”.

Have in mind that all of the Google Sheet code is built from these blocks:

=ImportJSON (“API URL”,”JsonPath”)

Now, let’s ask for the Bitcoin market data for 11-11-2020.

CoinGecko has created a few Google Sheets templates that you can find and use on the following links:

https://docs.google.com/spreadsheets/d/1XI8e256upCetxeTAmuDe8wKAdoCtyx1DnuH3EyOQRoA/edit#gid=471367795

https://docs.google.com/spreadsheets/d/1XI8e256upCetxeTAmuDe8wKAdoCtyx1DnuH3EyOQRoA/edit#gid=0

https://docs.google.com/spreadsheets/d/1wTTuxXt8n9q7C4NDXqQpI3wpKu1_5bGVmP9Xz0XGSyU/edit#gid=0

What widgets does CoinGecko offer?

CoinGecko has created several interesting widgets that may be of use to its users. The available widgets are the following:

  • Coin Ticker Widget
  • Coin Market Ticker List Widget
  • Coin Price Chart Widget
  • Coin Converter Widget
  • Coin List Widget
  • Coin Price Marquee Widget
  • Coin Price Static Headline Widget
  • Coin Heatmap Widget
  • Coin Compare  Chart Widget
  • Beam Widget
  • Random Coin Widget

Now, allow me to show a few of them:

More about CoinGecko

CoinGecko is also used for ranking cryptocurrencies and their evaluation. The users of their website can track various currencies while having insight into the qualitative data and metrics behind them.

All of this allows us to make better market decisions, better algorithms and also aids the predictive values of our models.

CoinGecko follows a holistic approach when it comes to data aggregation. Currently, CoinGecko is tracking more than 4,750 coins and over 350 exchanges.

Moreover, CoinGecko doesn’t just track coins by measuring their market cap or trading volume, they also include other indicators like project’s code progress, community growth, developer stats, and major events that impact the said coins.

For example, the developer stats are obtained by tracking Gitlab, Github and Bitbucket. All the commits, lines added/deeted, forks, stars and pull requests are being counted for.

On the other hand, community stats are obtained through the tracking of Reddit subs, Twitter followers, Facebook likes/comments and more.

By adding all of this data on-top of the market indicators, CoinGecko manages to get a solid grasp on cryptocurrencies and their overtime predicted change.

As there is much uncertainty in the crypto market, CoinGecko decided to produce quarterly reports about the state of the crypto industry. This allows us to get a better understanding of the underlying movement of the crypto market.

You can check out the quarterly reports here: https://www.coingecko.com/en/publications/reports

CoinGecko also offers an automatic technical analysis tool for each coin.

CoinGecko developers also managed to produce a Google Add-on, Google Chrome Extension, and a mobile app for Android and iOS.

You can download the CoinGecko extension here:

https://chrome.google.com/webstore/detail/coingecko-bitcoin-cryptoc/ofmoicejmilkphppeoekfhbpkleppdlb/related

Full code

Github Link

Igor Radovanovic

One Reply to “CoinGecko API – A Complete Guide”

Comments are closed.