All resources
Tutorial · Data 5 min read

Download OHLCV candles to CSV for backtests and notebooks.

Optiom Research · runnable code, tested against the live API

Every backtest starts with clean candles. This tutorial downloads the most recent bars for a symbol and timeframe from the Optiom API, merges the volume series, and writes a CSV you can load anywhere. Signed-in users can also use the one-call server-side export (/api/tradinghub/export).

Fetch, merge, save

The ohlcv endpoint returns candles and volume as two aligned series. The limit parameter always returns the most recent N bars. Merge on time, add an ISO timestamp column, and dump to CSV.

import pandas as pd
import requests

BASE = "https://www.getoptiom.com/api/tradinghub"

res = requests.get(
    f"{BASE}/ohlcv",
    params={"symbol": "BTCUSDT", "timeframe": "1h", "limit": 500},
    timeout=30,
)
res.raise_for_status()
payload = res.json()

candles = pd.DataFrame(payload["candles"])
volume = pd.DataFrame(payload["volume"])
candles = candles.merge(
    volume[["time", "value"]].rename(columns={"value": "volume"}),
    on="time", how="left",
)
candles["iso_time"] = pd.to_datetime(candles["time"], unit="s", utc=True)

candles.to_csv("btcusdt_1h.csv", index=False)
print(f"Saved {len(candles)} candles")
print(candles.tail())

Server-side CSV export

If you are signed in, one request does all of this server-side and streams a ready CSV: /api/tradinghub/export?dataset=candles&symbol=BTCUSDT&timeframe=1h&max_rows=5000. The same route exports funding, liquidations and oi datasets.

Going further

Loop over symbols and timeframes to build a research dataset, or schedule the script daily to keep local files fresh. Timeframes follow the exchange convention: 1m, 5m, 15m, 1h, 4h, 1d.

Run it on your own data.

Create a free account for CSV exports, then move to API access as your workflow grows.