CoinAPI

Binance US Crypto Price Data

Introduction

The Binance US Crypto Price Data by CoinAPI is for Cryptocurrency price and volume data points. The data covers 174 Cryptocurrency pairs, starts in October 2019, and is delivered on any frequency from tick to daily. This dataset is created by monitoring the trading activity on Binance US.

For more information about the Binance US Crypto 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 snippets demonstrates how to set the brokerage model, request data, and perform universe selection with the Binance US dataset:

# Binance US only accepts cash accounts
self.SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash)

self.symbol = self.AddCrypto("BTCUSD", Resolution.Minute, Market.BinanceUS).Symbol

self.AddUniverse(CryptoCoarseFundamentalUniverse(Market.BinanceUS, self.UniverseSettings, self.UniverseSelectionFilter))
// Binance US only accepts cash accounts
SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash);

_symbol = AddCrypto("BTCUSD", Resolution.Minute, Market.BinanceUS).Symbol;

AddUniverse(new CryptoCoarseFundamentalUniverse(Market.BinanceUS, UniverseSettings, UniverseSelectionFilter));

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateOctober 2019
Asset Coverage174 Cryptocurrency Pairs
Data DensityDense
ResolutionTick, Second, Minute, Hourly, & Daily
TimezoneUTC

Data Point Attributes

The Binance US Crypto Price dataset provides TradeBar, QuoteBar, Tick, and CryptoCoarseFundamental 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:

CryptoCoarseFundamental Attributes

CryptoCoarseFundamental objects have the following attributes:

Requesting Data

To add Binance US Crypto Price data to your algorithm, call the AddCrypto method. Save a reference to the Crypto 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)
        self.SetCash(100000)

        # BinanceUS accepts Cash account type only, AccountType.Margin will result in an exception.
        self.SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash)
        
        self.symbol = self.AddCrypto("BTCUSD", Resolution.Minute, Market.BinanceUS).Symbol
namespace QuantConnect
{
    public class CoinAPIDataAlgorithm : QCAlgorithm
    {
        private Symbol _symbol;
        
        public override void Initialize()
        {
            SetStartDate(2020, 6, 1);
            SetEndDate(2021, 6, 1);
            SetCash(100000);
        
            // BinanceUS accepts Cash account type only, AccountType.Margin will result in an exception.
            SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash);
            
            _symbol = AddCrypto("BTCUSD", Resolution.Minute, Market.BinanceUS).Symbol;
        }
    }
}

For more information about creating Crypto subscriptions, see Requesting Data.

Accessing Data

To get the current Binance US Crypto Price data, index the Bars, QuoteBars, or Ticks properties of the current Slice with the Crypto 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 data, see Handling Data.

Historical Data

To get historical Binance US Crypto Price data, call the History method with the Crypto 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.

Universe Selection

To select a dynamic universe of Binance US Crypto pairs, call the AddUniverse method with a CryptoCoarseFundamentalUniverse object. A Crypto coarse universe uses a selection function to select Crypto pairs based on their OHLCV and dollar volume of the previous day as of midnight Coordinated Universal Time (UTC).

def Initialize(self) -> None:
    self.SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash)
    self.AddUniverse(CryptoCoarseFundamentalUniverse(Market.BinanceUS, self.UniverseSettings, self.UniverseSelectionFilter))

def UniverseSelectionFilter(self, crypto_coarse: List[CryptoCoarseFundamental]) -> List[Symbol]:
    return [c.Symbol for c in crypto_coarse if c.Volume >= 100 and c.VolumeInUsd > 10000]
public override void Initialize()
{
    SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash);
    AddUniverse(new CryptoCoarseFundamentalUniverse(Market.BinanceUS, UniverseSettings, UniverseSelectionFilter));
}

private IEnumerable<Symol> UniverseSelectionFilter(IEnumerable<CryptoCoarseFundamental> cryptoCoarse)
{
    return from c in cryptoCoarse
           where c.Volume >= 100m && c.VolumeInUsd > 10000m
           select c.Symbol;
}

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 US Crypto Price dataset enables you to accurately design strategies for Cryptocurrencies. Examples include the following strategies:

  • Buy and hold
  • Trading Cryptocurrency volatility and price action
  • Allocating a small portion of your portfolio to Cryptocurrencies to hedge against inflation

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: