Skip to content

betting_combat.execution.venues

venues.py — the venues the execution sends to, behind one face (Sam 2026-11-16: Kalshi and Polymarket US).

Venue quote (our side's top from the card's live book mirror, our own resting order left
out), cash, buy (a limit order: IOC to take, GTC post-only to rest), amend, cancel,
look (an order's state), fills (an order's fills, the venue's record), fee
KalshiVenue the Kalshi client (``providers.kalshi``) and the recorder's Kalshi books
(``BookMirror``); NO is bought as NO (its own price)
PolyUsVenue the Polymarket US client and the recorder's US books (each frame a whole book in
the long side's terms); our side is the venue's long or short as the market's
``venue_side`` says; its fills are the order's cumulative fills (no fill list)

Every send is once (never retried: a lost answer is looked up, look). Prices are our side’s, 0-1, on the venue’s 1c tick.

Classes

Ack

An order’s state on the venue.

KalshiVenue

Bases: Venue

amend

amend(market: Market, outcome: Side, ack: Ack, price: float, count: float, client_order_id: str) -> Ack

buy

buy(market: Market, outcome: Side, price: float, count: float, resting: bool, client_order_id: str) -> Ack

cancel

cancel(market: Market, ack: Ack) -> None

cancel_open

cancel_open(markets: list[Market], prefix: str) -> int

cash

cash() -> float

fills

fills(market: Market, outcome: Side, ack: Ack) -> list[VenueFill]

find

find(market: Market, client_order_id: str, since: dt.datetime) -> Ack | None

levels

levels(market: Market, outcome: Side) -> tuple[list[tuple[float, float]], list[tuple[float, float]]] | None

look

look(market: Market, ack: Ack) -> Ack

ready

ready() -> str | None

Kalshi takes no sports order once our key’s location attestation has expired.

PolyUsVenue

Bases: Venue

amend

amend(market: Market, outcome: Side, ack: Ack, price: float, count: float, client_order_id: str) -> Ack

buy

buy(market: Market, outcome: Side, price: float, count: float, resting: bool, client_order_id: str) -> Ack

cancel

cancel(market: Market, ack: Ack) -> None

cancel_open

cancel_open(markets: list[Market], prefix: str) -> int

Every open order on the card’s markets (the US account is the execution’s alone).

cash

cash() -> float

fills

fills(market: Market, outcome: Side, ack: Ack) -> list[VenueFill]

The order’s fills so far as one row per change of its cumulative fill (the US gives no fill list): the newest cumulative fill at its average price, the fee computed.

find

find(market: Market, client_order_id: str, since: dt.datetime) -> Ack | None

levels

levels(market: Market, outcome: Side) -> tuple[list[tuple[float, float]], list[tuple[float, float]]] | None

look

look(market: Market, ack: Ack) -> Ack

ready

ready() -> str | None

Venue

One venue’s face (module doc).

affordable

affordable(cash: float, price: float) -> int

Whole contracts cash buys at price with the taker fee.

amend

amend(market: Market, outcome: Side, ack: Ack, price: float, count: float, client_order_id: str) -> Ack

buy

buy(market: Market, outcome: Side, price: float, count: float, resting: bool, client_order_id: str) -> Ack

cancel

cancel(market: Market, ack: Ack) -> None

cancel_open

cancel_open(markets: list[Market], prefix: str) -> int

Every order of ours still resting on markets (ids starting prefix) cancelled: a relaunched card run starts clean, never with an earlier run’s bid left on the book. How many.

cash

cash() -> float

fee

fee(price: float, contracts: float) -> float

The taker fee of contracts at price, rounded up to the cent (the venues charge it so).

fills

fills(market: Market, outcome: Side, ack: Ack) -> list[VenueFill]

find

find(market: Market, client_order_id: str, since: dt.datetime) -> Ack | None

A sent order whose answer was lost, by our id (None: the venue has none).

levels

levels(market: Market, outcome: Side) -> tuple[list[tuple[float, float]], list[tuple[float, float]]] | None

Our side’s bids (best first) and offers (cheapest first), (price, size); None when the book is not mirrored.

look

look(market: Market, ack: Ack) -> Ack

quote

quote(market: Market, outcome: Side, mine: tuple[float, float] | None = None) -> Quote | None

Our side’s top: the best bid others hold (mine = our resting (price, contracts) left out) and the best offer.

ready

ready() -> str | None

Why live orders cannot go out now (None: they can).

VenueFill

Functions

floor_tick

floor_tick(p: float) -> float