Perp Funding Basis logo

Perp Funding Basis

OrganizationPopular
HKUDS
perp-funding-basis

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.

Overview

PublisherHKUDS
RepositoryVibe-Trading
Skill nameperp-funding-basis
Stars
33.6K
Forks
5.5K
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by HKUDS on GitHub. Read the source before you install it.

Installation

Install the Perp Funding Basis AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git /tmp/Vibe-Trading
mkdir -p .claude/skills
cp -r /tmp/Vibe-Trading/agent/src/skills/perp-funding-basis .claude/skills/perp-funding-basis
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Perp Funding Basis in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Perp Funding Basis on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Perp Funding Basis is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Perpetual Funding Rate & Basis Trading

Overview

Analyze 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.

Core Concepts

1. Funding Rate Mechanics

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 longs

OKX funding rate schedule: payments at 00:00, 08:00, 16:00 UTC

Annualized funding rate:

python
# 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% annualized

Units 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).

2. Funding Rate Signal Framework

Funding Rate (8h)AnnualizedMarket StateSignal
> +0.05%> +54.75%Extreme long crowdingContrarian short / reduce longs
+0.02% to +0.05%+21.9% to +54.75%Elevated long biasCautious, carry trade viable
+0.005% to +0.02%+5.5% to +21.9%Mild long biasNeutral to mild bullish
-0.005% to +0.005%-5.5% to +5.5%BalancedNeutral
-0.02% to -0.005%-21.9% to -5.5%Mild short biasNeutral to mild bearish
< -0.02%< -21.9%Short squeeze territoryContrarian long / reduce shorts

Funding rate regime detection:

python
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"

3. Spot-Futures Basis Analysis

Basis = Futures price - Spot price

For dated futures (quarterly), basis reflects cost-of-carry expectations:

python
# 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 BasisMarket StateSignal
> 30%Extreme contango, euphoric leverageSell basis (cash-carry), top warning
15-30%Elevated contango, bullish leverageCarry trade attractive
5-15%Normal contangoNeutral, mild bullish
0-5%Flat basisLow conviction, wait for direction
< 0% (backwardation)Bearish, forced sellingContrarian long, extreme pessimism

4. Cash-Carry Arbitrage (Delta-Neutral)

Strategy: buy spot + sell perpetual futures → collect funding rate

python
# 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:

  1. Buy spot BTC-USDT on OKX spot market
  2. Open equal-sized short BTC-USDT-SWAP on OKX perpetual
  3. Net delta = 0 (spot long cancels perp short)
  4. Collect positive funding rate every 8 hours
  5. Close both legs when funding rate turns negative or basis compresses

Risk factors:

  • Funding rate can flip negative → carry becomes a cost
  • Liquidation risk on short perp if insufficient margin (use 3-5x max leverage)
  • Exchange counterparty risk (keep position across 2-3 exchanges)
  • Basis can widen further before mean-reverting → mark-to-market loss on short leg

5. Cross-Exchange Funding Arbitrage

Different exchanges have different funding rates for the same asset. Arbitrage the spread:

python
# 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/flip

6. Funding Rate as Directional Indicator

Divergence signals (most powerful):

Price ActionFunding RateInterpretationSignal
Price making new highsFunding decliningLongs not chasing → distributionBearish divergence
Price making new lowsFunding rising (less negative)Shorts not pressing → accumulationBullish divergence
Price consolidatingFunding spiking positiveLeverage building without breakoutSqueeze risk
Price consolidatingFunding deeply negativeShorts paying heavy cost to maintainShort squeeze imminent

Historical pattern statistics (BTC):

  • Funding > +0.05% for 3+ consecutive periods → 70% probability of a 5-10% correction within 7 days
  • Funding < -0.03% for 3+ consecutive periods → 65% probability of a 5-15% bounce within 7 days
  • These are contrarian signals; funding rate extremes indicate crowded positioning

7. Open Interest × Funding Rate Matrix

python
# 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"

Data Access

Via OKX API

python
# 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-SWAP

Use load_skill("okx-market") for OKX data retrieval patterns.

Key Metrics to Track

MetricSourceFrequencyAlert Threshold
BTC funding rate (8h)OKX / BinanceEvery 8h> +0.05% or < -0.03%
ETH funding rate (8h)OKX / BinanceEvery 8h> +0.05% or < -0.03%
Annualized basis (quarterly)OKXContinuous> 30% or < 0%
BTC open interest changeOKXHourly> ±5% in 24h
Cross-exchange funding spreadMulti-exchangeEvery 8hSpread > 0.02%

Output Format

## 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]

Notes

  • Funding rates are exchange-specific; always compare across OKX, Binance, and Bybit for the full picture
  • Extremely high funding rates are a cost for longs, not a bullish signal — they indicate overcrowded positioning
  • Cash-carry trades have execution risk: slippage on entry/exit, funding rate flipping, and exchange downtime during volatility
  • Basis and funding rate signals work best when combined with on-chain data (MVRV, exchange flows)
  • This framework is for research purposes only and does not constitute investment advice

Frequently asked questions

What does the Perp Funding Basis AI skill do?

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.

Why use Perp Funding Basis on TypingMind?

Because you install it once and use it with any model. Perp Funding Basis is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Perp Funding Basis in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/perp-funding-basis. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Perp Funding Basis?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Perp Funding Basis?

As many as you like. As long as a model supports skills, you can use Perp Funding Basis with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Perp Funding Basis AI skill free?

Yes. It is published on GitHub by HKUDS under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇