Skip to content

betting_combat.features.book_tops

book_tops — features.book_tops: the top of Kalshi’s book at every change, the tick-level quote series. The raw book (ufc.books) is every level’s new size, snapshots and deltas; this replays it per market and keeps the best YES bid and the best NO bid (YES ask = 1 - the best NO bid) with their sizes each time either moves. Kalshi’s book is recorded only on the cards the recorder ran (2026-10-10 on); the trades (ufc.trades) are the other tick-level series and need no table: they are already one row a print.

BookTopsTable NAME book_tops, KEY (market_id, at), DATE date
market_id, bout_id, kind, date
at the change's time: Kalshi's ``exchange_ts`` (a snapshot carries none: our receipt time)
received_at when it reached us
yes_bid, yes_bid_size, no_bid, no_bid_size the best of each side after the change (blank: that side empty)
yes_ask 1 - no_bid: the price a YES buyer pays (its size is ``no_bid_size``)
snapshot the row is a subscription's snapshot (the book read whole)

Kept per fight from WINDOW_BEFORE before its first bell to WINDOW_AFTER after its end (the replay runs from each market’s first row, so a window opens on the book as it stood). Several changes at one moment: the last state. Built a card day at a time (the book is the bulk of the base: 22M rows inside fights on 6 cards).

Classes

BookTopsTable

Bases: FeatureTable

features.book_tops: Kalshi’s top of book at every change, inside the fights (module doc).

build

build(db: DBClient, base: Base | None = None) -> dict[str, int]

Every card day the book was recorded on, one at a time.

compute

compute(base: Base) -> pd.DataFrame

day

day(db: DBClient, day: dt.date) -> pd.DataFrame

One card day’s tops: each market’s book replayed, kept inside its fight’s window.

update

update(db: DBClient, since: dt.date, base: Base | None = None) -> dict[str, int]

Functions

replay

replay(rows: pd.DataFrame) -> pd.DataFrame

One market’s book rows (sorted by received_at, seq) -> the top after every change that moved it: at, received_at, yes_bid, yes_bid_size, no_bid, no_bid_size, snapshot. A snapshot (rows sharing one receipt time, is_snapshot) starts the book afresh; a delta sets a level’s size (0 removes it).