Skip to content

Repository files navigation

funding-collector

A small, focused Python library to collect crypto perpetual funding rates from Binance, Bybit, and OKX into a normalized SQLite schema. MIT licensed, no API keys required, no exchange account needed.

Use this as a building block for funding-rate arbitrage scanners, dashboards, backtesting datasets, alert bots, or research notebooks.

Why

Existing funding-rate data services either charge $29+/month with limited history (Coinglass), only cover BTC (Coinalyze), or require you to deal with each exchange's quirks individually. This library does the boring, exchange-specific normalization work once so you can focus on what you actually want to build on top of it.

It also gets two non-obvious things right that most ad-hoc scrapers get wrong:

  1. Per-symbol funding interval. Roughly 30% of USDT perps on Binance and Bybit settle every 4 hours (or 1 hour for a few), not every 8 hours. The collector fetches fundingInfo / instruments-info and stores the correct interval per symbol so your annualized-yield calculations are accurate.
  2. 24h volume per symbol. Stored alongside the funding rate so you can filter out illiquid traps before computing arbitrage spreads.

Install

pip install funding-collector  # once published to PyPI

Or from source:

git clone https://github.com/clementslowik/funding-collector
cd funding-collector
pip install -e .

Quickstart

As a library

from funding_collector import init_db, collect_all, latest_per_symbol
from funding_collector.db import set_db_path

set_db_path("./funding.db")  # optional, defaults to ./funding.db
init_db()

collect_all(["binance", "bybit", "okx"])

rows = latest_per_symbol(min_age_seconds=900)
for r in rows[:5]:
    print(f"{r['exchange']:8s} {r['symbol']:12s} {r['funding_rate']*100:+.5f}%  vol24h ${r['volume_24h_usd']:>14,.0f}")

As a CLI

# One-shot — fetch from all 17 exchanges
funding-collector --exchanges binance,bybit,okx,bitget,mexc,hyperliquid,gateio,dydx,bitfinex,kraken,bingx,bitmex,kucoin,htx,phemex,btse,coinbase_intx

# Daemon loop, fetch every 5 minutes
funding-collector --exchanges binance,bybit,okx,bitget,mexc,hyperliquid,gateio,dydx,bitfinex,kraken,bingx,bitmex,kucoin,htx,phemex,btse,coinbase_intx --loop 300

# Custom DB path via env var
FUNDING_COLLECTOR_DB=/var/data/funding.db funding-collector --loop 300

Examples

The examples/ directory contains starter templates you can clone and modify:

File What it does
quickstart.py Collects from all 17 exchanges and prints the top 10 cross-exchange arb opportunities
telegram_daily_summary.py Builds a daily funding-rate summary (sentiment + top opps) using the local collector library and posts it to a Telegram chat via the bot API
api_summary_telegram.py Same daily digest, but consumes the public Funding Finder HTTP API directly (no local DB). Pure requests, ~100 lines, ideal as a cron job.
ff_client.py A 50-line Python client library for the hosted Funding Finder API. Use this if you want to consume the hosted scanner without self-hosting the data layer.

Schema

CREATE TABLE funding_rates (
    exchange TEXT NOT NULL,
    symbol TEXT NOT NULL,
    base TEXT NOT NULL,
    funding_rate REAL NOT NULL,
    funding_interval_hours INTEGER NOT NULL DEFAULT 8,
    next_funding_time INTEGER,
    mark_price REAL,
    volume_24h_usd REAL DEFAULT 0,
    fetched_at INTEGER NOT NULL,
    PRIMARY KEY (exchange, symbol, fetched_at)
);

The composite primary key gives you a free historical record. Run the collector in a 5-minute loop and after a week you have a queryable funding-rate history per (exchange, symbol).

Coverage today

Exchange Endpoint Symbols
Binance /fapi/v1/premiumIndex (USDT-M) ~670
Bybit /v5/market/tickers?category=linear ~544
OKX /api/v5/public/funding-rate (per inst, parallelized) ~285
Bitget /api/v2/mix/market/tickers + current-fund-rate ~537
MEXC /api/v1/contract/funding_rate + ticker ~762
Hyperliquid /info metaAndAssetCtxs (1h funding interval) ~229
Gate.io /futures/usdt/contracts + tickers ~642
dYdX v4 /v4/perpetualMarkets (1h funding interval) ~124
Bitfinex /v2/conf + tickers + status/deriv (3 bulk calls) ~56
Kraken Futures /derivatives/api/v3/tickers (1 bulk call, 1h funding) ~321
BingX /openApi/swap/v2/quote/premiumIndex + ticker (2 bulk) ~589
BitMEX /api/v1/instrument/active (1 bulk, USDT-quoted only) ~45
KuCoin Futures /api/v1/contracts/active (1 bulk) ~561
HTX (Huobi) /swap_batch_funding_rate + market/detail/batch_merged ~219
Phemex /md/v3/ticker/24hr/all (1 bulk) ~507

Total ~6090 USDT perp symbols across 15 venues. Coinbase Derivatives is the only major missing CEX (no bulk volume endpoint).

Computing arbitrage opportunities

Once you have the data, computing cross-exchange funding-rate arbitrage opportunities is a 10-line operation:

from collections import defaultdict
from funding_collector import latest_per_symbol

rows = latest_per_symbol(min_age_seconds=900)
by_base = defaultdict(list)
for r in rows:
    by_base[r["base"]].append(r)

opportunities = []
for base, group in by_base.items():
    liquid = [g for g in group if g["volume_24h_usd"] >= 1_000_000]
    if len(liquid) < 2:
        continue
    sg = sorted(liquid, key=lambda x: x["funding_rate"])
    spread = sg[-1]["funding_rate"] - sg[0]["funding_rate"]
    if spread > 0:
        opportunities.append((base, sg[0]["exchange"], sg[-1]["exchange"],
                              spread * (24 / sg[0]["funding_interval_hours"]) * 365 * 100))

for base, long_ex, short_ex, apy in sorted(opportunities, key=lambda x: -x[3])[:10]:
    print(f"{base:10s}  long {long_ex:8s}  short {short_ex:8s}  APY {apy:+8.1f}%")

That's it. Long the perp on the exchange with the lowest funding rate, short the perp on the exchange with the highest, capture the spread until convergence.

A hosted version of this — with a web dashboard, REST API, Telegram alerts, and a paid history tier — runs at funding-finder.

Disclaimer

Not financial advice. Funding-rate spreads can converge in minutes, especially on illiquid alts. Always verify execution conditions (slippage, fees, withdraw delays between exchanges, leg correlation breakdown) before sizing real positions. The library only collects data — what you do with it is on you.

Contributing

Pull requests welcome, especially:

  • Additional exchanges (Bitget, Gate.io, MEXC, Hyperliquid)
  • Tests
  • Better rate-limit handling
  • Async collector variant

License

MIT — see LICENSE.

About

Collect crypto perpetual funding rates from Binance, Bybit, and OKX into a normalized SQLite schema. Stdlib + requests only, no API keys required. MIT.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages