February 13, 2026

Python Scripts for CCXT Crypto Candlestick (OHLCV) Charting Data

Python Scripts for CCXT Crypto Candlestick (OHLCV) Charting Data

Python Scripts for CCXT Crypto Candlestick (OHLCV) Charting Data

Python Scripts for CCXT Crypto Candlestick (OHLCV) Charting Data

Complete Script

Putting everything we covered together, we find the full final version of the script would look something like the following.

import ccxt
from datetime import datetime
import plotly.graph_objects as go
# collect the candlestick data from Binance
binance = ccxt.binance()
trading_pair = 'LTC/BTC'
candles = binance.fetch_ohlcv(trading_pair, '1h')
dates = []
open_data = []
high_data = []
low_data = []
close_data = []
# format the data to match the charting library
for candle in candles:
dates.append(datetime.fromtimestamp(candle[0] / 1000.0).strftime('%Y-%m-%d %H:%M:%S.%f'))
open_data.append(candle[1])
high_data.append(candle[2])
low_data.append(candle[3])
close_data.append(candle[4])
# plot the candlesticks
fig = go.Figure(data=[go.Candlestick(x=dates,
open=open_data, high=high_data,
low=low_data, close=close_data)])
fig.show()

You can chart different assets across every major exchange by changing the trading pair and exchange from which you collect the OHLCV data.

Besides CCXT, there are other libraries that can help you manage live and historical data from exchanges. One of those libraries is the Shrimpy Universal Crypto Trading APIs. These APIs provide candlestick data for every major exchange going back as far as 2011.

Before starting this script, you will need to sign up for a free Shrimpy Universal Crypto Trading APIs account.

After signing up, select the “Create Api Key” button to generate your free Master API Keys. Once you’ve generated your keys, ensure you have enabled “Data” permissions on the API keys and store them in a secure location.

Imports

We will start by importing the Shrimpy and Plotly libraries. These will be the only necessary libraries for this example tutorial.

import shrimpy
import plotly.graph_objects as go

Create a Client

Use your Shrimpy public and secret keys to create the Shrimpy client. This will allow you to access every exchange through the same client.

public_key = '...'
secret_key = '...'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)

Note: There are both a rest API client and websocket client for Shrimpy. We will be using the rest API client for this tutorial.

Get Data

Request data from the exchange. You are welcome to select any exchange or pair, but we will use the XRP/BTC pair on Bittrex.

candles = client.get_candles(
'bittrex', # exchange
'XRP', # base_trading_symbol
'BTC', # quote_trading_symbol
'1d' # interval
)

The “Get Candles” endpoint we used in the above snippet will allow us to get the latest 1,000 candlesticks for free. If your service requires additional historical data, the Shrimpy APIs support candlestick data all the way back to 2011 through the “Get Historical Candles” endpoint. The historical data endpoint requires a data subscription.

Using the historical data endpoint would look something like the example below.

candles = client.get_historical_candles(
'bittrex', # exchange
'XRP', # base_trading_symbol
'BTC', # quote_trading_symbol
'2017-02-11T00:00:00.000Z',# start_time
'2019-10-20T00:00:00.000Z',# end_time
1000, # limit
'1d' # interval
)

Notice how the request requires a starting date, end date, and a max candlestick limit (max 1,000). Since this endpoint is designed for collecting historical data, you would iterate over the candlesticks 1,000 at a time depending on what you want to collect.

Whichever endpoint you decide to access, the rest of the example will be identical. For the sake of brevity, we will assume you decide to use the “Get Candles” endpoint for the rest of the example code.

Format Data

Similar to the previous example with CCXT, we will need to format the Shrimpy candles to match the format required by the plotting library.

dates = []
open_data = []
high_data = []
low_data = []
close_data = []
for candle in candles:
dates.append(candle['time'])
open_data.append(candle['open'])
high_data.append(candle['high'])
low_data.append(candle['low'])
close_data.append(candle['close'])

Plot Candlesticks

As the last step, we will plot the candles using the Plotly library.

fig = go.Figure(data=[go.Candlestick(x=dates,
open=open_data, high=high_data,
low=low_data, close=close_data)])
fig.show()

The outcome of running all of these snippets would look something like the following chart.

Published at Sun, 24 Nov 2019 00:30:52 +0000

{flickr|100|campaign}

Previous Article

Python Scripts for CCXT Crypto Candlestick (OHLCV) Charting Data

Next Article

BitcoinBlink Update 1 – Bitcoin (BTC)Blink

You might be interested in …