betting_combat.feeds.market_data
market_data.py — the market data feed: every trade and every minute of every market in the
catalog, on our market ids (the books, and US trades, are recorded live: live.recorder).
MarketDataFeed ``build`` (a date range: the history), ``update`` (the recent past)Sources per venue (docs/BASE_TABLES.md):
Kalshi trades (archive before the cutoff, live after: a window across the cutoff
is asked on both paths; complete back to 2025-05), 1-minute candles (active
minutes only), books from the WebSocket
Polymarket intl trades (the data API, both tokens: priced as our YES), 1-minute history
(the legacy CLOB route, a week a call), books from the market socket
Polymarket US 1-minute quote history: the venue’s long and short prices, two asks (they
sum to 1.04 on average, an empty book shows 0.97 on both: found 2026-11-10),
so our side’s minute is ask = its price, bid = 1 - the other side’s, no
last; trades and books only with Sam’s key
Every price lands as our YES’s (0-1). Reruns write nothing new: trades are keyed by the
venue’s id, minutes by (market, minute); books are appended as received (the live record).
A minute lands when it changes (_changes): a minute missing inside a read window is the
last stored one’s prices with no volume (the venues’ histories repeat a flat minute: 96% of
Polymarket’s, 41% of Kalshi’s; found 2026-11-10 when the repeats filled the disk).
A build lands every CHUNK markets as they finish (no market waits on another), reports a
market (or a US span) that failed (failed) and goes on. What a market’s history was read
through (trades and minutes both, nothing failed) lands in market_reads; a build skips a
market read through its close + PAD (resume), so only the failed and the unfinished are
asked again. A market without a close of its own (Polymarket US) closes with its fight: the
fight over, the day after its card (CARD_OVER).
Classes
MarketDataFeed
Bases: Feed
Trades, minutes and books of the catalog’s markets.
build
build(start: dt.datetime, end: dt.datetime, resume: bool = True) -> dict[str, int]Every market listed or closed in start .. end: its trades and its minutes.
resume: a market already read through its close + PAD is skipped.
load
load() -> list[Market]update
update(hours_back: int = 48) -> dict[str, int]Markets open now or closed in the last hours_back: their recent trades and minutes.