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 348 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.set_brokerage_model(BrokerageName.BINANCE_FUTURES, AccountType.MARGIN)
    self.set_brokerage_model(BrokerageName.BINANCE_COIN_FUTURES, AccountType.MARGIN)

    self.crypto_future_symbol = self.add_crypto_future("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.

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateAugust 2020
Asset Coverage236 Crypto Futures Pairs
Data DensityRegular
ResolutionDaily
TimezoneUTC
Market HoursAlways Open

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

Data Point Attributes

The Binance Crypto Future Margin Rate dataset provides MarginInterestRatesmargin_interest_rates objects with the following attributes:

Supported Assets

The following table shows the available Crypto Future pairs:

Requesting Data

To add Binance Crypto Future Margin Rate data to your algorithm, call the AddCryptoFutureadd_crypto_future 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.set_start_date(2020, 6, 1)
        self.set_end_date(2021, 6, 1)

        # Set Account Currency to Binance Stable Coin for USD
        self.set_account_currency("BUSD")
        self.set_cash(100000)

        self.set_brokerage_model(BrokerageName.BINANCE_FUTURES, AccountType.MARGIN)
        self.set_brokerage_model(BrokerageName.BINANCE_COIN_FUTURES, AccountType.MARGIN)
        
        crypto_future = self.add_crypto_future("BTCBUSD", Resolution.MINUTE)
        # perpetual futures does not have a filter function
        self.btcbusd = 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 MarginInterestRatesmargin_interest_rates 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 on_data(self, slice: Slice) -> None:
    if self.btcbusd in slice.margin_interest_rates:
        interest_rate = slice.margin_interest_rates[self.btcbusd].interest_rate
        self.log(f"{self.btcbusd} 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 on_data(self, slice: Slice) -> None:
    for symbol, margin_interest_rate in slice.margin_interest_rates.items():
        interest_rate = margin_interest_rate.interest_rate
        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 AddCryptoadd_crypto method, call the RemoveSecurityremove_security method.

self.remove_security(self.btcbusd)
RemoveSecurity(_symbol);

The RemoveSecurityremove_security 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

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: