book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

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:

Select Language:
self.btc = self.add_data(CoinGecko, "BTC").symbol
self._universe = self.add_universe(CoinGeckoUniverse, self.universe_selection)

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.

For more example algorithms, see Examples.

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 add_data method. Save a reference to the dataset Symbol so you can access the data later in your algorithm.

Select Language:
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

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.

Select Language:
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}")

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

Select Language:
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}")

Historical Data

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

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

# Dataset objects
history_bars = self.history[CoinGecko](self.dataset_symbol, 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 add_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 create_symbol(market, quoteCurrency) method for each output item.

Select Language:
class CryptoMarketCapUniverseAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_account_currency("USD") 
        self._market = Market.COINBASE
        self._market_pairs = [
            x.key.symbol 
            for x in self.symbol_properties_database.get_symbol_properties_list(self._market) 
            if x.value.quote_currency == self.account_currency
        ]
        self._universe = self.add_universe(CoinGeckoUniverse, self._select_assets)

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

        # Select the coins that our brokerage supports and have a quote currency that matches
        # our account currency.
        tradable_coins = [d for d in data if d.coin + self.account_currency in self._market_pairs]
        # Select the largest coins and create their Symbol objects.
        return [
            c.create_symbol(self._market, self.account_currency) 
            for c in sorted(tradable_coins, key=lambda x: x.market_cap)[-10:]
        ]

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 history method with the Universe object and the lookback period. If there is no data in the period you request, the history result is empty.

Select Language:
# DataFrame example where the columns are the CoinGeckoUniverse attributes: 
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series example where the values are lists of CoinGeckoUniverse objects: 
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 universe_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.

Select Language:
# DataFrame example where the columns are the CoinGeckoUniverse attributes: 
history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)

# Series example where the values are lists of CoinGeckoUniverse objects: 
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 history method in Research.

Remove Subscriptions

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

Select Language:
self.remove_security(self.dataset_symbol)

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.

For more example algorithms, see Examples.

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: