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
+13
@@ -0,0 +1,13 @@
|
||||
# Test fixtures
|
||||
|
||||
A recording of Polymarket's market channel, replayed by the tests in
|
||||
`src/polymarket/feed.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.
|
||||
- `polymarket-frames.jsonl`: the first 90 s (14:24:44 to 14:26:14 UTC, so two
|
||||
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`.
|
||||
Vendored
+142
@@ -0,0 +1,142 @@
|
||||
[
|
||||
{
|
||||
"question": "2026 Balance of Power: D Senate, D House",
|
||||
"clobTokenIds": "[\"34722410608062854697106861099776685947172185964394483545370684749662285977831\", \"24483563228660028121020430722896740519524131851526579619586176931221901842798\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "2026 Balance of Power: R Senate, R House",
|
||||
"clobTokenIds": "[\"103704141773947678931823410030956181918562062788486034785782641603149828893320\", \"25869296386911654049715489068824757745174681288397238521780118949553760488529\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Republicans lose the Alaska, Iowa, Kansas, Maine, Michigan, Ohio, and Texas Senate seats?",
|
||||
"clobTokenIds": "[\"13535941900723044344907002451427688051727855016747811259193368015899108383450\", \"80727480162707694817992062873857913056698208056368499870278974630056151503113\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "2026 Balance of Power: R Senate, D House",
|
||||
"clobTokenIds": "[\"6302359956133594764084277082169634158291609371270652093164054687145970756151\", \"558600218792430158020964384658762756367786275998757133304987611939841005404\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will the Republicans win the Mississippi Senate race in 2026?",
|
||||
"clobTokenIds": "[\"36589074670521348842786325911391532620430247097981345860356484520500173888573\", \"4639340586725578716005500791739559303082924048072534329825226706547465941088\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Mary Peltola win the Alaska Senate race in 2026?",
|
||||
"clobTokenIds": "[\"72139607190315861034411702195742538105117960260100800877125381826122747504258\", \"38274379050640062523611849065721372699838119672720475300345842413156391540232\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will the Democrats win the Mississippi Senate race in 2026?",
|
||||
"clobTokenIds": "[\"77001639760095266374534198365421436593389036687975321536722226607654949914567\", \"109329484956764506378760583725617100193692863947320202695087573398990069238209\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "2026 Balance of Power: D Senate, R House",
|
||||
"clobTokenIds": "[\"70997927349469817841862065582625658840347600365813612622959588796331622340305\", \"45720947308530468765087874228584729250108790729495800420104302263408503667446\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Republicans win Iowa, and lose Alaska, Kansas, Maine, Michigan, Ohio, and Texas?",
|
||||
"clobTokenIds": "[\"106253100341058888227154298197221161777912145262343559280892425406157624656915\", \"38883886691124225989332035378913105158890603529288875957747834557386418386450\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will the US confirm that aliens exist before 2027?",
|
||||
"clobTokenIds": "[\"107505882767731489358349912513945399560393482969656700824895970500493757150417\", \"7305630249804085635496399869905769372294302716159034447326228509068694952392\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": false,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Rolex Paris Masters: Alexander Zverev vs Lorenzo Musetti",
|
||||
"clobTokenIds": "[\"97202122435166371596632600271207731098197012320781592658111953138552052790871\", \"64561849525628736112915971493239643546218846988377083760471198523625509677016\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": false,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Republicans win Alaska, and lose Iowa, Kansas, Maine, Michigan, Ohio, and Texas?",
|
||||
"clobTokenIds": "[\"83965128865532878903206942328238684643656639972076348062693215949819184139617\", \"93889370639599634853686597701962997508099936018794651953480468245159849951085\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "US x Iran ceasefire continues through October 31?",
|
||||
"clobTokenIds": "[\"67102598924726349989742049657609063097299442010642912942032681022413402597017\", \"114475889232765203212032217024645308497828327658421967586050553616813506019119\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": false,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Real Madrid CF win on 2026-11-04?",
|
||||
"clobTokenIds": "[\"39515423851331707664526519001996875757487006788622502797081364834883774387767\", \"3771084942539439798998256191956824579778203065651547449472385427482459623087\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Republicans win Iowa and Kansas, and lose Alaska, Maine, Michigan, Ohio, and Texas?",
|
||||
"clobTokenIds": "[\"105070040449310495327131730101841566321530681945885747881686068698995174349681\", \"111381299800799485509083912497813429956512687399857260440199290536659860679263\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will the U.S. invade Iran before 2027?",
|
||||
"clobTokenIds": "[\"55115078421062885512539156303747803058407616201213034911037320915726138659123\", \"1910830010387565971650098373488592514702818137344973088263643820608151819241\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": false,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Benjamin Netanyahu be the next Prime Minister of Israel?",
|
||||
"clobTokenIds": "[\"20006732765674855733524007935991362439352594042415161039767275461950712817548\", \"54533569528927082430133047556849600511985191158927477533124630301934489498530\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Dan Sullivan win the Alaska Senate race in 2026?",
|
||||
"clobTokenIds": "[\"2618138322856109565904469085316346602627882727483900432328802655317079880335\", \"64264976954058187238724333554507208255303776435657387002861226761784169752307\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will Nithya Raman win the 2026 Los Angeles mayoral election?",
|
||||
"clobTokenIds": "[\"50292933818751585369672690878774599873941191925538325333138798248932182222864\", \"58507084608782512565480280053882807505189448738098588563704773804344223603355\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
},
|
||||
{
|
||||
"question": "Will John McEntee win the 2028 Republican presidential nomination?",
|
||||
"clobTokenIds": "[\"50730508396692945396787154191308995513666087024795374376582570929738968294242\", \"7808428608295632540409928244677767077616163699109217296255297216219773833140\"]",
|
||||
"orderMinSize": 5,
|
||||
"negRisk": true,
|
||||
"enableOrderBook": true
|
||||
}
|
||||
]
|
||||
+3901
File diff suppressed because it is too large.
Load diff
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