feat(polymarket)!: two connections per market, first one wins

Every live market is subscribed on two connections chosen at random, and its
book takes each change from whichever connection delivers it first: the book
hash says whether a change is a duplicate, the next one, or one to hold until
the change before it arrives. A change one connection misses costs nothing,
each Delta carries the earliest receive time, and a connection that drops is
covered by the other. When a change fits on no connection in time, the book
follows one connection unchecked and asks the other for a fresh book.
Connections now decode and route events to 16 book threads, independent of
them; a move leaves its old connection only once the new one delivers, so it
costs no change; a connection closed with 1013 twice within ten minutes is
split. reconcile reads the collector's log and fails only on a mismatch no
cause line explains. SIGTERM and SIGHUP stop the collector cleanly.

Breaking: lanes are gone (connections and book threads are separate), and
reconcile takes the log as a second argument.
This commit is contained in:
pascal committed 2026-11-11 15:18:48 +00:00
1 parent 8114a51dc2
commit 02747b882f
24 files changed
+8984 -1214

No files matched your search

+9 -5
View File
@@ -1,8 +1,8 @@
# Test fixtures
A recording of Polymarket's market channel, replayed by the tests in
`src/polymarket/feed.rs`, and Gamma pages read by `src/polymarket/gamma.rs`
(no network in tests).
Two recordings of Polymarket's market channel, replayed by the tests in
`src/polymarket/feed.rs` (the first also by `socket.rs`'s routing test), and
Gamma pages read by `src/polymarket/gamma.rs` (no network in tests).
- `gamma-markets.json`: Gamma's top 20 markets by 24 h volume on 2026-11-04,
trimmed to the fields the collector reads. `conditionId`, `active`, `closed`
@@ -15,5 +15,9 @@ A recording of Polymarket's market channel, replayed by the tests in
minute boundaries) of the market channel for those markets' 40 tokens, one
line per frame: `{"received_at_us": <receive time, µs>, "text": <frame>}`.
Opening books, 3,850 changes, 28 mid-stream books, 14 trades, 8 `PONG`s.
- `record.py`: the recorder, if the fixtures need redoing:
`uvx --with websockets python -I record.py gamma-markets.json frames.jsonl 90`.
- `polymarket-frames-two.jsonl`: 95 s (2026-11-11, 12:19:58 to 12:21:33 UTC)
of the same tokens on two connections at once, in receive order, each line
with its `connection` (0 or 1). 20 of the 40 tokens still had an order book.
- `record.py`: the recorder, if the fixtures need redoing, on CONNECTIONS
connections at once (default 1):
`uvx --with websockets python -I record.py gamma-markets.json frames.jsonl 90 [CONNECTIONS]`.