All resources
Tutorial · Funding 10 min read

Analyze funding rates in Python with the Optiom API.

Optiom Research · runnable code, tested against the live API

Funding is the cost of holding a perpetual position. Persistent positive funding means longs pay shorts — a crowded long. This tutorial pulls the full funding history for a symbol from the Optiom API, annualizes it, and surfaces the extremes. You only need Python with requests and pandas installed (pip install requests pandas).

Fetch and annualize

One GET request returns funding points as {time, value} pairs, where value is the raw 8-hour rate. Multiply by 3 × 365 to annualize. The script prints distribution stats, the most negative intervals, and the share of time funding was positive — a crude long-bias gauge.

import pandas as pd
import requests

BASE = "https://www.getoptiom.com/api/tradinghub"
SYMBOL = "BTCUSDT"
INTERVALS_PER_YEAR = 3 * 365  # funding settles every 8h

res = requests.get(
    f"{BASE}/funding",
    params={"symbol": SYMBOL, "max_rows": 20_000},
    timeout=30,
)
res.raise_for_status()

df = pd.DataFrame(res.json())
df["dt"] = pd.to_datetime(df["time"], unit="s", utc=True)
df["annualized_pct"] = df["value"] * INTERVALS_PER_YEAR * 100
df = df.set_index("dt").sort_index()

print(df["annualized_pct"].describe().round(2))
print("\nMost negative intervals (shorts pay longs):")
print(df.nsmallest(5, "value")[["value", "annualized_pct"]])

positive_share = (df["value"] > 0).mean() * 100
print(f"\nFunding was positive {positive_share:.1f}% of the time.")

Reading the output

A mean annualized funding of a few percent is normal in neutral markets. Sustained readings above 30-50% annualized flag crowded longs and often precede mean reversion; deeply negative funding marks capitulation lows. Combine with open interest (GET /oi) to distinguish new positioning from forced unwinds.

Going further

Swap the symbol for any listed pair, or schedule this script and alert yourself when annualized funding crosses a threshold. The same endpoint powers the funding views in the Optiom terminal, so your numbers always match what you see on screen.

Run it on your own data.

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