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.
1.8 KiB
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