Introduction to Crypto Data in Algorithms
Requesting cryptocurrency data in your trading algorithm enables you to receive real-time asset price feeds through the OnData or on_data method. This data powers backtesting and live trading strategies. The QuantConnect platform primarily utilizes CoinAPI datasets for crypto backtesting, while live trading leverages its integrated data provider.
👉 Explore advanced crypto trading strategies
Creating Crypto Subscriptions
To establish a cryptocurrency data subscription, follow these steps:
- Initialize Your Algorithm: In the
Initializemethod, callAddCrypto(C#) oradd_crypto(Python). - Reference the Symbol: The method returns a
Cryptoobject containing aSymbolproperty—store this for accessing security data.
_symbol = AddCrypto("BTCUSD").Symbol;self._symbol = self.add_crypto("BTCUSD").symbolKey Features:
- Supports single-asset subscriptions
- Enables dynamic universe creation via Crypto universes
- Comprehensive asset coverage through CoinAPI
Understanding Crypto Asset Types
Fungible vs. Non-Fungible Assets
- Fungible: Interchangeable assets (e.g., Bitcoin)
- Non-Fungible: Unique assets (e.g., NFTs like Bored Ape Yacht Club)
Note: LEAN currently only supports trading fungible crypto assets.
Market Support and Configuration
Available markets include major exchanges like Coinbase. Specify your market preference:
_symbol = AddCrypto("BTCUSD", market: Market.Coinbase).Symbol;self._symbol = self.add_crypto("BTCUSD", market=Market.COINBASE).symbol👉 Master crypto market selection
Data Handling Parameters
Fill Forward
Controls whether missing data points use previous values (enabled by default):
_symbol = AddCrypto("BTCUSD", fillForward: false).Symbol;self._symbol = self.add_crypto("BTCUSD", fill_forward=False).symbolMargin and Leverage
Adjust leverage according to brokerage limits:
_symbol = AddCrypto("BTCUSD", leverage: 3).Symbol;self._symbol = self.add_crypto("BTCUSD", leverage=3).symbolPractical Implementation Example
Binance Algorithm Setup
public class CryptoExampleAlgorithm : QCAlgorithm
{
public override void Initialize()
{
SetBrokerageModel(BrokerageName.Binance, AccountType.Cash);
SetAccountCurrency("USDT", 100000);
AddCrypto("BTCUSDT");
AddCrypto("ETHUSDT");
}
}class CryptoExampleAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_brokerage_model(BrokerageName.BINANCE, AccountType.CASH)
self.set_account_currency("USDT", 100000)
self.add_crypto("BTCUSDT", market=Market.BINANCE)
self.add_crypto("ETHUSDT", market=Market.BINANCE)FAQ Section
What datasets does QuantConnect use for crypto backtesting?
QuantConnect primarily uses CoinAPI datasets for historical crypto data.
How do I handle different quote currencies like USDT?
Set your account currency to match the quote currency (e.g., USDT) to avoid conversion issues.
Can I trade NFTs using QuantConnect?
Currently, LEAN only supports trading fungible crypto assets, not NFTs.
What's the default leverage for crypto trading?
Leverage depends on your brokerage model, typically ranging from 3x to 5x for crypto assets.
How does fill forward affect my trading strategy?
Fill forward prevents gaps in data but may mask true market conditions—disable it for high-frequency strategies.
Where can I find supported crypto assets?
Check the CoinAPI datasets for the full list.
For more advanced crypto trading techniques, visit our comprehensive 👉 crypto trading guide.