QuantConnect
Binance Crypto Future Margin Rate Data
Introduction
The Binance Crypto Future Margin Rate Data by QuantConnect is for crypto-currency futures margin interest data points. The data covers 236 Cryptocurrency pairs, starts in August 2020, and is delivered on a daily update frequency. This dataset is created by downloading data using Binance API.
This dataset is an important companion to the Binance Crypto Future Price Data dataset because it contains information on margin interest data to model margin costs.
For more information about the Binance Crypto Future Margin Rate Data dataset, including CLI commands and pricing, see the dataset listing.
About the Provider
QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.
Getting Started
The following snippet demonstrates how to request data from the Binance Crypto Future Margin Rate dataset:
def Initialize(self) -> None: self.SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin) self.SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin) self.crypto_future_symbol = self.AddCryptoFuture("BTCBUSD", Resolution.Minute).Symbol
private Symbol _cryptoFutureSymbol; public override void Initialize { SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin); SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin); // perpetual futures does not have a filter function _cryptoFutureSymbol = AddCryptoFuture("BTCBUSD", Resolution.Minute).Symbol; }
The Binance Crypto Future Margin Rate data is added to your algorithm along with the market data when you add a crypto future subscription.
Requesting Data
To add Binance Crypto Future Margin Rate data to your algorithm, call the AddCryptoFuture method. Save a reference to the Crypto Future Symbol so you can access the data later in your algorithm.
class CoinAPIDataAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.SetStartDate(2020, 6, 1) self.SetEndDate(2021, 6, 1) # Set Account Currency to Binance Stable Coin for USD self.SetAccountCurrency("BUSD") self.SetCash(100000) self.SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin) self.SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin) crypto_future = self.AddCryptoFuture("BTCBUSD", Resolution.Minute) # perpetual futures does not have a filter function self.symbol = crypto_future.Symbol
namespace QuantConnect { public class CoinAPIDataAlgorithm : QCAlgorithm { private Symbol _symbol ; public override void Initialize() { SetStartDate(2020, 6, 1); SetEndDate(2021, 6, 1); // Set Account Currency to Binance Stable Coin for USD SetAccountCurrency("BUSD"); SetCash(100000); SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin); SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin); var cryptoFuture = AddCryptoFuture("BTCBUSD", Resolution.Minute); // perpetual futures does not have a filter function _symbol = cryptoFuture.Symbol; } } }
For more information about creating Crypto Future subscriptions, see Requesting Data.
Accessing Data
To get the current Binance Crypto Margin Rate data, index the MarginInterestRates property of the current Slice with the Crypto Future Symbol. Slice objects deliver unique events to your algorithm as they happen, but the Slice may not contain data for your security 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 self.symbol in slice.MarginInterestRates: interest_rate = slice.MarginInterestRates[self.symbol].InterestRate self.Log(f"{self.symbol} close at {slice.Time}: {interest_rate}")
public override void OnData(Slice slice) { if (slice.MarginInterestRates.ContainsKey(_symbol)) { var interestRate = slice.MarginInterestRates[_symbol].InterestRate; Log($"{_symbol} price at {slice.Time}: {interestRate}"); } }
You can also iterate through all of the data objects in the current Slice.
def OnData(self, slice: Slice) -> None: for symbol, margin_interest_rate in slice.MarginInterestRates.items(): interest_rate = margin_interest_rate.InterestRate self.Log(f"{symbol} close at {slice.Time}: {interest_rate}")
public override void OnData(Slice slice) { foreach (var kvp in slice.MarginInterestRates) { var symbol = kvp.Key; var marginInterestRate = kvp.Value; var interestRate = marginInterestRate.InterestRate; Log($"{symbol} price at {slice.Time}: {interestRate}"); } }
For more information about accessing Crypto Future data, see Handling Data.
Remove Subscriptions
To unsubscribe from a Crypto pair that you added with the AddCrypto method, call the RemoveSecurity method.
self.RemoveSecurity(self.symbol)
RemoveSecurity(_symbol);
The RemoveSecurity method cancels your open orders for the security and liquidates your holdings in the virtual pair.
Example Applications
The Binance Crypto Future Margin Rate dataset enables correct margin cost so you can accurately design strategies for Cryptocurrencies with term structure. Examples include the following strategies:
- Horizontal/Diagonal arbitrage with the underlying cryptocurrencies
- Trade Contango/Backwardation predictions
- Hedge for illiquid cryptocurrencies
Python:
C#: