import asyncio
import json
import requests
import websockets
API_KEY = "ps_live_..."
BASE = "https://api.polysimulator.com/v1"
# Mint WS token
ws_token = requests.post(
f"{BASE}/keys/ws-token",
headers={"X-API-Key": API_KEY},
).json()["token"]
async def stream_prices():
async with websockets.connect(
f"wss://api.polysimulator.com/v1/ws/prices?token={ws_token}"
) as ws:
# Subscribe to markets
await ws.send(json.dumps({
"action": "subscribe",
"markets": ["0xabc123...", "0xdef456..."],
}))
async for raw in ws:
msg = json.loads(raw)
if msg["type"] == "price":
cid = msg["condition_id"][:16]
buy = msg["data"]["buy"]
print(f"{cid}... → Yes: {buy}")
asyncio.run(stream_prices())