How do you know your local order book still matches the exchange?
Check the sequence numbers. Exchange feeds number their updates, so receiving 41 then 43 means one is missing and your local book is now wrong in a way nothing will announce. Detecting the gap and resyncing from a snapshot before the book is used again is the only reliable guard.
System architecture · Arbitrage Engine
What a gap actually does to you
It creates a price that is not there. If the missing update removed liquidity at the best level, your local book still shows it, and a spread scanner comparing two venues sees an opportunity that closed before you knew about it.
The engine then trades into it. The order is real, the fill is real, the loss is real, and the opportunity never existed. Nothing in the system errored at any point.
Why you cannot just carry on
Because the error does not decay. A missing update leaves your book permanently divergent from the venue at that price level until something rebuilds it, and subsequent updates apply on top of a wrong foundation.
So a gap is not a degraded state you can trade through more cautiously. It is a state where your view of the market is unreliable, and the only correct response is to stop using that venue's book until it is whole again.
How resync works
Request a fresh snapshot of the book, which arrives stamped with the sequence number it was taken at. Meanwhile keep buffering the live updates still arriving.
Then discard buffered updates older than the snapshot and replay the rest on top of it. The book is now current and contiguous, and trading on that venue can resume. Until that completes, the venue is out.
What else depends on book integrity
More than the spread calculation. Position sizing reads depth to estimate what a given size would actually cost, and risk checks use the same numbers to decide whether a trade is within limits.
A wrong book therefore does not only produce a phantom opportunity, it produces a wrongly sized trade against it. The two errors compound rather than cancel.
How we have used it
Our cross-exchange arbitrage engine is written in Go with pluggable adapters per venue, holding L20 books in memory per exchange. Every update is checked for a gap before it is applied, and a gap forces a snapshot resync before that book is used again.
It sits alongside the other correctness measures: decimal-only money math with no floating point in the price path, explicit partial-fill recovery, and circuit breakers on loss, latency and error rate that can halt trading outright.
COMMON QUESTIONS /
Questions people also ask
What is a sequence number in an exchange feed?
A monotonically increasing identifier attached to each order-book update so consumers can verify they have received every change in order. It is the mechanism that makes a dropped message detectable rather than silent, which is why feeds that lack one are much harder to trust.
How do you resync an order book after a gap?
Request a fresh snapshot while continuing to buffer live updates, then discard buffered updates older than the snapshot's sequence number and replay the remainder on top. The result is a contiguous, current book. Trading on that venue should stay paused until it completes.
Is L20 depth enough for arbitrage?
For most sizes, yes. Twenty levels each side is enough to estimate the cost of a trade that is not enormous relative to the book. What matters more than depth is that the levels you do hold are accurate, which is what gap detection protects.
What happens if you trade on a stale order book?
You act on prices that no longer exist. The trade executes at whatever the venue actually offers, so the loss is the difference between the phantom opportunity and reality. Because nothing errors, this can continue indefinitely until someone notices the cumulative loss.