Skip to main content

What We’re Building

A spot-futures arbitrage strategy that:
  • Buys on Binance spot when the futures premium is high
  • Sells short on Binance futures to hedge the position
  • Uses VenueAwareSizing to allocate capital across venues
  • Uses TotalEquityCalculator to track combined equity
  • Uses PairIdGenerator to link spot and futures legs atomically
This is an advanced tutorial. Make sure you understand First Strategy and Multi-Factor before proceeding.

Step 1: Multi-Venue Setup

Cross-exchange strategies need multiple entries in SymbolSourceMap and multiple AccountSpec entries:

Step 2: Price Inputs

Each venue has its own FIELD inputs:

Step 3: Arbitrage Signal

Compute the futures premium (basis) as the arbitrage signal:
Create a custom operator for the basis calculation, or use a combination of built-in operators. Here’s the concept using a custom operator:

Step 4: Per-Venue Equity

Track equity for each venue separately, then combine:
TotalEquityCalculator sums equity from all venue-level calculators, giving you a portfolio-wide equity figure for risk management and position sizing.

Step 5: Venue-Aware Position Sizing

VenueAwareSizing allocates capital across venues based on the arbitrage signal:
Allocation modes:
  • "equal" — Equal split across venues
  • "proportional" — Split based on allocation_ratio
  • "inverse_hedge" — Spot long, futures short (or vice versa based on signal direction)
How it works:
  1. Takes the arbitrage signal (per symbol)
  2. Allocates total equity to each venue based on config
  3. For inverse_hedge: positive signal → buy spot, sell futures; negative → opposite
  4. Outputs target notional per axis_key across all venues

Step 6: Pair ID Generation

Link spot and futures legs so they execute atomically:
PairIdGenerator creates a unique pair ID when the same symbol has active signals on multiple venues. This tells the executor to execute both legs atomically — if one leg fails, the other is cancelled.

Step 7: Order Intentions

Create separate intentions for each venue, referencing the shared sizing output:

Step 8: Configure and Run

The Complete Graph

Multi-Exchange Variant

The same pattern works across different exchanges:
Each exchange is independently simulated with its own fees, margin rules, and funding rates.

Key Considerations

Funding rate arbitrage

For spot-futures basis trading, the main return comes from collecting funding rates. When futures trade at a premium:
  • Long spot (earn the asset)
  • Short futures (collect positive funding every 8 hours)
  • Net return ≈ funding rate × time
See Funding Rate Simulation for how funding is modeled in backtest.

Execution risk

  • Leg risk: One leg fills but the other doesn’t. PairIdGenerator mitigates this by linking legs
  • Timing: In live mode, both orders are submitted simultaneously
  • Slippage: Use LATENT mode backtest to estimate realistic execution costs

Capital efficiency

Supported Exchanges

Exchange matrix with fees, leverage, and data

Funding Rates

How funding rate simulation works in backtest

Liquidation Logic

Per-exchange margin and liquidation rules

Code Parity

Same arb strategy runs from backtest to live