Handle Missing Bid and Ask Values in Paper Research
If you write prediction-market strategies, the first bug you hit is almost never your signal. It is a tick that arrives with no bid, no ask, or a price your code reads as zero. Handle that case wrong and your logic either crashes, skips good markets, or worse, treats a missing quote as a real price of zero and acts on it.
This post is about the difference between a null quote, a one-sided book, and an actual zero, and how to reason about them inside a paper research loop before you ever assume a fill. It uses the verified Banger SDK tick semantics and the current Kalshi order book structure. No live execution is implied anywhere here. Banger paper research runs against current market data without venue trading keys, so everything below is observation and simulation, not real orders.
Null is not zero, and zero is a real price
A binary prediction contract trades between $0 and $1. That means a quote of exactly $0.00 or $1.00 is, in principle, a valid price. It usually signals that the market has effectively resolved or that one side has no interest, but it is a number your code can compare against.
A missing quote is a different object entirely. It means there is no information at all: no resting interest to buy, no resting interest to sell, or a feed gap. In the Banger SDK, tick prices are Decimal and bid or ask can be absent. Absent is not the same as Decimal("0"). If you coerce a missing value to zero somewhere in your pipeline, you have manufactured a price that no one quoted.
The practical rule: check for presence before you check for value. A None-or-absent guard comes first. Only after you confirm a side exists do you compare its magnitude.
Why Kalshi books are one-sided by design
On Kalshi you will see one-sided books constantly, and it is not a bug. Kalshi's binary markets are built on a complement: a YES contract and a NO contract sum to one dollar. Because of that, the order book API returns yes bids and no bids only, with no asks returned directly.
A bid for YES at price X is equivalent to an ask for NO at the complementary price (1 minus X). The ask you want is derived, not sent. You reconstruct the other side from the opposite book.
- A YES bid at 42 cents is equivalent to a NO ask at 58 cents.
- A NO bid at 56 cents implies a YES ask at 44 cents, which is your best visible immediate YES purchase.
- If only one side of the book has resting interest, the complementary side still gives you a derived ask, but the direct bid on that side is genuinely empty.
So a market can legitimately have a best YES bid and no depth on the NO complement, or the reverse. Your strategy has to decide what each absence means before it reasons about edge.
Three cases your tick handler must separate
When a tick arrives, there are three distinct states, and collapsing them is the root of most false signals.
- No executable quote: the side you need is absent. There is nothing to lift or hit. This is a wait-or-skip, not a trade input.
- A real boundary price: a side quotes 0 or 100 cents. That is information about resolution or one-sided conviction, and it is a number, but acting on it is a deliberate decision, not a default.
- A normal two-sided quote: both the bid you care about and the derived ask exist. Only here do you have a spread and a mid to reason about.
Worth noting: two separate reads of a fast book can disagree. A market snapshot from the REST endpoint and a direct orderbook read, fetched back to back, can return different top-of-book values, especially in fast in-play markets. Treat the snapshot price and the orderbook response as two reads of a moving target, not one consistent source of truth.
A defensive pattern, in plain terms
Inside Banger, the strategy callback is on_market_tick(self, market, tick, ctx), with an optional on_start(ctx). The tick carries Decimal prices, a datetime timestamp, and bid or ask fields that may be absent. The defensive order of operations is always the same:
- Guard presence first. If the side you need is absent, return early and do nothing.
- Then guard range. A price at the 0 or 1 boundary is valid but exceptional; handle it on purpose.
- Only then compute spread, mid, or edge, and only from sides that actually exist.
- Never fund a decision with a value you had to invent to replace a missing one.
Here is the shape of that guard, written against the verified callback signature. It makes no order and asserts no fill. It only decides whether a tick is usable. Field names on the tick object are illustrative of the pattern; inspect your actual tick model.
async def on_market_tick(self, market, tick, ctx):
# 1. presence before value: absent is not zero
if tick.yes_price is None:
return # no executable YES quote this tick
price = tick.yes_price # Decimal
# 2. boundary prices are valid but exceptional
if price <= 0 or price >= 1:
return # resolved / one-sided; handle deliberately, not by default
# 3. only now is it safe to reason about a real quote
# (spread, mid, edge) using sides that actually exist
...That early return on a missing side is the whole point. It is cheap, and it stops a null from propagating into a comparison that silently treats it as a tradable zero.
What a paper result does and does not prove
Observing quotes and simulating logic is not the same as executing. In Banger paper research, a result is evidence under a particular data, fill, fee, and valuation model, not proof of profitable or real venue execution. The forward-paper context can fill a non-crossing requested limit at that limit and will log that it assumed a resting fill. Its quantity cap is based on reported volume, not full book depth or passive queue reconstruction. Missing quotes can trigger a price fallback.
All of that matters here because a feed-only test, one where you only inspect ticks and never model a fill, proves even less. It tells you your guards are correct and your market is quoting. It does not tell you a real order would have filled. Keep those claims separate in your own notes: a usable tick is not a fill, a simulated fill is not a real fill, and a marked value is not credited cash.
Build the missing-quote guard first, verify it against live ticks in a short supervised paper run, and inspect the actual result model rather than assuming how a gap was priced. The strategies that survive contact with real books are the ones that knew, on every tick, whether they had a quote at all.
Sources
- Get Market Orderbook - Kalshi API Documentation
- Orderbook Responses - Kalshi API Documentation
- Quick Start: Market Data - Kalshi API Documentation
- How to Read a Kalshi Order Book: Bid, Ask and Depth
- We rebuilt our Kalshi API starter from its own prompt. Live data found five bugs.
- Banger - Polymarket & Kalshi Paper Strategies
- bangertrades 0.1.7 - PyPI