This is the capstone. We assemble the whole course — market structure, perps, funding, the Greeks, risk, and the tooling — into one small, disciplined, delta-neutral crypto algo: a funding-capture bot. It does not predict BTC; it earns funding while staying market-neutral. Simple idea, demanding execution.
The architecture
Every systematic crypto strategy runs the same loop you have seen throughout:
- Fetch — funding rate, spot price, perp price (Lesson 11).
- Signal — is funding above your threshold (and/or the basis attractive)?
- Risk check — size the position, check leverage, liquidation distance, and your limits. This gate can veto the trade.
- Enter neutral — short the perp and buy an equal amount of spot, so price moves cancel and you are delta-neutral (Lesson 8).
- Monitor — collect funding each window, and exit when funding flips negative or your rules say so.
…re-checking every funding window, wrapped in a kill-switch that flattens both legs the instant anything looks wrong.
A runnable skeleton
import ccxt
def run_once(ex_spot, ex_perp, cfg):
funding = ex_perp.fetch_funding_rate(cfg.symbol)["fundingRate"]
spot = ex_spot.fetch_ticker(cfg.spot_symbol)["last"]
# 2. SIGNAL — only trade when funding pays us enough (annualised)
apr = funding * 3 * 365
if apr < cfg.min_apr:
return f"no trade — funding {apr:.0%} APR below threshold"
# 3. RISK CHECK (veto gate)
qty = size_position(cfg.capital, cfg.max_risk_pct, spot)
if leverage_for(qty, spot, ex_perp) > cfg.max_leverage:
return "skip — would exceed max leverage"
if liquidation_distance(ex_perp) < cfg.min_liq_buffer:
return "skip — liquidation too close"
# 4. ENTER NEUTRAL — short perp + buy equal spot
ex_perp.create_order(cfg.symbol, "market", "sell", qty, params={"reduceOnly": False})
ex_spot.create_order(cfg.spot_symbol, "market", "buy", qty)
return f"entered delta-neutral funding capture, {apr:.0%} APR"
# main loop — runs 24/7
while True:
try:
log(run_once(ex_spot, ex_perp, cfg))
enforce_exits(ex_spot, ex_perp, cfg) # exit if funding flips
check_margin_and_liquidation(ex_perp, cfg)
except Exception as e:
kill_switch(ex_spot, ex_perp) # flatten BOTH legs, stop
alert(f"KILLED: {e}")
break
sleep(cfg.poll_seconds)As with the options course, notice how little of this is “clever”. The signal is two lines. The overwhelming majority is risk checks, margin monitoring, exits and the kill-switch — and that is exactly right. In a live crypto algo, the discipline is the strategy.
The realities that make or break it
- Keep leverage LOW. The short-perp leg uses margin; a sharp rally can liquidate it and leave you long spot only — now you are naked, directional, and losing. Low leverage and a big liquidation buffer are survival.
- Watch the liquidation price constantly. This is a 24/7 trade; margin must be monitored around the clock, with auto top-up or auto-exit before liquidation.
- Fees can eat the whole edge. Two legs, entry and exit, often on two exchanges — model every fee precisely. A 20% APR that becomes 5% after fees may not be worth the risk.
- Two venues, carefully. Spot on one exchange, perp on another means transfer latency and venue risk on both. A delay while moving collateral can leave you unhedged.
- Exit cleanly, together. When funding flips, close both legs. A kill-switch that flattens both at once is non-negotiable — a half-closed hedge is instantly a naked leveraged bet, which is exactly the thing you were avoiding.
- Start on a testnet, then tiny. Paper-trade the full loop for weeks, then one small position, scaling glacially.
The course in one line
Crypto takes the options and derivatives you know and drops them into a 24/7, 4–5× more volatile, largely unregulated, API-driven market — so the maths is familiar, the opportunities (perps, funding, basis, fat premium) are real, and the risks (liquidation, exchange failure, depeg, custody) can ruin you regardless of your analysis. Automate the boring parts like the programmer you are, keep leverage low and size small, prefer delta-neutral and defined-risk, and make survival the strategy.
You now have the foundations — crypto market structure, perps and funding, options, volatility, strategies, basis trades, DeFi, risk, and the tooling to build. Go and paper-trade on a testnet, patiently, and stay paranoid.
For more, revisit the Options Trading for Programmers course for the options fundamentals, the Low-Latency Trading Systems course for execution, the algo trading vocabulary, and position sizing with Kelly.