CLOB v2, WebSocket quoting, and live safety rails
Polymarket retired the original CLOB, so live orders now go through the v2 client. Alongside that, a new WebSocket engine re-quotes on every book update instead of polling once per cycle, paper fills model the real order queue, and live runs get hard caps that read positions from the exchange rather than from local bookkeeping.
# Live safety rails, USDC defaults
# halt once realized loss exceeds:
LIVE_MAX_DAILY_LOSS=25
# freeze new buys at this exposure:
LIVE_MAX_EXPOSURE=50
# seconds between cancel/replace:
LIVE_CANCEL_SEC=3
# CLOB v2 signing wallet:
# 1 = email / Magic proxy wallet
# 2 = browser wallet
POLYMARKET_SIG_TYPE=1
# WebSocket engine, same .env:
# python ws_engine.py
# live data, log orders, no posts:
# WS_LIVE_SHADOW=trueNew
- Live execution moved to Polymarket CLOB v2. The archived v1 endpoint now rejects orders with an “invalid order version” error, so auth, order posting and cancels go through the v2 client. Paper mode is untouched.
- WebSocket engine (ws_engine.py): order books arrive by push and every update re-evaluates quotes, with a 250 ms per-market floor and a 500 ms ticker for quiet markets. Discovery, settlement and saves run as background tasks, and WS_LIVE_SHADOW=true runs the full live path while logging every order instead of posting it.
- Live kill switch and exposure cap: LIVE_MAX_DAILY_LOSS cancels every open order, stops posting, sends a Telegram alert and writes a LIVE_HALT file that survives restarts; LIVE_MAX_EXPOSURE freezes new buys once the USDC committed across open markets reaches the cap.
- CONTRA strategy mode: accumulates the dipped side with a maker ladder while BTC spot stays within a few dollars of the window open, takes profit into the bounce and locks Up+Down pairs below $0.93 combined. Tunable through CONTRA_* variables; expect long losing streaks by design.
- Hourly Telegram digest (tg_report.py): realized P&L, markets won and lost, and average win and loss for each running bot. Read-only, so it never races the bot's own portfolio saves.
- Benchmark scripts pull any wallet's activity from the public data API and score your paper or live run on the same metrics as the reference trader: taker share, edge per share, heavy-side win rate.
Updated
- Live stake caps now read positions and spend from the exchange every cycle and fail closed: if the fetch fails, nothing new is posted that cycle.
- Paper fills model the real L2 queue: taker orders consume displayed liquidity level by level at VWAP, resting orders wait behind the size already at their price, and real taker prints fill them in price-time order. Partial fills show in the log.
- Maker mode posts a standing bid ladder that keeps its queue position instead of chasing the best bid, with a side-ratio guard, re-price hysteresis, a price band and a queue-jump rule. All of it is tunable through MAKER_* variables.
- POLYMARKET_SIG_TYPE selects the signing wallet type (1 for email or Magic proxy wallets, 2 for browser wallets), and order sizes round up to the CLOB minimum of 5 shares.
Bug fixes
- A 15-second socket timeout now also covers the CLOB client's own calls, which issue requests without one. A single stalled TCP connection had frozen a run for 12 hours with the process still alive.
- SIGHUP is ignored, so a dropped SSH session no longer kills a bot started in the foreground.
- The WebSocket engine subscribes to the next window before it opens, so the first seconds of a window are no longer lost to market discovery.