feat(polymarket): hash-verified order books for a subset of symbols

Collects the order books of Polymarket's 20 busiest markets (40 symbols)
into the template's SBE format: a Delta per level change, plus Snapshots on
subscribe, every minute, and whenever a fresh book corrects ours. Every
change is checked against Polymarket's own book hash; a failed check
resyncs the symbol on the open socket, and the log counts losses apart from
the few ms our own resync hides. Runs until SIGINT, which closes the socket
and flushes the output; reconnects when the server drops it. A `reconcile`
binary checks an output file against itself.
This commit is contained in:
pascal committed 2026-11-04 17:10:17 +01:00
1 parent 0e687e7eba
commit adb7fee8d8
22 files changed
+6423 -84

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
# Order-book collector
The collector's language: what it tracks on each exchange and what it writes
for the backtests that read its output.
## Exchange side
**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.
_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.
_Avoid_: Asset, instrument, ticker (for Polymarket)
**Book hash**:
The exchange's fingerprint of a symbol's full book state, sent with every
full book and every change.
## Collector side
**Book**:
The collector's in-memory order book for one symbol: its bid and ask price
levels, each with its absolute quantity.
_Avoid_: Order book state, depth
**Receive time**:
When a message came off the socket, by the local clock.
_Avoid_: Arrival time, local timestamp
**Loss**:
Any message for a symbol that the collector did not apply, which leaves its
book silently wrong.
_Avoid_: Gap (implies sequence numbers)
**Resync**:
Asking the exchange for a fresh full book of a symbol and replacing ours with
it, whenever our book can't be verified. Our book was wrong (a loss) only if
the fresh one differs.
_Avoid_: Re-snapshot, rebuild, refresh
**Resync gap**:
The changes a symbol's resync itself keeps from us: the exchange holds them in
the fresh book but never sends them as changes.
_Avoid_: calling it a loss (the state stays right; only those updates are missing)
## Output
**Snapshot**:
The output message holding one symbol's whole book at a point in time.
_Avoid_: using it for the action of fetching a fresh book (that is a resync)
**Delta**:
The output message changing one price level of one symbol's book to a new
absolute quantity (`PriceLevelUpdate` in the schema).
_Avoid_: Increment, diff