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 421 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
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:
Property | Value |
---|---|
Start Date | August 2020 |
Asset Coverage | 421 Crypto Futures Pairs |
Data Density | Regular |
Resolution | Daily |
Timezone | UTC |
Market Hours | Always 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
For more example algorithms, see Examples.
Requesting Data
To add Binance Crypto Future Margin Rate data to your algorithm, call the add_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
For more information about creating Crypto Future subscriptions, see Requesting Data.
Accessing Data
To get the current Binance Crypto Margin Rate data, index the margin_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}")
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}")
For more information about accessing Crypto Future data, see Handling Data.
Historical Data
To get historical Binance Crypto Future Margin Rate data, call the history
method with MarginInterestRate
data type and the Crypto Future Symbol
. If there is no data in the period you request, the history result is empty.
# DataFrame history_df = self.history(MarginInterestRate, self.btcbusd, 100, Resolution.DAILY) # MarginInterestRate objects history = self.history[MarginInterestRate](self.btcbusd, 100, Resolution.DAILY)
For more information about historical data, see History Requests.
Remove Subscriptions
To unsubscribe from a Crypto pair that you added with the add_crypto
method, call the remove_security
method.
self.remove_security(self.btcbusd)
The remove_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
For more example algorithms, see Examples.