feat!: a generic core, and Kalshi through it

The orchestrator, the connection loop and the book thread's shell move to
src/core/, generic over an Exchange and its loss rule (ADR 0004).
Polymarket runs through it unchanged. Kalshi joins: a signed handshake
(KALSHI_KEY_ID_FILE, KALSHI_PRIVATE_KEY_FILE), a reconnect on a skipped
sequence number, first one wins by clock and rank, and its market listing
with markets tracked from three hours before they open.

Breaking: the exchange is now the first argument,
`engineering-challenge <polymarket|kalshi|kalshi-demo> [OUTPUT]`.
This commit is contained in:
pascal committed 2026-11-11 20:54:17 +00:00
1 parent 480ee3ad2d
commit 1a5bbcd602
33 files changed
+8150 -1846

No files matched your search

+19 -5
View File
@@ -7,24 +7,37 @@ for the backtests that read its output.
**Market**:
A tradable question on an exchange. On Polymarket it has two outcomes (Yes,
No), each traded as its own symbol, and their books mirror each other.
No), each traded as its own symbol, and their books mirror each other. On
Kalshi it has one book, holding bids for Yes and bids for No.
_Avoid_: Event, contract
**Symbol**:
The unit that has one order book: on Polymarket a token (one outcome of a
market), named by its token id.
market), named by its token id; on Kalshi the market itself, named by its
ticker, a bid for No at a price being an ask at one minus that price.
_Avoid_: Asset, instrument, ticker (for Polymarket)
**Live**:
Said of a market (and its symbols) the exchange lists as open for trading on
its order book. A market stops being live when it closes or stops accepting
orders, not at its end date.
orders, not at its end date. A Kalshi market about to open is tracked ahead
of being live, its book empty.
_Avoid_: Active (Gamma's flag, only one input of being live)
**Book hash**:
The exchange's fingerprint of a symbol's full book state, sent with every
Polymarket's fingerprint of a symbol's full book state, sent with every
full book and every change.
**Sequence number**:
Kalshi's count of the messages it sent on one connection, all its markets
together: one skipped means the connection lost a message, for a market it
doesn't name.
**Clock**:
Kalshi's counter for one market, the same on every connection, carried by
every book and change. Several changes can share one clock, always in the
same order.
## Collector side
**Book**:
@@ -100,7 +113,8 @@ _Avoid_: Arrival time, local timestamp
A change for a symbol that no connection delivered in time, which leaves its
book silently wrong. A change only one connection missed is rescued, not
lost.
_Avoid_: Gap (implies sequence numbers)
_Avoid_: Gap (a skipped sequence number is one connection's, and may be no
loss at all)
**Resync**:
Asking the exchange for a fresh full book of a symbol and replacing ours with