> youcanbuildthings.com
tutorials books topics about

Crypto Funding Rate Arbitrage Bot: BTC Cash and Carry

by J Cook · 8 min read·

Summary:

  1. A crypto funding rate arbitrage bot collects the funding payment that crowded perpetual longs pay to crowded shorts. Pure cash-and-carry, delta-neutral, no directional bet.
  2. Long spot, short perp at equal notional. Enter when funding rate exceeds 0.025% per 8 hours. Exit when funding drops below 0.005% or basis converges to within 5 bps.
  3. Worked example: $90K capital ($60K spot + $30K perp margin) at 0.04% funding nets +$62/day, $2,160/month, 28.8% annualized.
  4. Public REST endpoints (OKX, Binance, Bybit) return the funding rate live. Reader can call the same endpoint right now.

Most crypto funding rate arbitrage bot tutorials drift into DeFi yield farming, shitcoin chasing, or naked perp shorts. This one does not. It is a pure cash-and-carry trade on regulated centralized exchanges: long spot, short perp at equal notional, collect the funding every 8 hours, unwind when the rate mean-reverts. The strategy institutional crypto desks have been running for years, in 200 lines of Python.

A 30-day chart of BTC spot and BTC perp prices trading in tight tandem with a small persistent perp premium. Below it, the 8-hour funding rate plotted as a step function with horizontal entry threshold at 0.025% and exit threshold at 0.005%. Markers at May 2 entry and May 22 exit. P&L decomposition shows funding income +$72, spot fees -$6, perp fees -$4, net +$62 per day on $90,000 capital ($60,000 spot leg, $30,000 perp margin). Bottom: $2,160 per month, 28.8% annualized.

How does crypto funding rate arbitrage actually work?

Perpetual futures contracts have no expiry. To keep the perp price tethered to spot, exchanges require longs and shorts to exchange a periodic payment based on the gap between perp and spot. When perps trade at a premium (longs are crowded), funding is positive and longs pay shorts. When perps trade at a discount, funding is negative and shorts pay longs.

The trade: when funding is positive and above threshold, go long spot at notional X and short perp at notional X. The position is delta-neutral; long spot cancels the directional risk of the perp short. You collect the funding payment every 8 hours until the rate normalizes. Three settlements a day on most exchanges, so positive funding compounds quickly.

The strategy is not “free money,” and the standard objection is that institutions arb it out. They have. It still persists at retail size for two structural reasons. The trade requires capital on both legs plus margin on the short, which most retail accounts do not deploy at scale. And the bot has to actively rotate capital across instruments and exchanges to chase the highest rates, which most retail builders do not automate. Both gaps create persistent retail edges.

What is the entry threshold and the math behind it?

0.025 to 0.03 percent per 8-hour window is the threshold. The math: 0.03 × 3 settlements per day × 365 days = 32.85 percent annualized, ignoring compounding. That is the floor where the trade is worth the capital lock-up plus exchange fees plus the small slippage on entry and exit. Below 0.025%, the annualized return drops below the cost of capital and you are better off in a money-market fund.

A worked example. BTC perp funding hits 0.04% per 8-hour window. That is 0.04 × 3 × 365 = 43.8% annualized. Open a 1-BTC notional basis trade: long 1 BTC spot, short 1 BTC perp at 2x margin on the short leg. At a $60K BTC price:

  • Spot leg: $60,000 of capital
  • Perp short margin: $30,000 (2x margin posted on the short leg)
  • Total capital deployed: $90,000

Each 8-hour window pays you 0.04% of $60K notional, which is $24. Three settlements a day equals $72 a day in gross funding. Subtract spot fees ($6/day) and perp fees ($4/day), and you net $62/day. Over 30 days, $2,160. On the $90K of deployed capital, that is roughly 28.8% annualized.

The math is real. The math is also bounded by funding mean-reversion. The typical lifecycle is 24 to 72 hours, not 30 days; the May 2 to May 22 example above is an unusually durable funding regime. Plan for shorter cycles and faster turnover.

How do I scan funding rates from a public endpoint?

The exchanges expose funding-rate data on public REST endpoints with no auth required. OKX is the cleanest example because Binance and Bybit are geo-blocked from some regions (OKX docs):

curl -s "https://www.okx.com/api/v5/public/funding-rate?instId=BTC-USDT-SWAP"

Response (verbatim, fetched live):

{
    "code": "0",
    "data": [
        {
            "instId": "BTC-USDT-SWAP",
            "instType": "SWAP",
            "fundingRate": "-0.0000221357971929",
            "fundingTime": "1778140800000",
            "nextFundingTime": "1778169600000",
            "premium": "-0.0005020037190006",
            "settFundingRate": "-0.0000200730970558",
            "maxFundingRate": "0.00375",
            "minFundingRate": "-0.00375",
            "method": "current_period",
            "settState": "settled",
            "ts": "1778112747204"
        }
    ],
    "msg": ""
}

Read the fundingRate field. In this snapshot it is -0.0000221, which is roughly -0.0022% per 8-hour period. Slightly negative; shorts pay longs. The bot waits. When the rate flips above +0.025% per 8h, the bot enters. The nextFundingTime (ms epoch) tells you when the next settlement fires.

For Binance and Bybit (when not geo-blocked), the equivalent endpoints are https://fapi.binance.com/fapi/v1/premiumIndex?symbol=BTCUSDT and https://api.bybit.com/v5/market/funding/history?category=linear&symbol=BTCUSDT. The schemas differ; the conceptual fields (current rate, next funding time, premium) are the same.

How do I open the basis trade atomically?

Two legs, simultaneously, with limit orders. Market orders on fast-moving crypto pairs split your fill across price levels and the basis you opened on is already off your intended entry. The fix:

import ccxt

def open_basis_trade(exchange, symbol_spot: str, symbol_perp: str, notional: float):
    """Long spot + short perp, equal notional, abort if either leg doesn't fill in 30s."""
    spot_price = exchange.fetch_ticker(symbol_spot)["last"]
    perp_price = exchange.fetch_ticker(symbol_perp)["last"]

    spot_qty = notional / spot_price
    perp_qty = notional / perp_price

    spot_order = exchange.create_order(symbol_spot, "limit", "buy", spot_qty, spot_price)
    perp_order = exchange.create_order(symbol_perp, "limit", "sell", perp_qty, perp_price)

    return {"spot": spot_order, "perp": perp_order, "notional": notional}

If both legs do not fill within 30 seconds, cancel and retry. Slippage between legs is the single biggest small-money killer in this strategy: a 25-basis-point gap between the spot fill and the perp fill eats a full week of funding income.

The position is delta-neutral by construction once both legs are filled. The Q33 line about “performance looks great until volatility hits” applies less here than in any other strategy in this book. A 10 percent drop in BTC moves both legs against each other; the net P&L is dominated by the funding payments.

When does the bot exit?

Three conditions, any one fires an unwind:

def exit_signal(funding_rate: float, basis_bps: float) -> str | None:
    """funding_rate is per-8h window; basis_bps is perp-vs-spot in basis points."""
    if funding_rate < 0.00005:  # below 0.005% per 8h
        return "funding_normalized"
    if abs(basis_bps) < 5:
        return "basis_converged"
    if funding_rate < 0:  # circuit breaker
        return "inversion_circuit_breaker"
    return None

Funding mean-reverts (most common). Within 24 to 72 hours of opening, the rate drops below 0.005% per window. The bot unwinds, books the funding, moves on.

Basis converges. Even before funding fully normalizes, the perp’s premium to spot can compress to within 5 basis points. The spread has paid out; close the trade.

Funding inverts hard (rare, dangerous). In a market shock, funding flips from +0.04% to -0.05% in 4 hours. Your short-perp leg starts losing money on the funding side AND the basis can blow out. Unwind immediately, take the slippage, exit. Do not wait for basis convergence in a market that has lost its reference price.

What broke

Three failure modes hit in production.

The two legs fill at different prices. Spot fills at $60,100 while perp fills at $60,250. The basis you opened on is 25 bps off your intended entry. Use limit orders at marked-to-mid prices instead of market orders, and abort if both legs do not fill within 30 seconds.

The short-perp leg gets liquidated. You sized at 2x margin; the underlying rallies 30% in 8 hours; the perp short is at risk. Strict 2-to-3x margin cap, never higher. Hard stop-out: close the entire basis trade if the short-perp’s mark-to-market loss exceeds 50% of the margin posted.

The exchange goes down. Binance has had multi-hour outages. Bybit has had partial API outages. Your spot leg is on Binance but you cannot close the perp short. Never run more than 50 percent of strategy capital on any single exchange. The exchange diversification is not optional; it is the single biggest counterparty-risk mitigation in the strategy.

What should you actually do?

  • If you are running funding-rate arb on one exchange today → split to at least two. The 2014 Mt. Gox failure and the 2022 FTX collapse were both regulated, “trustworthy” exchanges that lost user funds. The 50-percent-per-venue cap is not a suggestion.
  • If you are sized at 5x or 10x margin on the short → drop to 2-to-3x this afternoon. The funding rate is not “free” enough to justify a forced liquidation in a 20 percent rally.
  • If you are not running an inversion circuit breaker → ship one this weekend. A 4-hour funding flip in a crash will cost more than a week of normal-regime gains.
  • If your entry threshold is below 0.025% per 8h → raise it. Below that, the annualized return doesn’t pencil after fees and capital cost.
  • If you have no per-instrument cap → add one. No more than 33% of strategy capital on any single instrument; SOL funding is volatile and basis-divergence on SOL during shocks is the worst in the basket.

bottom_line

  • Cash-and-carry funding arbitrage is the boring, math-clean, delta-neutral edge that pays you for being patient. It is not DeFi, not yield farming, not directional. The simplicity is the strategy.
  • Slippage between legs is the small-money killer. Limit orders or no trade. Abort the trade if both fills do not land in 30 seconds.
  • The 50-percent-per-exchange cap is your single most important risk control. Funds get stuck in outages and exchanges fail; the cap is what turns a catastrophic event into a manageable one.

Frequently Asked Questions

What is funding rate arbitrage on crypto perpetual futures?+

When perpetual futures trade at a premium to spot, longs pay shorts every 8 hours via the funding mechanism. You go long spot at the same notional and short perp; the position is delta-neutral, and you collect the funding payments until the rate normalizes. Pure cash-and-carry, not DeFi.

What is the entry threshold for cash-and-carry crypto arbitrage?+

0.025 to 0.03 percent per 8-hour funding window. Below that, the annualized return drops below the cost of capital plus fees, and you are better off in a money-market fund. Above that, the carry is meaningfully higher than risk-free and the strategy starts paying.

What is the worst-case loss on a delta-neutral funding arbitrage?+

Counterparty failure (FTX risk) or short-leg liquidation in a sharp rally. The 50-percent-per-exchange capital cap and 2-to-3x margin ceiling on the short leg keep both bounded. The position itself is delta-neutral; price moves do not by themselves break the trade.