CoinAPI
Bybit Crypto Price Data
Introduction
The Bybit Crypto Price Data by CoinAPI is for Cryptocurrency price and volume data points. The data covers 721 Cryptocurrency pairs, starts in July 2017, and is delivered on any frequency from tick to daily. This dataset is created by monitoring the trading activity on Bybit.
For more information about the Bybit 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 snippet demonstrates how to request data from the Bybit Crypto Price dataset:
# Bybit accepts both Cash and Margin account types only. self.set_brokerage_model(BrokerageName.BYBIT, AccountType.CASH) self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN) self.btcusdt = self.add_crypto("BTCUSDT", Resolution.MINUTE, Market.BYBIT).symbol self._universe = self.add_universe(CryptoUniverse.bybit(self.universe_selection_filter))
// Bybit accepts both Cash and Margin account types only. SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash); SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin); _symbol = AddCrypto("BTCUSDT", Resolution.Minute, Market.Bybit).Symbol; _universe = AddUniverse(CryptoUniverse.Bybit(UniverseSelectionFilter));
Data Summary
The following table describes the dataset properties:
Property | Value |
---|---|
Start Date | April 2022 |
Asset Coverage | 721 Currency Pairs |
Data Density | Dense |
Resolution | Tick, Second, Minute, Hourly, & Daily |
Timezone | UTC |
Market Hours | Always Open |
Example Applications
The Bybit 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
For more example algorithms, see Examples.
Data Point Attributes
The Bybit 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 Bybit Crypto Price data to your algorithm, call the AddCryptoadd_crypto 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.set_start_date(2020, 6, 1) self.set_end_date(2021, 6, 1) # Set Account Currency to Tether self.set_account_currency("USDT", 100000) # Bybit accepts both Cash and Margin account types. self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN) self.btcusdt = self.add_crypto("BTCUSDT", Resolution.MINUTE, Market.BYBIT.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); // Bybit accepts both Cash and Margin account types. SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin); _symbol = AddCrypto("BTCUSDT", Resolution.Minute, Market.Bybit).Symbol; } } }
For more information about creating Crypto subscriptions, see Requesting Data.
Accessing Data
To get the current Bybit Crypto Price data, index the Barsbars, QuoteBarsquote_bars, or Ticksticks 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 on_data(self, slice: Slice) -> None: if self.btcusdt in slice.bars: trade_bar = slice.bars[self.btcusdt] self.log(f"{self.btcusdt} close at {slice.time}: {trade_bar.close}") if self.btcusdt in slice.quote_bars: quote_bar = slice.quote_bars[self.btcusdt] self.log(f"{self.btcusdt} bid at {slice.time}: {quote_bar.bid.close}") if self.btcusdt in slice.ticks: ticks = slice.ticks[self.btcusdt] for tick in ticks: self.log(f"{self.btcusdt} 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 on_data(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.quote_bars.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 Bybit Crypto Price data, call the Historyhistory 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.btcusdt, 100, Resolution.DAILY) # TradeBar objects history_trade_bars = self.history[TradeBar](self.btcusdt, 100, Resolution.MINUTE) # QuoteBar objects history_quote_bars = self.history[QuoteBar](self.btcusdt, 100, Resolution.MINUTE) # Tick objects history_ticks = self.history[Tick](self.btcusdt, 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 Bybit Crypto pairs, call the AddUniverseadd_universe method with a CryptoUniverse object. A Crypto 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).
from QuantConnect.Data.universe_selection import * def initialize(self) -> None: self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN) self.universe_settings.asynchronous = True self._universe = self.add_universe(CryptoUniverse.bybit(self.universe_selection_filter)) def universe_selection_filter(self, universe_day): return [c.symbol for c in universe_day if c.volume >= 100 and c.volume_in_usd > 10000]
using QuantConnect.Data.UniverseSelection; public override void Initialize() { SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin); UniverseSettings.Asynchronous = True; _universe = AddUniverse(CryptoUniverse.Bybit(UniverseSelectionFilter)); } private IEnumerable<Symbol> UniverseSelectionFilter(IEnumerable<CryptoUniverse> universeDay) { return from c in universeDay where c.Volume >= 100m && c.VolumeInUsd > 10000m select c.Symbol; }
For more information about universe settings, see Settings.
Universe History
You can get historical universe data in an algorithm and in the Research Environment.
Historical Universe Data in Algorithms
To get historical universe data in an algorithm, call the Historyhistory method with the Universe object, and the lookback period. If there is no data in the period you request, the history result is empty.
var history = History(_universe, 30, Resolution.Daily); foreach (var universeDay in history) { foreach (CryptoUniverse universeItem in universeDay) { Log($"{universeItem.Symbol} price at {universeItem.EndTime}: {universeItem.Close}"); } }
# DataFrame example where the columns are the CryptoUniverse attributes: history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True) # Series example where the values are lists of CryptoUniverse objects: history = self.history(self._universe, 30, Resolution.DAILY) for (univere_symbol, time), universe_day in history.items(): for universe_item in universe_day: self.log(f"{universe_item.symbol} price at {universe_item.end_time}: {universe_item.close}")
Historical Universe Data in Research
To get historical universe data in research, call the UniverseHistoryuniverse_history method with the Universe object, and the lookback period. The UniverseHistoryuniverse_history returns the filtered universe. If there is no data in the period you request, the history result is empty.
var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time); foreach (var universeDay in universeHistory) { foreach (CryptoUniverse universeItem in universeDay) { Console.WriteLine($"{universeItem.Symbol} price at {universeItem.EndTime}: {universeItem.Close}"); } }
# DataFrame example where the columns are the CryptoUniverse attributes: history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True) # Series example where the values are lists of CryptoUniverse objects: universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time) for (univere_symbol, time), universe_day in universe_history.items(): for universe_item in universe_day: print(f"{universe_item.symbol} price at {universe_item.end_time}: {universe_item.close}")
You can call the Historyhistory method in Research.
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 RemoveSecurityremove_security method cancels your open orders for the security and liquidates your holdings in the virtual pair.
Example Applications
The Bybit 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
For more example algorithms, see Examples.