Detect Stale Quotes in a Paper Strategy Test
A quote that has not changed in two minutes is not automatically wrong. It might be a quiet market with no new trades, or it might be a dead feed that stopped delivering. Your paper strategy cannot tell the difference unless you make it. This post covers three things: the two different ages every tick carries, how to pick a freshness rule on purpose instead of by accident, and why recording a gap beats pretending the last quote still holds.
Two clocks, two kinds of age
Every quote has at least two timestamps that matter, and confusing them is the most common way staleness checks go wrong.
- Observation age: how old the price is according to the venue. This is the exchange's own timestamp on the quote or trade, the moment the book changed on their side.
- Receipt age: how long since your worker last received anything at all. This is your local clock minus the last message you processed, regardless of what the message said.
These diverge. A market can be genuinely idle, so observation age grows while messages (heartbeats, unrelated channel traffic) still arrive and receipt age stays near zero. The reverse is worse: your socket silently drops, no messages arrive, and the last quote you cached looks perfectly valid because you are only reading its price, not asking when it landed.
Kalshi's WebSocket ticker payloads give you the venue clock directly. Older messages carried ts in Unix seconds and time as an RFC3339 datetime; Kalshi has since added millisecond ts_ms fields to non-margin messages while keeping the seconds and RFC3339 fields for now, and has marked the older ticker.ts, ticker.time, trade.ts and similar fields deprecated in its AsyncAPI docs. If you parse these yourself, read the current field, not a removed one.
Idle market versus disconnected worker
The signal that separates a quiet market from a dead connection is the heartbeat, and Kalshi is explicit about it. Kalshi sends WebSocket Ping frames every 10 seconds with the body heartbeat, and clients respond with Pong. The practical consequence: if those pings stop arriving, the connection is dead and you should reconnect, independent of whether any price changed.
So you actually have three states, not two:
- Live and quiet: heartbeats arriving, receipt age low, observation age high. The price is real but old because nobody traded. Acting on it may be fine, or you may choose to stand aside.
- Disconnected: heartbeats stopped, receipt age climbing past your tolerance. The cached price is unverifiable. Treat it as missing.
- Live and active: both ages low. Normal operation.
A single threshold on price-change age cannot distinguish the first two. You need the receipt clock and the heartbeat, measured separately from the quote's own timestamp. Note that some well-behaved clients delegate ping handling to the library: the Python websockets library, for example, answers ping/pong automatically, which keeps the socket alive but means your strategy code never sees those frames. If the library handles liveness, track receipt age at the layer that still sees message arrivals.
Choose a freshness rule, do not inherit one
There is no universally correct staleness threshold. The right number depends on how fast your market moves and how much slippage a stale fill would cost you. A 90-second-old quote on a slow weekly settlement market may be fine. The same age on a fast-moving event is a trap. Pick the rule deliberately and write it down as part of the experiment, because it changes what your results mean.
A workable rule has three independent limits rather than one:
- Max observation age: refuse to treat a quote as actionable if the venue timestamp is older than X seconds.
- Max receipt age: flag the worker as possibly disconnected if nothing has arrived in Y seconds, calibrated against the 10-second heartbeat interval so one or two missed pings trip it.
- Explicit missing-quote handling: decide up front what happens when bid or ask is absent, not just when it is old.
The following is a hypothetical rule with chosen inputs, not a recommendation or a tested parameter. Suppose heartbeats arrive every 10 seconds. Setting max receipt age to 25 seconds trips after roughly two missed pings; setting max observation age to 60 seconds is a separate judgment about how stale a price can be before you stand aside. Those two numbers answer different questions and should not be collapsed into one.
Record the gap, do not paper over it
The failure mode that quietly corrupts results is carrying the last good quote forward and valuing positions against it as if it were current. In a backtest that inflates confidence; in forward paper it produces fills that could never have happened. The discipline is to preserve missing data as missing. When a quote is absent or past your freshness limit, log that state and let valuation reflect the uncertainty, rather than substituting the stale number and moving on.
This mirrors how careful feed clients are built. One open-source async Kalshi client, for instance, preserves unknown WebSocket message kinds as a raw variant so applications can log or handle newly introduced events instead of dropping them. The same instinct applies to gaps: an unexplained silence is information, and throwing it away is a modeling choice you did not mean to make.
Where this fits in a paper workflow
If you are testing on Banger, this matters because a paper result is evidence under a specific data, fill, fee and valuation model, not proof of real execution. Banger is a paper-research beta: it runs code-first strategies against current Kalshi and Polymarket market data without venue keys, and public live deployment is blocked. Hosted historical backtesting currently supports Kalshi binary markets. The strategy callback is on_market_tick(self, market, tick, ctx), tick prices are Decimal, bid and ask can be absent, and the tick timestamp is a datetime. That absent-quote case and that timestamp are exactly the inputs your freshness check consumes.
A couple of simulation details sharpen why staleness handling is not optional. The public 0.1.7 forward-paper context can fill a non-crossing requested limit at that limit and logs paper.fill.resting-assumed when it does, and missing quotes can trigger a price fallback. If you feed a stale or fallback price into a sizing decision and the simulator fills it, your recorded P&L reflects a world that did not exist. Inspect the actual result model to see which assumption produced a given fill, rather than assuming every fill walked a live book.
To check behavior locally, run an existing file with banger run strategy.py --paper after account setup, watch it under supervision, and Ctrl+C to stop; that creates a local paper record. Deliberately choose and preserve one exact current market ticker for the run, because taking whatever a discovery call returns first does not make the test reproducible. Stopping preserves your research history and says nothing about any real account, since there is no live order path here to begin with.
The short version
- Measure observation age (venue clock) and receipt age (your clock) separately. They answer different questions.
- Use the heartbeat to tell an idle market from a dead connection. Kalshi pings every 10 seconds; stalled pings mean reconnect.
- Set the freshness thresholds on purpose and record them with the experiment.
- When a quote is missing or stale, log it as missing and let valuation show the uncertainty. Never carry a dead price forward as if it were fresh.
Sources
- API Changelog - Kalshi API Documentation (ticker ts_ms added; ticker.ts, ticker.time, trade.ts deprecated)
- Connection Keep-Alive - Kalshi API Documentation (Ping every 10 seconds, body heartbeat)
- WebSocket Channels: Timestamp Conventions - Kalshi API Documentation (event contract ts in Unix seconds and time as RFC3339; margin ts_ms)
- Quick Start: WebSockets - Kalshi API Documentation (Python websockets auto ping/pong)
- kalshi-pmx 0.1.1 WebSocket message types (unknown kinds preserved as Raw)
- Banger - Polymarket & Kalshi Paper Strategies
- bangertrades 0.1.7 - PyPI