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

+26
View File
@@ -147,6 +147,32 @@ From a 60 s run of the M1 spike on one market, both tokens subscribed, and the
403 (curl and `ureq` get 200), most likely Cloudflare filtering by user agent.
Fetch with curl in throwaway scripts.
## Two connections on the same symbols (observed 2026-11-11)
- **Same changes, same order**: two connections subscribed to the same 8,000
tokens for 335 s delivered the same 616,708 changes, none on only one, in
the same order per token. So the book hash orders changes across
connections too.
- **The second delivery's lag**: 0.5 ms at the median, over 10 ms for 6.5% of
changes, over 100 ms for 1%, 706 ms at worst; up to 82 changes of its token
behind. Neither connection leads (one was first 34% of the time).
- **Batches**: 95% of updates are one change. The others come one change per
frame, all with the hash of the whole batch, within 1 ms (40 ms at worst).
- **The server repeats some changes** on one connection (104 in that
recording, the same on both): harmless, quantities being absolute.
- **Connections carrying the same tokens are closed together**: two ramped on
the same tokens got their 1013 close 3 s apart. Over 20 minutes on 48,038
tokens with two subscriptions each, twins in creation order had both
subscriptions down for 33,345 token-seconds, twins dealt at random 3,787,
two independent random deals 272.
- **300 connections** opened at once from one address all stayed up.
- **A connection whose every subscribed market has resolved is closed** by the
server, code 1000, reason `all subscribed assets resolved` (seen on a
connection left with one market, 2026-11-11).
- **A change's `timestamp` never goes back within a token** on a connection
(0 of 660,084 changes on each of the two):
one older than the last applied is a late copy.
## Gamma, the market listing (observed 2026-11-04)
- **Size:** 238,308 markets `active` and not `closed`; 238,201 of them with