CoinAPI

Binance Crypto Future Price Data

Introduction

The Binance Crypto Future Price Data by CoinAPI is for Crypto-currency futures price and volume data points. The data covers 348 Cryptocurrency pairs, starts in August 2020, and is delivered on any frequency from tick to daily. This dataset is created by monitoring the trading activity on Binance.

The Binance Crypto Future Margin Rate Data dataset provides margin interest data to model margin costs.

For more information about the Binance Crypto Future Price Data dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

CoinAPI was founded by Artur Pietrzyk in 2016 with the goal of providing real-time and historical cryptocurrency market data, collected from hundreds of exchanges. CoinAPI provides access to Cryptocurrencies for traders, market makers, and developers building third-party applications.

Getting Started

The following snippet demonstrates how to request data from the Binance Crypto Future Price 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;
}

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateAugust 2020
Asset Coverage292 Crypto Futures Pairs
Data DensityDense
ResolutionTick, Second, Minute, Hourly, & Daily
TimezoneUTC

Data Point Attributes

The Binance Crypto Future Price dataset provides TradeBar, QuoteBar, and Tick objects.

TradeBar Attributes

TradeBar objects have the following attributes:

QuoteBar Attributes

QuoteBar objects have the following attributes:

Tick Attributes

Tick objects have the following attributes:

Supported Assets

The following table shows the available Crypto Future pairs:

Requesting Data

To add Binance Crypto Future Price 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 Future Price data, index the Bars, QuoteBars, or Ticks properties 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.Bars:
        trade_bar = slice.Bars[self.symbol]
        self.Log(f"{self.symbol} close at {slice.Time}: {trade_bar.Close}")

    if self.symbol in slice.QuoteBars:
        quote_bar = slice.QuoteBars[self.symbol]
        self.Log(f"{self.symbol} bid at {slice.Time}: {quote_bar.Bid.Close}")

    if self.symbol in slice.Ticks:
        ticks = slice.Ticks[self.symbol]
        for tick in ticks:
            self.Log(f"{self.symbol} price at {slice.Time}: {tick.Price}")
public override void OnData(Slice slice)
{
    if (slice.Bars.ContainsKey(_symbol))
    {
        var tradeBar = slice.Bars[_symbol];
        Log($"{_symbol} price at {slice.Time}: {tradeBar.Close}");
    }

    if (slice.QuoteBars.ContainsKey(_symbol))
    {
        var quoteBar = slice.QuoteBars[_symbol];
        Log($"{_symbol} bid at {slice.Time}: {quoteBar.Bid.Close}");
    }

    if (slice.Ticks.ContainsKey(_symbol))
    {
        var ticks = slice.Ticks[_symbol];
        foreach (var tick in ticks)
        {
            Log($"{_symbol} price at {slice.Time}: {tick.Price}");
        }
    }
}

You can also iterate through all of the data objects in the current Slice.

def OnData(self, slice: Slice) -> None:
    for symbol, trade_bar in slice.Bars.items():
        self.Log(f"{symbol} close at {slice.Time}: {trade_bar.Close}")

    for symbol, quote_bar in slice.QuoteBars.items():
        self.Log(f"{symbol} bid at {slice.Time}: {quote_bar.Bid.Close}")

    for symbol, ticks in slice.Ticks.items():
        for tick in ticks:
            self.Log(f"{symbol} price at {slice.Time}: {tick.Price}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Bars)
    {
        var symbol = kvp.Key;
        var tradeBar = kvp.Value;
        Log($"{symbol} price at {slice.Time}: {tradeBar.Close}");
    }

    foreach (var kvp in slice.QuoteBars)
    {
        var symbol = kvp.Key;
        var quoteBar = kvp.Value;
        Log($"{symbol} bid at {slice.Time}: {quoteBar.Bid.Close}");
    }

    foreach (var kvp in slice.Ticks)
    {
        var symbol = kvp.Key;
        var ticks = kvp.Value;
        foreach (var tick in ticks)
        {
            Log($"{symbol} price at {slice.Time}: {tick.Price}");
        }
    }
}

For more information about accessing Crypto Future data, see Handling Data.

Historical Data

To get historical Binance Crypto Future Price data, call the History method with the Crypto Future Symbol. If there is no data in the period you request, the history result is empty.

# DataFrame
history_df = self.History(self.symbol, 100, Resolution.Daily)

# TradeBar objects
history_trade_bars = self.History[TradeBar](self.symbol, 100, Resolution.Minute)

# QuoteBar objects
history_quote_bars = self.History[QuoteBar](self.symbol, 100, Resolution.Minute)

# Tick objects
history_ticks = self.History[Tick](self.symbol, timedelta(seconds=10), Resolution.Tick)
// TradeBar objects 
var historyTradeBars = History(_symbol, 100, Resolution.Daily);

// QuoteBar objects 
var historyQuoteBars = History<QuoteBar>(_symbol, 100, Resolution.Minute);

// Tick objects 
var historyTicks = History<Tick>(_symbol, TimeSpan.FromSeconds(10), Resolution.Tick);

For more information about historical data, see History Requests.

Remove Subscriptions

To unsubscribe from a Crypto Future contract that you added with the AddCryptoFuture method, call the RemoveSecurity method.

self.RemoveSecurity(self.symbol)
RemoveSecurity(_symbol);

The RemoveSecurity method cancels your open orders for the security and liquidates your Crypto Future holdings.

Example Applications

The Binance Crypto Future Price dataset enables you to 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#:

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: