Skip to content

betting_combat.trading.session

One fight night of strategy 4 (rounds), start to finish.

configs + the active rounds model ─► the card on Kalshi
─► restore everything recorded for this card ─► strategy 4's card plan
─► every poll: the live feed · the market's bell (``trading.bell``) · strategy 4's
decision at each round break · settle finished fights · record
─► every second while a bet is being worked: its next slice (``trading.working``)
─► the joint execution's in-round decisions: every minute end of a round after a joint
break, one take-now slice per order (``trading.rounds_joint``)
─► a row pricing with the primary's 'stats' variant: at each bell, one look at the live
feed for the round statistics (``rounds.live.round_feed``, in the background, at most
``bell_timeout_s``), and the break decides when it answers (``_stats_due``)
─► stop when every fight is over and settled, or the card window has passed

Paper and live share every line up to the executor. Nothing here trades on a guess: missing books, a stale feed, a missing model or a missing price becomes a recorded no-trade reason, and a database that cannot record stops the run. Monitoring (the Grafana tables) never stops a card: its failures are counted.

Classes

CardSession

run

run() -> SessionResult

SessionDeps

SessionError

Bases: RuntimeError

The run cannot trade safely (e.g. live mode without the Kalshi credentials).

SessionResult

StatsWait

A break waiting for its round’s statistics: the feed’s read in the background, what first decided the break and when the round ended by the feed’s clock.

Working

One decision’s bets being worked (trading.working): its record, the moment it was decided, the bets, the slices sent so far and every child order.

Functions

decided_settlements

decided_settlements(orders: Mapping[str, OrderRecord], settlements: Mapping[str, SettlementRecord], done: set[str], books: Mapping[str, BookTop], now: dt.datetime) -> dict[str, SettlementRecord]

Kalshi’s settlements, plus a provisional one for each filled order of a finished fight (done) whose market’s book already shows the result: YES bid >= DECIDED_HIGH (YES won) or YES ask <= DECIDED_LOW (YES lost), valued at that result. Any other order waits for Kalshi.

fight_start

fight_start(tracker: FightTracker) -> dt.datetime | None

The fight’s start on the feed’s clock: round 1’s anchor; for a fight this run first saw under way (a late join, a relaunch: _late_anchor), its earliest anchor less 6 minutes a round before it. A decision takes its window edges from the market’s bells (RoundsRunner.decide); this start only reaches its trade tape back far enough. None before any anchor.

late_bell

late_bell(prints: Sequence[Print], now: dt.datetime) -> dt.datetime | None

The market’s bell on a list of prints up to now: the start of its current collapse (bell.collapse) held HOLD, or None — also when the prints begin inside the collapse, whose moment was not read (2026-10-17, the card’s first fight: the feed showed round 2 nine minutes late, and once the window had slid past the collapse a lone 1c print in round 3 was taken for the bell).

mid_boundary

mid_boundary(now: dt.datetime, interval_s: int) -> dt.datetime

The in-round decision time at or before now: the last whole interval_s boundary of the minute (a divisor of 60; 60: the minute end).

mid_late

mid_late(interval_s: int) -> dt.timedelta

How late an in-round decision may still run: MID_LATE, at most half the interval.