---
title: "Crypto"
description: "A Crypto universe lets you select a basket of Cryptocurrencies based on CryptoUniverse data."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/universes/crypto
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/universes/crypto.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/12%20Universes/09%20Crypto
modified: 2026-10-29
index: https://www.quantconnect.com/llms.txt
---

# Crypto

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Universes > Crypto

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

A Crypto universe lets you select a basket of Cryptocurrencies based on `CryptoUniverse` data.

## Crypto Universes

To add a universe of Cryptocurrencies, in the `initialize` method, pass a `CryptoUniverse` to the `add_universe` method.

```python
def initialize(self) -> None:
    self.universe_settings.asynchronous = True
    self.universe_settings.resolution = Resolution.DAILY
    self.set_brokerage_model(BrokerageName.COINBASE, AccountType.CASH)

    # Add crypto universe selection
    self._universe = self.add_universe(CryptoUniverse.coinbase(lambda universe_day: [c.symbol for c in universe_day]))
```

The following table shows the helper methods to create Crypto universes for the supported exchanges:

| Brokerage Name | Helper Method | Example |
| --- | --- | --- |
| `BrokerageName.``BINANCE` | `CryptoUniverse.``binance` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/binance-crypto-price-data.md#08-Universe-Selection) |
| `BrokerageName.``BINANCE_US` | `CryptoUniverse.``binance_us` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/binance-us-crypto-price-data.md#08-Universe-Selection) |
| `BrokerageName.``BITFINEX` | `CryptoUniverse.``bitfinex` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/bitfinex-crypto-price-data.md#08-Universe-Selection) |
| `BrokerageName.``BYBIT` | `CryptoUniverse.``bybit` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/bybit-crypto-price-data.md#08-Universe-Selection) |
| `BrokerageName.``COINBASE` | `CryptoUniverse.``coinbase` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/coinbase-crypto-price-data.md#08-Universe-Selection) |
| `BrokerageName.``KRAKEN` | `CryptoUniverse.``kraken` | [Example](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/kraken-crypto-price-data.md#08-Universe-Selection) |

The following table describes the `CryptoUniverse` method arguments:

| Argument | Data Type | Description | Default Value |
| --- | --- | --- | --- |
| `selector` | `Callable[[List[CryptoUniverse]], List[Symbol]]` | A function to select some of the Cryptocurrencies for the universe. |  |
| `universe_settings` | `UniverseSettings` | The [universe settings](https://www.quantconnect.com/docs/v2/writing-algorithms/universes/settings.md). | `None` |

The filter function receives `CryptoUniverse` objects, which represent one of the Cryptocurrencies in the market. The `Symbol` objects that the filter function returns represent the universe constituents. `CryptoUniverse` objects have the following attributes:

*Members of `QuantConnect.DataSource.CryptoUniverse` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.CryptoUniverse&language=python*

To perform thorough filtering on the `CryptoUniverse` objects, define an isolated filter method.

```python
def initialize(self) -> None:
    self.universe_settings.asynchronous = True
    self.universe_settings.resolution = Resolution.DAILY
    self.set_brokerage_model(BrokerageName.COINBASE, AccountType.CASH)

    # Add crypto universe selection
    self._universe = self.add_universe(CryptoUniverse.coinbase(self._universe_filter))

def _universe_filter(self, universe_day):
    # Define the universe selection function
    return [cf.symbol for cf in universe_day if cf.volume >= 100 and cf.volume_in_usd > 10000]
```

## Historical Data

To get historical Cryptocurrency universe data, call the `history` method with the `Universe` object and the lookback period. The return type is a multi-index `pandas.Series` or `pandas.DataFrame` containing `CryptoUniverse` data.

```python
# Get 30 days of history for the Crypto universe.
# DataFrame object:
df_history = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series object:
series_history = self.history(self._universe, 30, Resolution.DAILY)
for (univere_symbol, time), universe_day in history.items():
    for universe_item in universe_day:
        self.log(f"{universe_item.symbol} price at {universe_item.end_time}: {universe_item.close}")
```

For more information about Cryptocurrency data, see [Crypto](https://www.quantconnect.com/docs/v2/research-environment/datasets/crypto.md).

## Alternative Data Universes

An alternative data universe lets you select a basket of Cryptocurrencies based on an alternative dataset that's linked to them. If you use an alternative data universe, you limit your universe to only the securities in the dataset, which avoids unnecessary subscriptions. Currently, only the [Crypto Market Cap](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/coingecko/crypto-market-cap.md#08-Universe-Selection) alternative dataset supports universe selection for Crypto.

## Selection Frequency

Crypto universes run on a daily basis by default. To adjust the selection schedule, see [Schedule](https://www.quantconnect.com/docs/v2/writing-algorithms/universes/settings.md#10-Schedule).

## Live Trading Considerations

In live mode, the pipeline has a 16-hour delay. Your algorithm receives the `CryptoUniverse` objects at around 16:00-16:30 Coordinated Universal Time (UTC) each day, depending on the data processing task.

## Examples

The following examples demonstrate some common Crypto universes.

### Example 1: Highly Liquid Crypto Universe

To fairly compare the liquidity between Crypto pairs, use the `volume_in_usd` property of the `CryptoUniverse` objects during universe selection. The following algorithm selects the 10 Crypto pairs with the greatest USD volume on Bitfinex:

```python
class HighlyLiquidCryptoUniverseAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.add_universe(CryptoUniverse.bitfinex(self._select_assets))

    def _select_assets(self, data):
        selected = sorted(
            [x for x in data if x.volume_in_usd],
            key=lambda x: x.volume_in_usd
        )[-10:]
        return [x.symbol for x in selected]
```

### Example 2: Highly Volatile Crypto Universe

The following algorithm creates a universe of volatile Crypto pairs on Binance by selecting the pairs with the largest trading range in the previous day:

```python
class HighlyVolatileCryptoUniverseAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.add_universe(CryptoUniverse.binance(self._select_assets))

    def _select_assets(self, data):
        selected = sorted(data, key=lambda x: (x.high - x.low) / x.low)[-10:]
        return [x.symbol for x in selected]
```

### Example 3: Large Cap Crypto Universe

The following algorithm uses the [CoinGecko Crypto Market Cap](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/coingecko/crypto-market-cap.md) dataset to create a universe of the largest Crypto pairs on Coinbase. To avoid trading errors, it only selects pairs that have a quote currency that matches your [account currency](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#03-Set-Account-Currency) . At noon each day, it rebalances the portfolio to give equal weight to each coin in the universe.

```python
class LargeCapCryptoUniverseAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        # Set the account currency. USD is already the default value. Change it here if you want.
        self.set_account_currency("USD")
        # Get the pairs that our brokerage supports and have a quote currency that
        # matches your account currency. We need this list in the universe selection function.
        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
        ]
        # Add a universe of Cryptocurrencies.
        self._universe = self.add_universe(CoinGeckoUniverse, 'CoinGeckoUniverse', Resolution.HOUR, self._select_assets)
        # Add a Sheduled Event to rebalance the portfolio.
        self.schedule.on(self.date_rules.every_day(), self.time_rules.at(12, 0), self._rebalance)

    def _select_assets(self, data: List[CoinGecko]) -> List[Symbol]:
        # 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:]
        ]

    def _rebalance(self):
        if not self._universe.selected:
            return
        symbols = [symbol for symbol in self._universe.selected if self.securities[symbol].price]
        # Liquidate coins that are no longer in the universe.
        targets = [PortfolioTarget(symbol, 0) for symbol, holding in self.portfolio.items() if holding.invested and symbol not in symbols]
        # Form an equal weighted portfolio of the coins in the universe.
        targets += [PortfolioTarget(symbol, 0.5/len(symbols)) for symbol in symbols]
        # Place orders to rebalance the portfolio.
        self.set_holdings(targets)
```

### Example 4: Indicator Universe

The following example shows how to select a universe of Crypto pairs based on indicators.

```python
class CryptoIndicatorUniverseSelectionAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        # Add a universe of Crypto pairs based on indicators.
        self._selection_data_by_symbol = {}
        self._universe = self.add_universe(CryptoUniverse.coinbase(self._select_assets))
        # Add a warm-up period to warm up the indicators in the universe selection.
        self.set_warm_up(timedelta(60))

    def _select_assets(self, data):
        # Update the indicator of all Crypto pairs in the universe dataset and
        # get the subset of them that have their indicator ready.
        ready_pairs = [
            c for c in data
            if self._selection_data_by_symbol.setdefault(c.symbol, SelectionData()).update(c)
        ]
        # As Crypto pairs leave the universe dataset, delete their SelectionData objects.
        for symbol in self._selection_data_by_symbol.keys() - {c.symbol for c in data}:
            del self._selection_data_by_symbol[symbol]
        # During warm-up, keep the universe empty.
        if self.is_warming_up:
            return []
        # Select a subset of the Crypto pairs based on their indicators.
        # Example: Pairs trading above their bollinger band with high volume.
        filtered = []
        for c in ready_pairs:
            selection_data = self._selection_data_by_symbol[c.symbol]
            if c.close > selection_data.bb.upper_band.current.value:
                filtered.append(c)
        filtered = sorted(filtered, key=lambda c: self._selection_data_by_symbol[c.symbol].mean_daily_usd_volume)[-10:]
        return [c.symbol for c in filtered]

class SelectionData:

    def __init__(self):
        self.mean_daily_usd_volume = SimpleMovingAverage(30)
        self.bb = BollingerBands(30, 2)

    def update(self, c):
        # Update all the indicators and return true if they are all ready.
        return (
            self.mean_daily_usd_volume.update(c.end_time, c.volume_in_usd) &
            self.bb.update(TradeBar(c.end_time, c.symbol, c.open, c.high, c.low, c.close, c.volume_in_usd))
        )
```
