How to Download Cryptocurrency Candlestick Data from Exchanges

board-2398309_1920.jpg

Candlestick data is one of the most popular ways to consume the current state of the cryptocurrency market. Every time you visit an exchange, a trading application, or even some trading bots - Candlesticks can be found scattered throughout the UI.

As a developer, it has become a painful experience to integrate candlesticks from every exchange. Each exchange provides different formats, time intervals, historical quantity, and endpoints.

In this article, we will investigate the best ways to access historical candlestick data, download, and serve this data. Whether you are managing a global application or just want the data for personal use, this guide will help you build a solution which works for you.

15476575019422.jpg

There are a number of different ways we can go about collecting this data. Let’s examine some of the most popular strategies and the advantages and disadvantages of each strategy.

Calculate from Raw Data

Fundamentally, candlesticks are simply the culmination of each trade that is executed on the exchange. That means you can technically construct the entire candlestick history yourself if you had the historic tick-by-tick trade data from the exchange. All you would need to do is the following steps:

  1. Tally up the volume from every trade in a given candlestick interval

  2. Calculate the min trade price for each interval

  3. Calculate the max trade price for each interval

  4. Calculate the open and close prices for each interval

This is by far the most time consuming method to constructing the historical candlestick data. Not to mention it would likely be pricey. This trade data could set you back anywhere from $1,000 to $1o,000 depending on what vendor you decide to approach for the data.

Not to mention it would require a constant connection to every exchange in order to provide forward filling data. Every trade matters, so make sure you don’t miss one!

Download Candlesticks from Exchange

The next popular option is to access the candlestick data directly from the exchange. That way you don’t need to do any of the heavy lifting of calculating the candlesticks yourself.

It should be a breeze right? Wrong!

In order to support candlesticks across every major exchange, you will need to follow these steps:

  1. Write custom code to access the candlesticks across each exchange you want to integrate

  2. Normalize the candlesticks so you have consistent intervals across each exchange (exchanges don’t have a consistent interval they agree on)

  3. Manage incorrect labeling of assets, token swaps, forks, and rate limits which make it near impossible to manage a number of exchanges

  4. Constantly update your code for each exchange as they release updates, modify conventions, or change the way they serve data

While calculating every candlestick by using the tick-by-tick data would be a nightmare, accessing the data directly from the exchange isn’t much better.

Exchanges in the cryptocurrency market are difficult to manage. Every exchange has a different set of standards and APIs. Some exchanges incorrectly mark assets or have poor conventions. In the end, it requires constantly updating your custom code to remain relevant.

To highlight the intensity of the situation, let’s take examples from a few exchanges.

binance-logo.png

Binance Candlesticks

Documentation: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#klinecandlestick-data

Response:

[
  [
    1499040000000,      // Open time
    "0.01634790",       // Open
    "0.80000000",       // High
    "0.01575800",       // Low
    "0.01577100",       // Close
    "148976.11427815",  // Volume
    1499644799999,      // Close time
    "2434.19055334",    // Quote asset volume
    308,                // Number of trades
    "1756.87402397",    // Taker buy base asset volume
    "28.46694368",      // Taker buy quote asset volume
    "17928899.62484339" // Ignore.
  ]
]

Supported Candlestick Intervals:

1 minute, 3 minute, 5 minute, 15 minute, 30 minute, 1 hour, 2 hour, 4 hour, 6 hour, 8 hour, 12 hour, 1 day, 3 day, 1 week, 1 month.

poloniex.png

Poloniex Candlesticks

Documentation: https://docs.poloniex.com/#returnchartdata

Response:

{ 
    date: 1539864000,
    high: 0.03149999,
    low: 0.031,
    open: 0.03144307,
    close: 0.03124064,
    volume: 64.36480422,
    quoteVolume: 2055.56810329,
    weightedAverage: 0.03131241 
},

Supported Candlestick Intervals:

5 minute, 15 minute, 30 minute, 2 hour, 4 hour, 1 day.

Candlestick Disarray

These simple examples demonstrate the complete inconsistency between exchange candlestick APIs. There are no standards when it comes to cryptocurrency exchange APIs.

It’s a disaster.

Even creating consistency between these two exchanges would require significant overhead to standardize the candlestick intervals, provide consistent data in responses, and a deep understanding of what each piece of data represents.

Leverage a Crypto Data Vendor

Cryptocurrency data vendors are a convenient option for developers who want something that just works. Instead of fussing with each exchange, maintaining a complete history of everything that has ever happened on an exchange, or stressing about sporadic updates - Data vendors manage the complexities so you can focus on a simple way to access the data.

The steps are then simplified to:

  1. Plug into a data vendor and automatically access normalized candlesticks from every exchange.

There’s no maintenance, no confusion about nonstandard conventions, or random updates on a Friday night when you’re out having dinner.

Shrimpy is the one of the most prominent of these vendors. Accessing candles can be done through our public endpoints here.

The data is completely public for use. Just call the endpoint in your browser to test like this:

https://dev-api.shrimpy.io/v1/exchanges/binance/candles?quoteTradingSymbol=BTC&baseTradingSymbol=LTC&interval=1H

In an instant, you have access to candlesticks across every major exchange in a consistent format.

Shrimpy Dark.png

Normalized Candlesticks

Both the data presented and the supported candlestick intervals are carefully chosen to provide the best experience possible for both developers and traders who will need to read charts generated from this data.

Sign up for a free developer account here.

Documentation: https://developers.shrimpy.io/docs/#get-candles

Response:

  {
    "open": "0.0000157300000000",
    "high": "0.0000157800000000",
    "low": "0.0000155800000000",
    "close": "0.0000157100000000",
    "volume": "219444.0000000000000000",
    "quoteVolume": 3.44176145,
    "btcVolume": 3.44176145,
    "usdVolume": 27437.297915762,
    "time": "2019-05-24T23:00:00.000Z"
  },

Supported Candlestick Intervals:

1 minute, 5 minute, 15 minute, 1 hour, 6 hour, 1 day.


About Shrimpy

Shrimpy’s Developer Trading API is a unified way to integrating trading functionality across every major exchange. Collect market data, access real-time websockets, execute advanced trading strategies, and manage an unlimited number of users.

Shrimpy Crypto Trading API: Shrimpy | Crypto Trading APIs for Developers

Don’t forget to follow us on Twitter and Facebook for updates, and ask any questions to our amazing Telegram community.

The Shrimpy Team