betting_combat.trading.rounds
Strategy 4 (rounds) inside the card run: the live side of rounds.live.
prepare (once, at the start of the run) the card's bouts linked to its Kalshi fights by the fighters' names; the Dataset 1 rows of every scheduled round start (``rounds.live.upcoming``) with the Kalshi card-start quotes as the pre-fight price; layer 1 on them. A fight that cannot be linked or priced is not traded.observe before each fight: its winner books (the ``mid_a`` of the round-0 row time, which every later row's ``chg_since_pre`` reads)decide at each round break — the fight clock's 'break' decision point, the first poll that shows round k+1 (``domain.fight``: the feed switches when the round starts) — and, with ``trade_round0``, when the feed first shows the fight live: the trades before now -> Set 3 -> layer 2 -> candidates -> meta -> size -> caps (``rounds.live.decision``) -> each bet's working order: its room and every instrument it may buy, at limits held at the quote + the cushion (the card run works it, ``trading.working``)The clock is the card run’s own (trading.tracker / domain.fight): the round anchors
are the moments the feed first showed each round, never the research’s clock (derived from
the result). The window edges are the feed’s start + 6k minutes.
Money: the card’s state is rebuilt from the run’s own orders and settlements at every decision (what this strategy staked per fight and on the card, what is still at risk, the settled P&L), so a relaunch resumes with the same caps. Every portfolio gate applies (kill switch, daily loss, drawdown), plus the strategy’s own daily stop on SETTLED P&L.
Data the run needs from outside (RoundsData): the UFC tables as of the card and the
card’s bouts before it starts. Without it (or without an active model version) the
strategy records why and does not trade.
Classes
FightLink
A Kalshi fight and its bout: swap when Kalshi’s fighter A (the first ticker) is
the dataset’s fighter B (a_slot_of decides who is A). On our ids (a card with an
identity) ufc_fight_id is the bout_uid and kalshi_a / kalshi_b the
fighter_uids of Kalshi’s A and B, the swap read from them, never from names.
FightPlan
KalshiRoundsData
RoundsMarketData on the run’s Kalshi desk (trades: the WebSocket mirror, else
REST) and REST (open interest).
minute_bars
minute_bars(tickers: Mapping[str, tuple[str, str]], fight_id: str, start: dt.datetime, until: dt.datetime) -> pd.DataFrameopen_interest
open_interest(market_id: str) -> float | Noneprints
prints(market_id: str, since: dt.datetime, until: dt.datetime) -> list[Print] | NoneMoment
One decision point of one fight.
MoneyLimits
Sam’s money controls in dollars (resolve_money).
RoundsData
Bases: Protocol
What the data layer supplies for a card run (SessionDeps.rounds_data).
history
history(card_date: dt.date) -> UfcTablesEvery UFC table as the research read it, holding nothing dated on or after
card_date (services.rounds_inputs.ufc_tables).
upcoming
upcoming(card_date: dt.date) -> UpcomingCard | NoneThe card’s bouts as UFCStats lists them before it starts (no results); the Kalshi quotes may be left out (the run takes them from the live books).
RoundsMarketData
Bases: Protocol
The Kalshi reads a decision needs beyond the books (trading.desks.KalshiDesk).
minute_bars
minute_bars(tickers: Mapping[str, tuple[str, str]], fight_id: str, start: dt.datetime, until: dt.datetime) -> pd.DataFrameThe markets’ minute panel to until (rounds_v2.minute_bars): the meta’s
inputs.
open_interest
open_interest(market_id: str) -> float | Noneprints
prints(market_id: str, since: dt.datetime, until: dt.datetime) -> list[Print] | NoneRoundsRunner
Strategy 4 for one card run.
card_state
card_state(orders: Mapping[str, OrderRecord], settlements: Mapping[str, SettlementRecord]) -> CardStateThis strategy’s money on the card in its mode now, from its orders (filled cost; an order whose fate is unknown counts at its limit) and their settlements, in the order they settled. Paper and live never mix.
decide
decide(m: Moment, quotes: Mapping[tuple[str, str], Quote], market: RoundsMarketData, portfolio: PortfolioConfig, orders: Mapping[str, OrderRecord], settlements: Mapping[str, SettlementRecord], reserved: Mapping[str, float] | None = None) -> tuple[DecisionRecord, list[BetPlan]]One decision: its record and its bets, each to be worked (trading.working;
none in shadow mode or on a no-trade). reserved: Kalshi fight -> the room of
its bets still being worked (counted on the card and the fight like stakes).
decide_mid
decide_mid(m: Moment, at: dt.datetime, quotes: Mapping[tuple[str, str], Quote], market: RoundsMarketData, portfolio: PortfolioConfig, orders: Mapping[str, OrderRecord], settlements: Mapping[str, SettlementRecord], reserved: Mapping[str, float] | None = None, others: Iterable[OrderRecord] = ()) -> tuple[DecisionRecord | None, list[BetPlan]]One in-round decision of the fight at the minute end at (MidPlan): the
break’s probabilities conditioned on no finish so far (the artifact’s finish clock),
the books now, each order at most the volume share of its market’s dollars in the
last minutes (others: the other strategies’ live orders of the card, whose fills,
like this run’s, are not the market’s); buys of the break’s candidates (mid_add),
sells of any holding (mid_cut below its cost, mid_take_profit at or above). A
record only when it trades (each minute that does not is counted in the findings).
gate
gate(portfolio: PortfolioConfig, state: CardState, s: Settings) -> Reason | NoneWhat stops a new bet (option A: strategy 4 answers to its own money controls only): the shared kill switch, and its stop loss on this card’s settled rounds P&L in its mode. The older strategies’ gates (bankroll cap, card loss, drawdown) never apply.
in_scope
in_scope(fight: Fight, round_idx: int) -> boolWhether the strategy decides the break after round round_idx: every break but
on the one execution, whose row names its breaks (RoundsConfig.breaks: the
scheduled rounds of the fight’s link, which Kalshi’s format must agree with - else the
last break is not known and only ‘all’ trades: a finding).
moment
moment(fight: Fight, round_idx: int, now: dt.datetime, start: dt.datetime | None, feed_age_seconds: float, round_end: dt.datetime | None = None, bells: Mapping[int, dt.datetime] | None = None, lines: pd.DataFrame | None = None) -> Moment | NoneThe decision point, or None when this strategy has none here. round_end: when
the feed’s clock says the round before ended (for the latency record); lines: the
live round statistics (the ‘stats’ variant).
observe
observe(fight_id: str, now: dt.datetime, book_a: BookTop | None, book_b: BookTop | None) -> NoneA pre-fight sample of the dataset’s A winner mid (Kalshi’s books A and B).
prepare
prepare(fights: Sequence[Fight], data: RoundsData, winner_books: Mapping[str, tuple[BookTop | None, BookTop | None]], prop_books: Mapping[str, Mapping[str, BookTop | None]] | None = None) -> NoneLink the card’s fights and build their pre-fight rows (in a worker thread: the
fighter histories take a while). winner_books: Kalshi fight id -> its two winner
books now (the card-start quotes, before any fight has started); prop_books: Kalshi
fight id -> role (‘distance’, ‘mof_ko’, ‘mof_sub’, ‘mof_dec’, ‘mof_draw’) -> its book
now, the primary’s card-start prices (rounds_v2.card_props; a fight without them
takes the clock’s history alone, as the research’s unpriced fights). The primary’s rows
are built whenever the model version carries it, whatever the row’s primary_model
(a switch during the card finds them ready); a failure leaves the strategy on layer 1
with a finding.
settings
settings(portfolio: PortfolioConfig) -> Settings | NoneThe decision’s settings now (None: no sizing bankroll, nothing trades).
wants_stats
wants_stats(round_idx: int, fight: Fight | None = None) -> boolThe break waits for the round’s statistics from the live feed: the row prices with
the primary’s ‘stats’ variant, the round has been fought and (fight given) the
strategy trades this break (in_scope).
warm
warm(fight_id: str, market: RoundsMarketData, now: dt.datetime) -> NoneKeep the fight’s trade tape current between decisions (every WARM_EVERY), so a
break reads only its last seconds: from the card run’s first sight of the fight, or
the start - 61 minutes once the fight has started.
StoreRoundsData
RoundsData on the rounds data layer: the UFC tables from its loader
(services.rounds_inputs.ufc_tables) with the three frames it does not land (the
bookmakers’ method odds, the sportsbook lines, the Kalshi card-start prices of past
fights) given as pd.read_csv read them; the card’s bouts from upcoming (None:
no card, the strategy off with a finding). The card run does not use this class: it is
wired with services.rounds_upcoming.StoreRoundsSource (trading.wiring), whose
upcoming is the upcoming-card loader (load_upcoming) and whose history is
every stored input as it stood before the card.
The upcoming card’s own Kalshi quote is not taken from fights_kalshi (no job derives
it for new fights): the run takes it from the live winner books (_with_quotes).
history
history(card_date: dt.date) -> UfcTablesEvery UFC table (with_upcoming refuses them if any holds a result on or after
the card’s date).
upcoming
upcoming(card_date: dt.date) -> UpcomingCard | NoneFunctions
card_ids
card_ids(card: UpcomingCard, fights: Sequence[Fight], links: Mapping[str, FightLink]) -> CardIdsThe card on our ids for the Cito link: its bouts and, per fighter, the registry’s name and spellings, the card’s name and Kalshi’s.
fighters_order
fighters_order(a: str, b: str, n1: str, n2: str) -> bool | NoneOn the one bout the loader linked by ticker: True when Kalshi’s fighter A (a) is
the bout’s fighter 1, False when fighter 2, None when the names cannot tell. The words
first (orientation); when they cannot tell, the spellings (same_fighter):
exactly one order must match both fighters. Never used to FIND a bout.
last_completed_card
last_completed_card(history: UfcTables, before: dt.date) -> dt.date | NoneThe date of the latest card before before with results in the UFCStats tables.
late_seconds
late_seconds(now: dt.datetime, bells: Mapping[int, pd.Timestamp], round_idx: int) -> floatThe seconds of round round_idx + 1 gone at now (its start: the bell of round
round_idx + 60 s); 0 in the break, at round 0 or without the bell.
link_fights
link_fights(fights: Sequence[Fight], card: UpcomingCard) -> tuple[dict[str, FightLink], Counter[str]]Each Kalshi fight’s bout on the card.
A card the upcoming-card loader assembled (its bouts carry event_ticker, the Kalshi
fight the loader linked each to after its own checks): ONLY the bout naming the fight’s
ticker. A fight no bout names — the loader excluded it, or never linked it — is not
traded; names are never tried (they would skip the loader’s checks). The names then give
only the order of the fighters on that one bout (fighters_order).
A card without tickers (a research-built card: replays, tests): the names, strictly —
both fighters sharing a name word (over two letters) with the bout’s two names, in
either order, exactly one bout, the order by the words (orientation).
Either way the order must be clear, the scheduled rounds must agree and no two Kalshi fights may take one bout; anything else links nothing (never a guess). Names and tickers only, never an outcome: the forward check links the stored card the same way.
market_names
market_names(swap: bool) -> dict[Role, str]Kalshi role (framed on Kalshi’s fighter A) -> the dataset’s market name (framed on the dataset’s fighter A).
orientation
orientation(ka: frozenset[str], kb: frozenset[str], t1: frozenset[str], t2: frozenset[str]) -> bool | NoneTrue when Kalshi’s fighter A is the bout’s fighter 1, False when fighter 2, None when the names cannot tell. When both orders share a word (Jose Aldo vs Jose Mariscal), only the words the two fighters do NOT share decide: the order matching more of them wins; a tie (identical names) is ambiguous.
resolve_money
resolve_money(portfolio: PortfolioConfig, cfg: RoundsConfig | None = None) -> MoneyLimits | NoneThe ONE place a strategy’s money controls become dollar limits: the sizing bankroll
(None -> None: the strategy does not trade), the card cap and the stop loss, each given in
dollars (‘usd’) or as a share of the sizing bankroll (‘pct’); a control left NULL is
unlimited. They are the strategy row’s own when it sets a sizing bankroll, else the
portfolio’s (money_source). The live cash cap is not a setting
(RoundsRunner.finalize).
same_fighter
same_fighter(kalshi: str, ufc: str) -> boolOne fighter’s two spellings: a shared name word (over two letters), or the same letters once the spaces go (‘Alateng Heili’ = ‘Alatengheili’), or a word of four letters or more of one inside the other’s letters (‘Heili’ in ‘Alatengheili’).
send_timing
send_timing(m: Moment, sent_at: dt.datetime) -> dict[str, Any]When the round ended by the feed’s clock, when the decision was taken and when its working order sent its first slice (every bet of the record carries it).
settings_of
settings_of(cfg: RoundsConfig, portfolio: PortfolioConfig) -> Settings | NoneThe decision’s settings: the strategy row’s optimised core and its money controls in
dollars (resolve_money: the row’s own, else the portfolio’s); None without a sizing
bankroll.