QuantConnect
Bybit Crypto Future Margin Rate Data
Introduction
The Bybit Crypto Future Margin Rate Data by QuantConnect is for Cryptocurrency Futures margin interest data points. The data covers 370 Cryptocurrency pairs, starts in August 2020, and is delivered on a daily update frequency. This dataset is created by downloading data using Bybit API.
This dataset is an important companion to the Bybit Crypto Future Price Data dataset because it contains information on margin interest data to model margin costs.
For more information about the Bybit 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 Bybit Crypto Future Margin Rate dataset:
def Initialize(self) -> None: self.SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin) self.crypto_future_symbol = self.AddCryptoFuture("BTCBUSD", Resolution.Minute).Symbol
private Symbol _cryptoFutureSymbol; public override void Initialize { SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin); // perpetual futures does not have a filter function _cryptoFutureSymbol = AddCryptoFuture("BTCBUSD", Resolution.Minute).Symbol; }
The Bybit 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 | 370 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 Bybit 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.
from AlgorithmImports import *
from QuantConnect.DataSource import *
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 Tether
self.set_account_currency("USDT", 100000)
self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN)
crypto_future = self.add_crypto_future("BTCUSDT", Resolution.MINUTE)
# perpetual futures does not have a filter function
self.btcusdt = 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 Tether SetAccountCurrency("USDT", 100000); SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin); var cryptoFuture = AddCryptoFuture("BTCUSDT", 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 Bybit 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.btcusdt in slice.margin_interest_rates:
interest_rate = slice.margin_interest_rates[self.btcusdt].interest_rate
self.log(f"{self.btcusdt} 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.btcusdt)
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
For more example algorithms, see Examples.