MKT CAP$2.21T+0.8%
24H VOL$125.9B
BTC DOM59.4%
HEALTH40BEARISH
SHORT-TERM61NEUTRAL
LONG-TERM19BEARISH
OI$51.1B+7.6%
24H LIQ$252M
LONG/SHORT58.8% / 41.2%
REGIME (LT)ESTABLISHED BEAR MARKET
REGIME (ST)CHOPPY HIGH VOLATILITY
HL OI$7.8B
WHALESSHORT 46.0%
MKT CAP$2.21T+0.8%
24H VOL$125.9B
BTC DOM59.4%
HEALTH40BEARISH
SHORT-TERM61NEUTRAL
LONG-TERM19BEARISH
OI$51.1B+7.6%
24H LIQ$252M
LONG/SHORT58.8% / 41.2%
REGIME (LT)ESTABLISHED BEAR MARKET
REGIME (ST)CHOPPY HIGH VOLATILITY
HL OI$7.8B
WHALESSHORT 46.0%
Plug real-time crypto data into your AI agent — one command: Get your free API key →
Get API KeyLogin
Open-Source · MIT · Python

Backtest Hyperliquid perp strategies
on real market data

An open-source Python backtester that models honest taker fees and funding, refuses lookahead, checks liquidations, and replays every trade bar-by-bar in an interactive HTML chart. Historical klines and funding come straight from CryptoDataAPI.

Python 3.10+ NumPy · httpx 17 engine tests Data by CryptoDataAPI
The interactive replay every run exports — candles, trade markers, the equity curve and drawdown, played back bar-by-bar from a real backtest.

Three things most backtesters get wrong

The reasons a strategy looks great on a chart and dies live are almost always the same three. This engine is built to close all three gaps by default.

No lookahead

Your strategy's on_bar() only ever sees history up to the current bar — future data is structurally out of reach. Fills happen at the next bar's open, so you can never trade a price the strategy couldn't have seen.

Honest costs

Taker fees on entry and exit, slippage, and per-bar funding charges — the cost that quietly eats perp strategies — plus liquidation checks. Profit factor and expectancy are computed after all of it, not before.

Bar-by-bar replay

Every run exports a standalone HTML file: candles, trade markers, the equity curve, an underwater drawdown plot and play controls. You watch the strategy trade instead of trusting one summary number.

From clone to a replayed backtest in three commands

Install once, then sync the data, run a strategy, and open the interactive replay. Uses your CryptoDataAPI key in the CRYPTODATA_API_KEY env var.

# 1 · clone & install (Python 3.10+) git clone https://github.com/Crypto-Data-API/hyperliquid-backtester.git cd hyperliquid-backtester python -m venv .venv && . .venv/bin/activate pip install -e . export CRYPTODATA_API_KEY=cdk_live_YOUR_KEY
# 2 · sync data → run a strategy → replay it hlbt sync --symbol BTC --timeframe 15m --days 90 hlbt run --strategy strategies/examples/bollinger_revert.py --symbol BTC --json-out results/btc.json hlbt demo results/btc.json # opens the interactive HTML replay

sync caches klines + funding locally and extends incrementally from the last cached bar — no re-fetching what you already have. Any Hyperliquid or Binance symbol works. Need a key? Grab a free one or see the plans — bulk minute history is part of Pro Plus.

How a run works

STEP 01

Sync

Pull 1-minute klines and funding for your symbol from CryptoDataAPI and cache them locally, resampled to your timeframe.

STEP 02

Simulate

Replay bar-by-bar. Your strategy sees only past bars; orders fill at the next open with fees, slippage, funding and liquidation applied.

STEP 03

Score & replay

Get profit factor, expectancy, Sharpe and max drawdown, then open the HTML replay to watch the equity curve and every trade.

Write a strategy, tune it from the CLI

Subclass Strategy and implement on_bar(). Class attributes automatically become CLI-tunable parameters — sweep them without editing code. Built-in indicators cover SMA, EMA, RSI, ATR and Bollinger Bands.

# strategies/user/my_revert.py class MeanRevert(Strategy): rsi_len = 14 lower = 30 def on_bar(self, ctx): r = ctx.rsi(self.rsi_len) if r < self.lower and not ctx.position: ctx.buy() elif r > 55 and ctx.position: ctx.close()
# tune any attribute from the CLI — no code edits hlbt run --strategy strategies/user/my_revert.py \ --symbol ETH --set rsi_len=21 lower=25

What's in the repo

  • backtester.py — bar-by-bar simulation engine
  • strategy.py — the Strategy base class + context
  • indicators.py — SMA, EMA, RSI, ATR, Bollinger …
  • demo.py — interactive HTML replay exporter
  • sync.py — incremental data sync from CryptoDataAPI
  • strategies/examples/ — reference mean-reversion & trend implementations
  • tests/ — 17 tests validating core engine invariants

Example results — and an honest one

Three strategies ship with the repo, run on the same 71-day BTC window. They're here to show how much results vary — and how easy it is to fool yourself.

Example strategyWin rateNet returnNote
RSI Reversion62.5%+2.09%Modest edge survives fees on this window
Bollinger Revert64.2%+1.64%Works — but 79% of gross profit is eaten by fees
SMA Cross22.1%−17.45%Kept on purpose as an overfitting example

The teaching moment: the sma_cross example was tuned on 70% of the data and looked fine — then lost 3.43% on the unseen 30%. That's why the engine makes honest costs and out-of-sample testing the default, not an afterthought. Backtests are historical simulations, not predictions — profitable history never guarantees live profit. This is educational software, not investment advice.

Powered by CryptoDataAPI data

The backtester is only as honest as the data underneath it. It sources every bar from CryptoDataAPI so fees, funding and prices reflect what actually happened on-venue.

Minute klines + funding

1-minute OHLCV plus funding-rate history for any Hyperliquid perp or Binance market — resampled locally to your chosen timeframe.

Incremental sync

Local cache extends from the last stored bar instead of re-downloading, so repeated backtests stay fast and cheap on your quota.

Deep history via Pro Plus

Bulk minute history and deep klines/funding come from the backtesting archive — clean Parquet, updated nightly, part of Pro Plus.

See the full backtest data offering, the API docs (Backtesting section), or connect the MCP server so an agent can pull data and run the backtester for you.

FAQ

Is it really free?

The backtester is MIT-licensed and fully open-source. You only need a CryptoDataAPI key for the market data — the free tier covers live data, and bulk minute-history backtests use the Pro Plus archive.

Which markets can I backtest?

Any Hyperliquid perpetual and 450+ Binance USDT markets. The sync command takes any symbol the CryptoDataAPI archive covers.

Does it handle funding and liquidations?

Yes — funding is charged per bar from real funding-rate history, and the engine runs a liquidation check each bar so an over-leveraged position gets closed the way it would on-venue.

Can an AI agent drive it?

Absolutely — point Claude Code, Cursor or any agent at the repo with the MCP server connected, and it can sync data, write a strategy and run the backtest end-to-end. See the prompt library for starting points.

Clone it, or point your agent at it

Free, open-source, and honest about costs — with real Hyperliquid and Binance data behind every bar. Bring a CryptoDataAPI key and you're backtesting in minutes.

View on GitHub Need the data? Backtest data → · Compare plans →