Archived
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:
22 files changed
+6423
-84
No files matched your search
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
# Records the market channel for the markets in gamma-markets.json: one JSON
|
||||
# line per frame, {"received_at_us": <micros>, "text": <frame text>}.
|
||||
import asyncio, json, sys, time
|
||||
import websockets
|
||||
markets = json.load(open(sys.argv[1]))
|
||||
tokens = [t for m in markets if m["enableOrderBook"] for t in json.loads(m["clobTokenIds"])]
|
||||
async def main(out, seconds):
|
||||
async with websockets.connect("wss://ws-subscriptions-clob.polymarket.com/ws/market", max_size=None) as ws:
|
||||
await ws.send(json.dumps({"type": "market", "assets_ids": tokens}))
|
||||
loop = asyncio.get_event_loop(); end = loop.time() + seconds; last_ping = loop.time()
|
||||
while loop.time() < end:
|
||||
if loop.time() - last_ping >= 10:
|
||||
await ws.send("PING"); last_ping = loop.time()
|
||||
try: text = await asyncio.wait_for(ws.recv(), 1)
|
||||
except asyncio.TimeoutError: continue
|
||||
received_at_us = time.time_ns() // 1000
|
||||
out.write(json.dumps({"received_at_us": received_at_us, "text": text}) + "\n")
|
||||
with open(sys.argv[2], "w") as out:
|
||||
asyncio.run(main(out, float(sys.argv[3])))
|
||||
Reference in new issue
Block a user