Perpetual futures funding rate analysis and cash-carry basis trading — funding rate regimes, annualized basis signals, carry trade construction, and funding rate arbitrage between exchanges.
57
66%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./agent/src/skills/perp-funding-basis/SKILL.mdAnalyze perpetual futures funding rates and spot-futures basis to identify carry trade opportunities, market positioning extremes, and directional sentiment signals. Funding rates are the single most important microstructure indicator in crypto derivatives — they reveal real-time leverage positioning and crowd sentiment.
Perpetual futures have no expiry date. Instead, a funding rate is exchanged between longs and shorts every 8 hours (on most exchanges) to keep the perpetual price anchored to the spot price.
If perp price > spot price → funding rate positive → longs pay shorts
If perp price < spot price → funding rate negative → shorts pay longsOKX funding rate schedule: payments at 00:00, 08:00, 16:00 UTC
Annualized funding rate:
# Funding rate is a per-8h DECIMAL, exactly as OKX/Binance return it
# (the API sends "0.0001" for 0.01%). 3 funding windows/day → × 3 × 365.
funding_rate_8h = 0.0001 # 0.01% per 8h, as a decimal
annualized = funding_rate_8h * 3 * 365 # 0.1095 → 10.95% annualizedUnits convention (whole skill): all code treats the funding rate as a per-8h decimal (
0.0001= 0.01%), matching the raw OKX/Binance API value. The tables below show the equivalent percentages for readability — divide a table's%by 100 to get the decimal a comparison expects (+0.05%→0.0005).
| Funding Rate (8h) | Annualized | Market State | Signal |
|---|---|---|---|
| > +0.05% | > +54.75% | Extreme long crowding | Contrarian short / reduce longs |
| +0.02% to +0.05% | +21.9% to +54.75% | Elevated long bias | Cautious, carry trade viable |
| +0.005% to +0.02% | +5.5% to +21.9% | Mild long bias | Neutral to mild bullish |
| -0.005% to +0.005% | -5.5% to +5.5% | Balanced | Neutral |
| -0.02% to -0.005% | -21.9% to -5.5% | Mild short bias | Neutral to mild bearish |
| < -0.02% | < -21.9% | Short squeeze territory | Contrarian long / reduce shorts |
Funding rate regime detection:
def funding_regime(rates_7d):
"""Classify funding rate regime from 7-day history."""
avg = sum(rates_7d) / len(rates_7d)
consecutive_positive = all(r > 0 for r in rates_7d[-3:])
consecutive_negative = all(r < 0 for r in rates_7d[-3:])
if avg > 0.0003 and consecutive_positive: # > +0.03% per 8h
return "overheated_long" # High risk of long squeeze
elif avg > 0.0001 and consecutive_positive: # > +0.01% per 8h
return "bullish_carry" # Good carry trade environment
elif avg < -0.0002 and consecutive_negative: # < -0.02% per 8h
return "overheated_short" # High risk of short squeeze
elif avg < -0.00005 and consecutive_negative: # < -0.005% per 8h
return "bearish_carry" # Inverse carry trade
else:
return "neutral"Basis = Futures price - Spot price
For dated futures (quarterly), basis reflects cost-of-carry expectations:
# Annualized basis
def annualized_basis(futures_price, spot_price, days_to_expiry):
basis_pct = (futures_price - spot_price) / spot_price
annualized = basis_pct * (365 / days_to_expiry)
return annualized
# Example: BTC spot $65,000, quarterly future $66,500, 45 days to expiry
# Basis: 2.31%, Annualized: 18.7%Basis signal interpretation:
| Annualized Basis | Market State | Signal |
|---|---|---|
| > 30% | Extreme contango, euphoric leverage | Sell basis (cash-carry), top warning |
| 15-30% | Elevated contango, bullish leverage | Carry trade attractive |
| 5-15% | Normal contango | Neutral, mild bullish |
| 0-5% | Flat basis | Low conviction, wait for direction |
| < 0% (backwardation) | Bearish, forced selling | Contrarian long, extreme pessimism |
Strategy: buy spot + sell perpetual futures → collect funding rate
# Cash-carry trade P&L
def carry_trade_pnl(spot_entry, funding_rates, position_size):
"""
Delta-neutral carry: long spot + short perp
P&L comes purely from funding rate collection.
"""
total_funding_collected = 0
for rate in funding_rates:
if rate > 0: # Longs pay shorts → we collect as short
total_funding_collected += rate * position_size
else: # Shorts pay longs → we pay as short
total_funding_collected += rate * position_size # This is negative
return total_funding_collected
# Example: $100,000 position, avg funding +0.015% (0.00015 decimal) per 8h, 30 days
# Revenue: 0.00015 × 3 × 30 × $100,000 = $1,350 (16.4% annualized)Carry trade execution on OKX:
Risk factors:
Different exchanges have different funding rates for the same asset. Arbitrage the spread:
# Example: BTC-USDT perpetual funding rates
exchange_rates = { # per-8h decimals (API-native)
"OKX": 0.00015, # +0.015% per 8h
"Binance": 0.00020, # +0.020% per 8h
"Bybit": 0.00025, # +0.025% per 8h
}
# Strategy: short on highest funding (Bybit) + long on lowest funding (OKX)
# Net carry = 0.00025 - 0.00015 = 0.00010 per 8h (0.010%)
# Annualized: 0.00010 × 3 × 365 = 0.1095 → 10.95%
# Risk: execution cost + potential for rates to converge/flipDivergence signals (most powerful):
| Price Action | Funding Rate | Interpretation | Signal |
|---|---|---|---|
| Price making new highs | Funding declining | Longs not chasing → distribution | Bearish divergence |
| Price making new lows | Funding rising (less negative) | Shorts not pressing → accumulation | Bullish divergence |
| Price consolidating | Funding spiking positive | Leverage building without breakout | Squeeze risk |
| Price consolidating | Funding deeply negative | Shorts paying heavy cost to maintain | Short squeeze imminent |
Historical pattern statistics (BTC):
# Combined OI + Funding signal
def oi_funding_matrix(oi_change_24h_pct, funding_rate):
if oi_change_24h_pct > 5 and funding_rate > 0.0003: # funding > +0.03%
return "leveraged_long_buildup" # High risk, squeeze potential
elif oi_change_24h_pct > 5 and funding_rate < -0.0001: # funding < -0.01%
return "leveraged_short_buildup" # Short squeeze potential
elif oi_change_24h_pct < -5 and funding_rate > 0:
return "long_liquidation" # Forced long closing
elif oi_change_24h_pct < -5 and funding_rate < 0:
return "short_liquidation" # Forced short closing
elif abs(oi_change_24h_pct) < 2 and abs(funding_rate) < 0.00005: # |funding| < 0.005%
return "quiet_market" # Low conviction, wait
else:
return "mixed"# Funding rate history
# GET /api/v5/public/funding-rate-history?instId=BTC-USDT-SWAP
# Current funding rate
# GET /api/v5/public/funding-rate?instId=BTC-USDT-SWAP
# Open interest
# GET /api/v5/public/open-interest?instType=SWAP&instId=BTC-USDT-SWAPUse load_skill("okx-market") for OKX data retrieval patterns.
| Metric | Source | Frequency | Alert Threshold |
|---|---|---|---|
| BTC funding rate (8h) | OKX / Binance | Every 8h | > +0.05% or < -0.03% |
| ETH funding rate (8h) | OKX / Binance | Every 8h | > +0.05% or < -0.03% |
| Annualized basis (quarterly) | OKX | Continuous | > 30% or < 0% |
| BTC open interest change | OKX | Hourly | > ±5% in 24h |
| Cross-exchange funding spread | Multi-exchange | Every 8h | Spread > 0.02% |
## Funding Rate & Basis Analysis — [Asset]
### Current Funding Rates
| Exchange | 8h Rate | Annualized | Regime |
|----------|---------|------------|--------|
| OKX | +0.015% | +16.4% | bullish_carry |
| Binance | +0.020% | +21.9% | bullish_carry |
### Basis Structure
- **Spot price**: $XX,XXX
- **Perp price**: $XX,XXX (premium: X.XX%)
- **Quarterly futures**: $XX,XXX (annualized basis: X.X%)
- **Basis regime**: [contango / flat / backwardation]
### Funding History (7-day)
- **Average**: +X.XXX%
- **Trend**: [rising / stable / declining]
- **Consecutive direction**: [X periods positive/negative]
### Open Interest
- **Current OI**: $X.XB
- **24h change**: [+/-X%]
- **OI × Funding signal**: [leveraged_long_buildup / quiet / etc.]
### Carry Trade Opportunity
- **Best carry**: [short on Exchange X, long spot]
- **Expected annualized yield**: X.X%
- **Risk**: [funding flip probability, liquidation distance]
### Directional Signal
- **Funding regime**: [overheated / bullish / neutral / bearish / oversold]
- **Divergence**: [none / bullish / bearish]
- **Confidence**: [high / medium / low]8643fcd
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.