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.
Requesting Data
To add CoinGecko Crypto Market Cap data to your algorithm, call the AddData 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.SetStartDate(2019, 1, 1) self.SetEndDate(2020, 6, 1) self.SetCash(100000) self.symbol = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol self.dataset_symbol = self.AddData(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 OnData(self, slice: Slice) -> None: if slice.ContainsKey(self.dataset_symbol): data_point = slice[self.dataset_symbol] self.Log(f"{self.dataset_symbol} market cap::volume at {slice.Time}: {data_point.MarketCap}::{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 Get method.
def OnData(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.MarketCap}::{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 History 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 AddUniverse 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) method for each output item.
def Initialize(self) -> None: self.AddUniverse(CoinGeckoUniverse, "CoinGeckoUniverse", Resolution.Daily, self.UniverseSelection) def UniverseSelection(self, data: List[CoinGeckoUniverse]) -> List[Symbol]: for datum in data: self.Debug(f'{datum.Coin},{datum.MarketCap},{datum.Price}') # define our selection criteria selected = sorted(data, key=lambda x: x.MarketCap, 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.CreateSymbol(Market.GDAX, "USD") for x in selected]
AddUniverse<CoinGeckoUniverse>("CoinGeckoUniverse", Resolution.Daily, data => { foreach (var datum in data) { 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 orderby d.MarketCap descending select d.CreateSymbol(Market.GDAX, "USD")).Take(3); });
For more information about dynamic universes, see Universes.
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.