Skip to main content

Best Practices

Battle-tested patterns to make your bots production-ready.

1. Always Use String Numerics

Never send numeric values as JSON numbers. The API returns and expects all monetary values as strings to prevent IEEE 754 floating-point precision loss.
Use Decimal for all arithmetic:

2. Use Idempotency Keys

Every POST /v1/orders request should include an Idempotency-Key header to prevent duplicate orders on network retries:
If you retry a request with the same idempotency key, the server returns the original response without creating a duplicate order.

3. Prefer Batch Endpoints

When operating on multiple markets, use batch endpoints to reduce HTTP overhead and stay within rate limits:

4. Use WebSocket Over REST Polling

For price monitoring, WebSocket streaming is vastly more efficient: Reserve REST API for:
  • Order placement
  • Account queries
  • Historical data

5. Use Cursor Pagination for Large Datasets

For endpoints that return lists (orders, positions, trade history), prefer cursor-based pagination over offset:
Offset pagination (offset=100) can skip or duplicate items when new records are inserted between pages. Use cursor pagination for trading data.
The result-list key differs by endpoint. The native GET /v1/orders returns data["orders"] (shown above). The PM-shape GET /v1/data/orders returns the rows under data["data"] instead — read the right key for whichever endpoint you call, or the loop silently iterates nothing.

6. Cache Market Metadata

Market metadata (question text, outcomes, slugs) changes rarely. Cache it locally and refresh periodically:

7. Implement Exponential Backoff

Never hammer the API on errors. Use exponential backoff with jitter:

8. Monitor Your Bot

Use the health and metrics endpoints to monitor the API and your bot:
Track your bot’s performance via the equity curve:

9. Handle Market Resolution

Markets can resolve at any time. Your bot should handle positions being settled:
  • Winning positions: payout credited automatically
  • Losing positions: position marked CLOSED with $0 value
  • Use GET /v1/account/positions?status=CLOSED to review settled positions

10. Test in Virtual Mode First

PolySimulator is paper trading — develop and test your complete bot logic with zero financial risk against the same REST surface you’ll use in production. Switching to live trading on Polymarket is not a pure base-URL swap, though: PM’s CLOB POST /order requires EIP-712-signed orders (maker/taker amounts, salt, signature). The closest drop-in path is PolySimulator’s PM-shape POST /v1/order + py-clob-client, which approximates PM’s wire format — see CLOB Compatibility and Live Migration for what changes.

Checklist

Use this checklist before deploying your bot:
  • All numeric values sent as strings
  • Idempotency keys on all order requests
  • Exponential backoff on 429/5xx errors
  • Retry-After header respected
  • WebSocket reconnection with token refresh
  • Cursor pagination for list endpoints
  • Market metadata cached locally
  • Health check before trading loop starts
  • Logging for all order placements and errors
  • Tested in virtual mode with full strategy