Crypto
AvailableBitcoin daily bars from Coinbase, plus a few days of minute bars from Coinbase, Binance and Bybit.
Daily BTCUSD bars on Coinbase from December 2014 to August 2018. Short samples at finer resolutions: Coinbase minute bars for BTCUSD, BTCEUR and ETHUSD on a few days in 2016 to 2018, Binance BTCUSDT hourly bars in May 2018, and Binance BTCBUSD and Bybit BTCUSDT minute bars on 13 December 2022.
How the data works
- Pass the market when you add a pair: LEAN assumes Coinbase otherwise, and each sample exists on one market only.
- Crypto trades every day, so daily bars run through weekends, and each one closes at midnight UTC.
- Coinbase's BTCUSD daily bars cover December 2014 to August 2018. Finer samples last only a few days, so check the dates above before using them.
- For longer history, see the Binance Crypto and Bybit Crypto listings, which are test data for use before launch.
Fields
4 columns| Field | Description |
|---|---|
| time | When the bar began, in the market's time zone |
| end_time | When the bar closed: the moment it reaches your algorithm |
| open, high, low, close | Prices in the bar |
| volume | Amount of the base currency traded in the bar, for example bitcoin for BTCUSD |
Example algorithm
# region imports
from AlgorithmImports import *
# endregion
class BitcoinTrendAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2015, 6, 1)
self.set_end_date(2018, 8, 1)
self.set_cash(100000)
self.btc = self.add_crypto("BTCUSD", Resolution.DAILY, Market.COINBASE).symbol
self.trend = self.ema(self.btc, 50, Resolution.DAILY)
self.set_warm_up(50, Resolution.DAILY)
def on_data(self, slice):
if self.is_warming_up or not self.securities[self.btc].has_data:
return
# Hold bitcoin while it trades above its 50-day average. 90%, to leave room for fees.
if self.securities[self.btc].price > self.trend.current.value:
self.set_holdings(self.btc, 0.9)
else:
self.liquidate(self.btc)
Sample data distributed with the open-source LEAN engine.