Crypto
Holdings
Cash vs Margin Brokerage Accounts
Some of the Crypto brokerages integrated into QuantConnect support cash and margin accounts while some only support cash accounts. If you want to short Crypto assets or use leverage, you need a margin account. Follow these steps to view which account types each brokerage supports:
- Open the brokerage guides.
- Click a Crypto brokerage.
- Scroll down to the Account Types section.
Virtual Pairs
All fiat and Crypto currencies are individual assets. When you buy a pair like BTCUSD, you trade USD for BTC. In this case, LEAN removes some USD from your portfolio cashbook and adds some BTC. The virtual pair BTCUSD represents your position in that trade, but the virtual pair doesn't actually exist. It simply represents an open trade. If you call the Liquidate method with the Symbol
symbol
of a virtual pair, the method only liquidates the quantity in your virtual pair. For more information about liquidating Crypto postitions, see Crypto Trades.
Access Cypto Holdings
The CashBook
cash_book
stores the quantity of your Crypto holdings. To access your Crypto holdings, index the CashBook
cash_book
with the currency ticker. The values of the CashBook
dictionary are Cash
objects, which have the following properties:
var btcQuantity = Portfolio.CashBook["BTC"].Amount; var btcValue = Portfolio.CashBook["BTC"].ValueInAccountCurrency;
btc_quantity = self.portfolio.cash_book['BTC'].amount btc_value = self.portfolio.cash_book['BTC'].value_in_account_currency
To access the virtual pair of your Crypto trades, index the Portfolio
portfolio
object with the pair Symbol
symbol
.
var securityHolding = Portfolio[_btcUsdSymbol];
security_holding = self.portfolio[self._btc_usd_symbol]
Stateful Redeployments
When you make a trade inside of a running algorithm, LEAN tracks the virtual position state for you, but it won't survive between deployments. Some brokerages save your virtual pairs, so you can load them into your algorithm when you stop and redeploy it. Depending on the brokerage you select, you may be able to manually add virtual pairs when you deploy live algorithms with the LEAN CLI or cloud deployment wizard.