New API endpoints for DEX OHLCV candle data

new api endpoints for candle data

We have released new API endpoints for the decentralised exchange candle data making it easier to develop algorithmic trading strategies.


Trading Strategy is offering both real-time and historical dataset API for decentralised exchanges. We are currently using the same real-time API endpoints to render trading pair charts with ChartIQ, meaning we have candle data available. However, this time we optimised the API endpoint to be suitable for the backtesting of trading strategies. This is based on our early user feedback and the pain points we found in focus group testing.

JSONL streaming candle data

The new OHLCV data endpoint is called candles-jsonl. The highlights of this API are:

  • No API key needed - limited to 200 req/minutes and limited by response size (100 megabytes)
  • Optimised for fetching the historical data, instead of displaying the latest price action as one does with trading pair charts
  • Streaming data delivery method instead of pre-compressed dataset files
  • Dynamic filtering - makes datasets smaller
  • Web-native citizen - works in JavaScript and Python alike
  • Uses JSON Lines streaming data format - it's an easy to parse and human-readable format where each candle is a JSON object on its own line
  • Low latency - suitable for both real-time and backtesting usage
  • Supports fetching of data for multiple trading pairs simultaneously if one is to developer multi trading pair strategies

An example of a response:


For more information about the new candles API, see the OpenAPI explorer.

Example Python script

Here is a pain Python example that fetches data for two trading pairs over candles-jsonl endpoint.

  • Uses 15 minutes candles
  • BNB-BUSD trading pair on PancakeSwap on Binance Smart Chain
  • ETH-USD trading pair on Uniswap v2 on Ethereum mainnet

"""A sample script to download JSONL candle data.

Request all historical data for

- 15m candles



The download JSONL binary size is 28 Mbytes

import datetime
from collections import defaultdict

import requests
import jsonlines

api_url = ""

bnb_busd_params = {
    "chain_slug": "binance",
    "exchange_slug": "pancakeswap-v2",
    "pair_slug": "bnb-busd",

resp = requests.get(f"{api_url}/pair-details", bnb_busd_params)
assert resp.status_code == 200, f"Got {resp.text}"

bnb_busd = resp.json()

print("Pair #1", bnb_busd["summary"]["pair_name"], bnb_busd["summary"]["pair_id"])

eth_usdc_params = {
    "chain_slug": "ethereum",
    "exchange_slug": "uniswap-v2",
    "pair_slug": "eth-usdc",

resp = requests.get(f"{api_url}/pair-details", eth_usdc_params)
assert resp.status_code == 200, f"Got {resp.text}"

eth_usdc = resp.json()

print("Pair #2", eth_usdc["summary"]["pair_name"], eth_usdc["summary"]["pair_id"])

id_list = (eth_usdc["summary"]["pair_id"], bnb_busd["summary"]["pair_id"])

params = {
    "pair_ids": ",".join(str(i) for i in id_list),
    "time_bucket": "15m",

# Iterate the resulting response
# using jsonlines reader.
# We start to decode incoming data on the first arrived byte
# and keep decoding while streaming the response.
print("Loading OHLCV data")
resp = requests.get(f"{api_url}/candles-jsonl", params=params, stream=True)
reader = jsonlines.Reader(resp.raw)

print("Iterating response")
candle_data = defaultdict(list)
for item in reader:
    pair_id = item["p"]

eth_usdc_candles = candle_data[eth_usdc["summary"]["pair_id"]]
first_candle = datetime.datetime.utcfromtimestamp(eth_usdc_candles[0]["ts"])
last_candle = datetime.datetime.utcfromtimestamp(eth_usdc_candles[-1]["ts"])
bnb_busd_candles = candle_data[bnb_busd["summary"]["pair_id"]]

print(f"ETH-USDC has {len(eth_usdc_candles):,} candles from {first_candle} to {last_candle}")
print(f"BNB-BUSD has {len(bnb_busd_candles):,} candles")

If you are programming in Python we recommend you to use our trading-strategy client library.

We are hiring

Trading Strategy is hiring Python developers. Check the blog post for more information.

More information

Join our Discord to find out more about DeFi markets and algorithmic trading.

Trading Strategy is an algorithmic trading protocol for decentralised markets, enabling automated trading on decentralised exchanges (DEXs). Learn more about algorithmic trading here. operated by Trading Strategy Operations Ltd., Victoria, Mahe, Seychelles.