Data Library

Crypto

Introduction

QuantConnect supports cryptocurrency backtesting and live trading. We launched 2017 with the 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)

GDAX Brokerage

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


Data Properties
Resolutions AvailableTick, Second, Minute, Hourly, Daily
Data ProvidersGDAX
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

GDAX 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 GDAX.

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

GDAX Live Trading

Crypto currency live trading is available through the GDAX brokerage. In order to live trade with GDAX, QuantConnect users must sign up for a GDAX account here: https://gdax.com. After obtaining an account, the next step is to create a GDAX API token. Sign into your GDAX 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.

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 'GDAX' as your brokerage. Be sure to copy your API values and passcode correctly in the wizard.

Timezone

GDAX data is 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

GDAX 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.

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

Did you find this page Helpful ?