CoinGecko

Crypto Market Cap

Introduction

The Crypto Market Cap dataset by CoinGecko tracks the market cap of cryptocurrencies. The data covers 620 cryptocurrencies that are supported by QuantConnect, starts in 28 April 2013, and is delivered on a daily frequency. This dataset is created by scraping CoinGecko's Market Chart.

For more information about the Crypto Market Cap dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

CoinGecko was founded in 2014 by TM Lee (CEO) and Bobby Ong (COO) with the mission to democratize the access of crypto data and empower users with actionable insights. We also deep dive into the crypto space to deliver valuable insights to our users through our cryptocurrency reports, as well as our publications, newsletter, and more.

Getting Started

The following snippet demonstrates how to request data from the CoinGecko Crypto Market Cap dataset:

self.btc = self.add_data(CoinGecko, "BTC").symbol
self._universe = self.add_universe(CoinGeckoUniverse, self.universe_selection)
_symbol = AddData<CoinGecko>("BTC").Symbol;
_universe = AddUniverse(CoinGeckoUniverse, UniverseSelection)

Data Summary

The following table describes the dataset properties:

PropertyValue
Start Date28 April 2013
Asset Coverage620 cryptocurrencies
ResolutionDaily
TimezoneUTC

Example Applications

The CoinGecko Crypto Market Cap dataset provide information on the size of the crypto coin and can be used to compare the size of one coin to another. Examples include the following strategies:

  • Construct a major crypto index fund.
  • Invest on the cryptos with the fastest growth in market size.
  • Red flag stop when there might be a crypto bank run.

Data Point Attributes

The Crypto Market Cap dataset provides CoinGecko and CoinGeckoUniverse objects.

CoinGecko Attributes

CoinGecko objects have the following attributes:

CoinGeckoUniverse Attributes

CoinGeckoUniverse objects have the following attributes:

Supported Assets

The following table shows the available Cryptocurrencies:

Requesting Data

To add CoinGecko Crypto Market Cap data to your algorithm, call the AddDataadd_data method. Save a reference to the dataset Symbol so you can access the data later in your algorithm.

from Algorithm import *

class CoinGeckoMarketCapDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self.btcusd = self.add_crypto("BTCUSD", Resolution.DAILY).symbol
        self.dataset_symbol = self.add_data(CoinGecko, "BTC").symbol
using QuantConnect.DataSource;

namespace QuantConnect.Algorithm.CSharp.AltData
{
    public class CoinGeckoMarketCapDataAlgorithm: QCAlgorithm
    {
        private Symbol _symbol, _datasetSymbol;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2020, 6, 1);
            SetCash(100000);

            _symbol = AddCrypto("BTCUSD", Resolution.Daily).Symbol;
            _datasetSymbol = AddData<CoinGecko>("BTC").Symbol;
        }
    }
}

Accessing Data

To get the current Crypto Market Cap data, index the current Slice with the dataset Symbol. Slice objects deliver unique events to your algorithm as they happen, but the Slice may not contain data for your dataset at every time step. To avoid issues, check if the Slice contains the data you want before you index it.

def on_data(self, slice: Slice) -> None:
    if slice.contains_key(self.dataset_symbol):
        data_point = slice[self.dataset_symbol]
        self.log(f"{self.dataset_symbol} market cap::volume at {slice.time}: {data_point.market_cap}::{data_point.volume}")
public override void OnData(Slice slice)
{
    if (slice.ContainsKey(_datasetSymbol))
    {
        var dataPoint = slice[_datasetSymbol];
        Log($"{_datasetSymbol} market cap::volume at {slice.Time}: {dataPoint.MarketCap}::{dataPoint.Volume}");
    }
}

To iterate through all of the dataset objects in the current Slice, call the Getget method.

def on_data(self, slice: Slice) -> None:
    for dataset_symbol, data_point in slice.get(CoinGecko).items():
        self.log(f"{dataset_symbol} market cap::volume at {slice.time}: {data_point.market_cap}::{data_point.volume}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Get<CoinGecko>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} market cap::volume at {slice.Time}: {dataPoint.MarketCap}::{dataPoint.Volume}");
    }
}

Historical Data

To get historical CoinGecko Crypto Market Cap data, call the Historyhistory method with the dataset Symbol. If there is no data in the period you request, the history result is empty.

# DataFrame
history_df = self.history(self.dataset_symbol, 100, Resolution.DAILY)

# Dataset objects
history_bars = self.history[CoinGecko](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<CoinGecko>(_datasetSymbol, 100, Resolution.Daily);

For more information about historical data, see History Requests.

Universe Selection

To select a dynamic universe of Cryptos based on CoinGecko Crypto Market Cap data, call the AddUniverseadd_universe method with the CoinGeckoUniverse class and a selection function. Note that the filtered output is a list of names of the coins. If corresponding tradable crypto pairs are preferred, call CreateSymbol(market, quoteCurrency)create_symbol(market, quoteCurrency) method for each output item.

def initialize(self) -> None:
    self._universe = self.add_universe(CoinGeckoUniverse, self.universe_selection)

def universe_selection(self, data: List[CoinGeckoUniverse]) -> List[Symbol]:
    for datum in data:
        self.debug(f'{datum.coin},{datum.market_cap},{datum.price}')

    # define our selection criteria
    selected = sorted(data, key=lambda x: x.market_cap, reverse=True)[:3]
            
    # Use the CreateSymbol method to generate the Symbol object for
    # the desired market (Coinbase) and quote currency (e.g. USD)
    return [x.create_symbol(Market.COINBASE, "USD") for x in selected]
private Universe _universe;
public override void Initialize()
{
    _universe = AddUniverse<CoinGecko>(data =>
    {
        foreach (var datum in data.OfType<CoinGecko>())
        {
            Debug($"{datum.Coin},{datum.MarketCap},{datum.Price}");
        }

        // define our selection criteria
        // Use the CreateSymbol method to generate the Symbol object for
        // the desired market (Coinbase) and quote currency (e.g. USD)
        return (from d in data.OfType<CoinGeckoUniverse>()
            orderby d.MarketCap descending
            select d.CreateSymbol(Market.Coinbase, "USD")).Take(3);
    });
}

For more information about dynamic universes, see Universes.

Universe History

You can get historical universe data in an algorithm and in the Research Environment.

Historical Universe Data in Algorithms

To get historical universe data in an algorithm, call the Historyhistory method with the Universe object and the lookback period. If there is no data in the period you request, the history result is empty.

var universeHistory = History(_universe, 30, Resolution.Daily);
foreach (var coins in universeHistory)
{
    foreach (CoinGecko coin in coins)
    {
        Log($"{coin.Symbol.Value} market cap at {coin.EndTime}: {coin.MarketCap}");
    }
}
universe_history = self.history(self.universe, 30, Resolution.DAILY)
for (_, time), coins in universe_history.items():
    for coin in coins:
        self.log(f"{coin.symbol.value} market cap at {coin.end_time}: {coin.market_cap}")

Historical Universe Data in Research

To get historical universe data in research, call the UniverseHistoryuniverse_history method with the Universe object, a start date, and an end date. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.

var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time);
foreach (var coins in universeHistory)
{
    foreach (CoinGecko coin in coins)
    {
        Console.WriteLine($"{coin.Symbol.Value} market cap at {coin.EndTime}: {coin.MarketCap}");
    }
}
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (_, time), coins in universe_history.items():
    for coin in coins:
        print(f"{coin.symbol.value} market cap at {coin.end_time}: {coin.market_cap}")

You can call the Historyhistory method in Research.

Remove Subscriptions

To remove your subscription to CoinGecko Crypto Market Cap data, call the RemoveSecurityremove_security method.

self.remove_security(self.dataset_symbol)
RemoveSecurity(_datasetSymbol);

Example Applications

The CoinGecko Crypto Market Cap dataset provide information on the size of the crypto coin and can be used to compare the size of one coin to another. Examples include the following strategies:

  • Construct a major crypto index fund.
  • Invest on the cryptos with the fastest growth in market size.
  • Red flag stop when there might be a crypto bank run.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: