Data Library

Crypto

Introduction

QuantConnect supports cryptocurrency backtesting and live trading. We launched 2017 with the Coinbase Pro (formerly GDAX) exchange.

Cryptocurrency trading is handled similarly to a forex transaction; however the exchanges do not provide the same holdings history as traditional forex brokerages so it has some unique challenges in live trading we will go into below.

One common stumbling block that users face designing algorithms with crypto currency is a misunderstanding of Cash modeling. Most crypto exchanges only support cash trading so you cannot place trades when you do not have the cash in your account. 'Cash' in this sense means any of the crypto coin types.

For example, if you have $100,000 USD; but no LTC in your portfolio - you cannot trade BTCLTC, and in order to trade BTCEUR you need EUR in your portfolio. This means you must make trading decisions based on the Cashbook. This holds your current balance of coins available.

// Fetch the number of BTC coins in your portfolio.
var btc = Portfolio.CashBook["BTC"].Amount;
# Fetch the number of BTC coins in your portfolio.
btc = self.Portfolio.CashBook["BTC"].Amount

Cryptocurrency is also sensitive to transaction fees so it is important to set the correct BrokerageModel. This also helps your backtesting restrictions behave as close as possible to the production live trading environment.

SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)

Coinbase Pro Exchange

The Coinbase Pro Exchange is a US-Based crypto currency exchange formerly known as The Global Digital Asset Exchange (GDAX). Today Coinbase Pro offers 9 symbol pairs covering BTC, EUR, LTC, USD and ETH combinations. QuantConnect Coinbase Pro data is timestamped to the millisecond.


Data Properties
Resolutions AvailableTick, Second, Minute, Hourly, Daily
Data ProvidersCoinbase Pro
Start Date Jun 15th, 2015.
Symbol Universe 9 Crypto Currency Pairs

Data must be added in the Initialize() method manually with AddCrypto() method.

// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
public override void Initialize()
{
    SetStartDate(2015, 10, 07);  //Set Start Date
    SetEndDate(2017, 10, 11);    //Set End Date
    SetCash(100000);             //Set Strategy Cash
    AddCrypto("BTCUSD", Resolution.Hour, Market.GDAX);
}

// Accessing requested data
public override void OnData(Slice data) {
    //via a tradebar dictionary (symbol - bar)
    data.Bars["BTCUSD"].Close
    //or via a ticks list:
    data.Ticks["BTCUSD"][0].Close
}
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
def Initialize(self):
    self.SetStartDate(2015, 10, 07)  # Set Start Date
    self.SetEndDate(2017, 10, 11)    # Set End Date
    self.SetCash(100000)             # Set Strategy Cash
    self.AddCrypto("BTCUSD", Resolution.Hour, Market.GDAX)

# Accessing requested data
def OnData(self, data):
    # via a tradebar dictionary (symbol - bar)
    data.Bars["BTCUSD"].Close
    # or via a ticks list:
    data.Ticks["BTCUSD"][0].Close

Coinbase Pro trades are currently available from 2015-06-15 to the present. The data in 2015 is somewhat spotty and unrealistic so we recommend starting your backtests from 2016 onwards. We have data on all currency pairs supported by Coinbase Pro.

We currently only have Coinbase Pro brokerage integration. For more information on using this data in your algorithm see the Initializing Algorithms.

Bitfinex

Bitfinex is a digital asset exchange offering markets for 52 countries across a wide variety of symbol pairs. QuantConnect Bitfinex data is timestamped to the millisecond.


Data Properties
Resolutions AvailableTick, Second, Minute, Hourly, Daily
Data ProvidersCoinbase Pro
Start Date Jan 14th, 2013.
Symbol Universe 346 Cryptocurrency Pairs

Live Trading

Crypto currency live trading is available through both Bitfinex and Coinbase Pro brokerages.

In order to live trade with Coinbase Pro, QuantConnect users must sign up for a Coinbase Pro account here: https://pro.coinbase.com/. After obtaining an account, the next step is to create a Coinbase Pro API token. Sign into your Coinbase Pro account and click 'API' from the menu in the upper right. On the API page, users should select the 'View' and 'Trade' permissions. Click 'Create API key' on the bottom of the page. Be sure to record the API key, API passphrase and API secret.

To live trade with Bitfinex, create a Bitfinex account at https://www.bitfinex.com. Create an API token by going to https://www.bitfinex.com/api and click on the "Create New Key" box. Select your desired permission levels and create a label if you want, then click "Generate API Key".

Return to QuantConnect.com and go to the algorithm that you want to trade live. Select 'Go Live' from the upper right hand corner. Follow the 'Live' wizard and select the appropriate brokerage. Be sure to copy your API values and passcode correctly in the wizard.

CoinAPI

CoinAPI is a cryptocurrency data provider that aggregates trades from hundreds of exchanges. While they supply data on almost every imaginable pair, QuantConnect has only implemented the ones that can be traded on Bitfinex.

Timezone

Coinbase Pro, CoinAPI, and Bitfinex data is all set in UTC Time. This means that when accessing data from this brokerage, all data will be time stamped in UTC Time.

About the Provider

Coinbase Pro offers institutions and professionals the ability to trade a variety of digital currencies like Bitcoin, Ethereum, and more on a regulated U.S. based exchange.

Bitfinex is a Hong Kong headquartered cryptocurrency exchange serving a large portion of the world outside the United States.

CoinAPI provides real-time and historical cryptocurrency market data, collected from hundreds of exchanges.

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page helpful?