How to Code Betfair Exchange API Bots: Execution Systems Under Low Liquidity
Low liquidity on the Betfair Exchange is a brutal execution environment that destroys naive bots within minutes, because the order book thins out and your fill assumptions collapse. If your code still treats the market as a deep, forgiving pool, you are already bleeding money. The real battle is engineering an execution system that survives when matched volume dries up and every tick becomes a psychological war against stale prices and phantom liquidity.

Why Thin Books Break Standard Execution Logic
Most developers wire their bot to fire marketable orders and expect a clean fill at the best available price. That logic is fantasy under low liquidity. When the book is thin, a single marketable order can walk the ladder three or four levels deep, and your average fill price diverges catastrophically from the quoted top-of-book. This is the core reason execution systems under low liquidity must be re-engineered from the order-routing layer up, not patched with a wider slippage parameter.
The Exchange API returns a price ladder that looks tradeable but hides the real story: the size sitting at the second and third level may be spoofed, withdrawn, or simply gone by the time your packet lands. A bot that trusts the ladder snapshot as a guaranteed executable price is gambling, not trading. You need to treat every price level as conditional and every fill as a probabilistic event. 🎯
Order Type Selection Is a Survival Decision
Stop defaulting to market orders in thin markets. The correct approach is a disciplined ladder of limit orders placed just inside the spread, with aggressive cancellation logic that pulls liquidity the instant the book degrades. In low-liquidity conditions, a passive limit order often sits unfilled for minutes, which means your Betfair Exchange API bot needs a timeout mechanism that cancels and re-prices without thrashing the rate limiter.
Here is the hard truth most coders miss: the Exchange punishes overtrading with throttling, and a bot that cancels and replaces every 200 milliseconds will get its requests queued or rejected. Build a cancellation budget. Track how many order actions you consume per second and throttle your own re-pricing logic well below the hard limit. A bot that respects its own rate budget fills more reliably than one that spams the endpoint and gets silently starved.

Handling Partial Fills and Residual Risk
Partial fills are the norm, not the exception, when liquidity is scarce. Your execution system must track residual exposure from every partial fill and reconcile it against the intended position size in real time. A naive bot that assumes full fills will accumulate hidden directional risk that only surfaces when the market moves against the position. This is where algorithmic execution discipline separates professionals from hobbyists.
Implement a position ledger that updates on every fill event stream message, not on polling. Polling introduces latency that makes your residual risk calculation stale, and in a thin market, stale means wrong. When a partial fill lands, immediately recalculate the remaining size and decide whether to chase, hold, or abandon. That decision logic must be deterministic and fast, because the window to act closes in seconds. âš¡
Latency, Snapshot Staleness, and the Matching Engine Race
Every millisecond between your price snapshot and your order arrival is a window where the book can shift. Under low liquidity, that window is lethal because a single competing bot can pull the size you were targeting. The fix is to reduce reliance on stale snapshots and instead react to the fill and order-change stream directly, placing orders that are valid at the moment of submission rather than at the moment of calculation.
Co-locate your execution logic geographically close to the matching infrastructure, and strip every unnecessary network hop from the order path. A bot that computes a beautiful price but arrives 40 milliseconds late is a bot that fills at the wrong price or not at all. Measure your round-trip latency continuously and treat it as a first-class metric. If your order-to-ack latency drifts upward, your fill quality collapses proportionally, and no amount of clever pricing logic saves you. 🔧
Backtesting Must Simulate Liquidity Starvation
Standard backtests assume your order fills at the quoted price with infinite size, which is the single biggest lie in bot development. You must simulate liquidity starvation: model scenarios where only 20 percent of your intended size fills, where the book vanishes mid-order, and where your own order impact moves the price against you. A backtest that does not stress-test execution under thin conditions is worse than useless because it breeds false confidence.
Feed your simulator real historical order book snapshots and replay them tick by tick, injecting your order at the exact timestamp it would have arrived. Count how often you would have been filled, at what average price, and how much residual exposure you would have carried. The bots that survive live trading are the ones whose simulation already punished them for every optimistic assumption. ðŸ§
Circuit Breakers and Kill Switches for Thin Markets
When liquidity evaporates entirely, the correct action is to stop trading, not to widen parameters and hope. Build a circuit breaker that detects abnormal book conditions — sudden spread blowouts, volume collapse, or repeated partial fills at degraded prices — and halts order submission automatically. A bot without a kill switch will keep firing into a dead book and accumulate losses that no recovery logic can undo.
The breaker must trigger on measurable thresholds: if the top-of-book size drops below a defined floor, or if your fill rate falls below a minimum ratio over a rolling window, the system goes flat and waits. Re-entry requires the book to recover to healthy depth. This is not caution; it is the only rational response to a market that has stopped offering you a fair game. â›”
The difference between a profitable bot and a blown account under low liquidity comes down to how honestly your execution code models the market's refusal to fill you at the price you see.