Skip to content

betting_combat.trading.executors

Turning an order intent into an order, fills and a database record.

Paper and live share everything up to this point. Both persist the order and its fills themselves and return the final OrderRecord.

Paper fills the way the immediate-or-cancel order would against the book it was sent into: up to the contracts shown at the limit price or better (the working order hands it what the book offers at its slice, trading.working.PaperBook), at the shown price, with the venue’s fee.

Live is at-most-once by construction, the same way on every venue:

  1. an order already recorded for this client_order_id is never sent again;
  2. the order is written as submitted BEFORE it is sent, by an insert only one run can win (a crash after sending leaves a record the relaunch reconciles instead of re-sending; two overlapping runs never both send);
  3. the send is never retried; a lost answer is reconciled by looking the order up on the venue, and if it cannot be found the order is closed as error — still never re-sent;
  4. fills and fees come from the venue’s own fill records.

Only the venue calls differ; they live behind VenueTrader (one per venue).

Classes

Executor

Bases: Protocol

execute

execute(intent: OrderIntent, session_id: str, card_date: dt.date, now: dt.datetime) -> OrderRecord

LiveExecutor

execute

execute(intent: OrderIntent, session_id: str, card_date: dt.date, now: dt.datetime) -> OrderRecord

reconcile

reconcile(order: OrderRecord, note: str | None = None) -> OrderRecord

Find what happened to an order whose answer was lost; never re-send it.

PaperExecutor

execute

execute(intent: OrderIntent, session_id: str, card_date: dt.date, now: dt.datetime) -> OrderRecord

VenueAck

VenueFill

VenueRejected

Bases: Exception

The venue refused the order: final, nothing was placed.

VenueTrader

Bases: Protocol

The venue calls a live order needs; everything else is shared.

fills

fills(order_id: str, since: dt.datetime, outcome: str | None = None) -> list[VenueFill]

The order’s fills, priced as the side it bought (outcome).

find

find(order: OrderRecord, since: dt.datetime) -> VenueAck | None

The venue’s record of this order, or None if it has none.

submit

submit(order: OrderRecord) -> VenueAck

Send an immediate-or-cancel buy. Raises VenueRejected or VenueUnknown.

VenueUnknown

Bases: Exception

The venue’s answer was lost: the order may or may not exist.

Functions

new_order

new_order(intent: OrderIntent, session_id: str, card_date: dt.date, now: dt.datetime) -> OrderRecord