This is a market-making and arbitrage bot for Polymarket written in Rust. Experimental and not production ready.
-
Market WebSocket (
websocket.rs)booksnapshots used to derive best bid and askprice_change(new schema) with per-assetbest_bidandbest_askfor fast deltas
-
User WebSocket (
user_ws.rs)- Order updates and fills
- Used to keep inventory in sync
-
REST API (
execution.rs)GET /positions?user=on startup to seed inventory and persist positions across restartsget_ordersfor optional open-order debugging
-
Quote placement
- Quotes are anchored to book edges, not the mid-price
- Bid: 10% below current best bid
- Ask: 10% above current best ask (scaled toward 1.0)
-
Inventory-based skew
- Applied only when dollar imbalance exceeds
MAX_INVENTORY_IMBALANCE - Long YES:
- Lower ask (sell faster)
- Lower bid (discourage buying more YES)
- Short YES:
- Raise bid (buy faster)
- Raise ask (discourage selling more YES)
- Applied only when dollar imbalance exceeds
-
Conditional re-quoting
- Orders are replaced only if the mid-price bucket changes
- Bucket definition:
ceil(mid * 100) - Reduces churn on small price movements
-
Risk guards
- Cancel all orders and pause if total position value exceeds
MAX_POSITION_SIZE - Pause quoting if prices are extreme:
- Bid ≤ 0.02
- Ask ≥ 0.98
- Cancel all orders and pause if total position value exceeds
-
market_tx / market_rx
Market WebSocket → Trading Logic
Real-timeMarketUpdate -
cmd_tx / cmd_rx
Trading Logic → Order Execution
BotCommand::{Create, Cancel, CancelAll, Shutdown}
my_open_orders: active bot ordersinventory:token_id → quantitytoken_pairs / yes_token: explicit YES/NO mapping
(1st / 2nd entries inASSETS_IDS)last_prices: latest(bid, ask, timestamp)per tokenlast_mid_bucket:ceil(mid * 100)per marketrisk_paused,shutting_down: control flagsmax_inventory_imbalance,max_position_size: dollar risk limits
Ctrl + Csetsshutting_down- Issues
CancelAll - All tasks shut down cleanly