TIKTAPE
TikTape Learn

How do I backtest a Hyperliquid perp strategy in Python with fees and funding?

Load hourly candles and hourly funding into pandas, shift the signal one bar, then subtract the taker fee on each position change (0.045% at the base tier) and the funding for each hour held. Funding history is free from Hyperliquid; candles past the API's 5,000 come from TikTape.

Short answer

Load hourly candles and hourly funding rates into pandas, shift your signal one bar so it only uses closed candles, and subtract two costs from the bar returns: the taker fee on every position change (0.045% per side at Hyperliquid's base perp tier) and the funding each hour you hold a position. Hyperliquid's API gives you funding history for free but only the last 5,000 candles, so the candles below come from TikTape.

Runnable backtest: SMA trend with fees and funding

import os, time
import pandas as pd
import requests

KEY = os.environ["TIKTAPE_API_KEY"]
COIN, START, END = "ETH", "2025-06-01", "2025-12-01"
TAKER_FEE = 0.00045  # Hyperliquid base-tier perp taker fee, 0.045%

def ms(day):
    return int(pd.Timestamp(day, tz="UTC").timestamp() * 1000)

# 1. Hourly candles from TikTape (one request holds 10,000 candles, about 416 days of 1h).
r = requests.get("https://tiktape.xyz/api/v1/ohlcv", headers={"X-API-Key": KEY}, timeout=60,
                 params={"coin": COIN, "interval": "1h", "startTime": ms(START), "endTime": ms(END), "limit": 10_000})
r.raise_for_status()
px = pd.DataFrame(r.json()["data"], columns=["ts", "open", "high", "low", "close", "volume"])
px.index = pd.to_datetime(px.pop("ts"), unit="ms", utc=True)
px = px.astype(float)

# 2. Hourly funding from Hyperliquid's free fundingHistory (500 rows per call).
rows, cursor = [], ms(START)
while True:
    page = requests.post("https://api.hyperliquid.xyz/info", timeout=30, json={
        "type": "fundingHistory", "coin": COIN, "startTime": cursor, "endTime": ms(END) - 1}).json()
    rows += page
    if len(page) < 500:
        break
    cursor = page[-1]["time"] + 1
    time.sleep(0.2)
funding = pd.Series([float(x["fundingRate"]) for x in rows],
                    index=pd.to_datetime([x["time"] for x in rows], unit="ms", utc=True).floor("h"))
funding = funding[~funding.index.duplicated()]

# 3. Signal on closed bars, position held over the next bar.
fast, slow = px["close"].rolling(24).mean(), px["close"].rolling(168).mean()
pos = (fast > slow).astype(int) - (fast < slow).astype(int)  # +1 long, -1 short
pos = pos.shift(1).fillna(0)                                # no lookahead

ret = px["close"].pct_change().fillna(0)
fees = pos.diff().abs().fillna(0) * TAKER_FEE               # a flip pays two sides
# Funding settles at the end of each hour: longs pay a positive rate, shorts receive it.
fund = pos * funding.reindex(px.index).shift(-1).fillna(0)
pnl = pos * ret - fees - fund

print(f"bars {len(px)}, trades {int((pos.diff().abs() > 0).sum())}")
print(f"gross {(pos * ret).sum():+.2%}  fees {-fees.sum():+.2%}  funding {-fund.sum():+.2%}  net {pnl.sum():+.2%}")

We ran it on 2026-12-03: 4,392 hourly bars, with fees and funding each printed as a separate line so you can see what costs eat. It is a sketch, not a strategy: returns are summed, not compounded, and funding is charged on the position, not on its notional at the mark price.

The costs that matter on Hyperliquid

More history, other tools

For intraday bars, page through GET /api/v1/ohlcv 10,000 candles at a time with the Python download loop. To run the same idea in Freqtrade, write the candles and funding to its data folder: Freqtrade backtests on Hyperliquid history.

TikTape at a glance

Price
Full history: $19/month or $189/year; monthly starts with 1 month free (card required, cancel anytime). One-time candle packs from $7. 60 requests/min, up to 10,000 candles per request. Free no-signup sample: a week of BTC/ETH 1m candles as CSV.
Coverage
800+ Hyperliquid markets (perps, spot and HIP-3), 15 intervals from 1m to 1M. Perp and spot candles from 2025-03-23 at every interval; 1d, 3d, 1w and 1M back to each market's first Hyperliquid candle (BTC and ETH from 2020-08-19), 4h from 2024-08-13; HIP-3 markets from their listing. Candles from 2025-03-23 are built from Hyperliquid's S3 trade archives and live API; earlier candles are Hyperliquid's own candleSnapshot candles, not rebuilt from trades.
Quickstart
  1. Get a key at https://tiktape.xyz/#pricing (1 month free, then $19/mo; key emailed after checkout).
  2. Fetch candles (each row is [timestamp_ms, open, high, low, close, volume]):
    export TIKTAPE_API_KEY=your_key
    curl -H "X-API-Key: $TIKTAPE_API_KEY" \
      "https://tiktape.xyz/api/v1/ohlcv?coin=BTC&interval=1h&limit=24"
  3. Page backwards with endTime for older history. Full contract: https://tiktape.xyz/openapi.yaml.

Get the full Hyperliquid candle history

One TikTape key reads every market and interval past Hyperliquid's 5,000-candle limit, up to 10,000 candles per request. The monthly plan starts with 1 month free, then USD 19/month; a card is required and you can cancel anytime before the first charge.

Start the 1-month free trial