Crypto

Requesting Data

Introduction

Request Crypto data in your algorithm to receive a feed of asset prices in the OnData method. For more information about the specific datasets we use for backtests, see the CoinAPI datasets in the Dataset Market.

Create Subscriptions

To create a Crypto subscription, in the Initialize method, call the AddCrypto method. The AddCrypto method returns a Crypto object, which contains a Symbol. Save a reference to the Symbol so you can use it in OnData to access the security data in the Slice.

_symbol = AddCrypto("BTCUSD").Symbol;
self.symbol = self.AddCrypto("BTCUSD").Symbol

The AddCrypto method creates a subscription for a single Crypto asset and adds it to your user-defined universe. To create a dynamic universe of Crypto assets, add a Crypto universe.

To view the supported assets, see the Crypto price datasets in the Dataset Market.

Fungible Assets

Fungible assets are assets that are interchangeable with each other. For example, every Bitcoin is effectively identical to every other Bitcoin. In contrast, non-fungible tokens (NFTs) are non-fungible because each one is unique. An example of an NFT is the Bored Ape Yacht Club collection. LEAN doesn't currently support trading NFTs.

Resolutions

The following table shows the available resolutions and data formats for Crypto subscriptions:

ResolutionTradeBarQuoteBarTrade TickQuote Tick
Tickgreen checkgreen check
Secondgreen checkgreen check
Minutegreen checkgreen check
Hourgreen checkgreen check
Dailygreen checkgreen check

The default resolution for Crypto subscriptions is Resolution.Minute. To change the resolution, pass a resolution argument to the AddCrypto method.

_symbol = AddCrypto("BTCUSD", Resolution.Daily).Symbol;
self.symbol = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol

To create custom resolution periods, see Consolidating Data.

Supported Markets

The following Market enumeration members are available for Crypto:

To set the market for a security, pass a market argument to the AddCrypto method.

_symbol = AddCrypto("BTCUSD", market: Market.GDAX).Symbol;
self.symbol = self.AddCrypto("BTCUSD", market=Market.GDAX).Symbol

The brokerage models have a default market for each asset class. If you set a brokerage model, you may not need to specify the market to use.

Margin and Leverage

LEAN models buying power and margin calls to ensure your algorithm stays within the margin requirements. The amount of leverage available to you depends on the brokerage you use. To change the amount of leverage you can use for a security, pass a leverage argument to the AddCrypto method.

_symbol = AddCrypto("BTCUSD", leverage: 3).Symbol;
self.symbol = self.AddCrypto("BTCUSD", leverage=3).Symbol

For more information about the leverage each brokerage provides, see Brokerages.

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: