What you'll build
A script that fetches spot prices from Binance and futures prices from Binance Futures via Kwery, computes the annualized basis, and identifies when the spread is historically wide or narrow.
Prerequisites
- A Kwery API key (get one here)
- Python 3.10+
requests,pandas, andnumpyinstalled
Outline
- Fetch spot price data
- Fetch futures price data
- Compute the basis spread
- Annualize and analyze the spread
- Generate signals based on z-score
Step 1 — Fetch spot prices
Pull the current spot price using /v1/binance/spot/{symbol}/ticker.
curl "https://kwery-api.com/v1/binance/spot/BTCUSDT/ticker?api-key=YOUR_KEY"
Section coming soon — will include Python code to collect spot prices over time.
Step 2 — Fetch futures prices
Pull the corresponding futures price using /v1/binance/futures/{symbol}/ticker.
curl "https://kwery-api.com/v1/binance/futures/BTCUSDT/ticker?api-key=YOUR_KEY"
Section coming soon.
Step 3 — Compute the basis
Calculate the raw basis as (futures_price - spot_price) / spot_price.
Section coming soon.
Step 4 — Annualize and analyze
Annualize the basis using days-to-expiry (for dated futures) or a rolling window. Compute a historical distribution.
Section coming soon.
Step 5 — Generate z-score signals
Flag when the annualized basis z-score exceeds a threshold, indicating a mean-reversion opportunity.
Section coming soon.
Next steps
- Add Hyperliquid futures via
/v1/hyperliquidfor cross-venue basis comparison - Build an automated alert system
- Extend to multiple pairs for portfolio-level basis monitoring