GuidesResources
Best practices
Each rule below follows from something documented elsewhere. The reasoning is included so you can decide when it does not apply to you.
Correctness
Section titled “Correctness”Check capability before assuming support
Section titled “Check capability before assuming support”Read the venue’s has map or the capabilities field rather than discovering a gap through
a caught exception. The 16 served venues genuinely differ, and NOT_SUPPORTED is an answer
rather than a fault. See Capability-honest data.
Never render a synthetic book as depth
Section titled “Never render a synthetic book as depth”Venues without a real order book return a book-shaped response labelled synthetic. It is a faithful representation of price and is not orders anyone can fill against. Feeding it into a sizing calculation produces a number with no meaning.
Do not equate similar markets across venues
Section titled “Do not equate similar markets across venues”Matched clusters carry a similarity score, not an identity claim, and two venues can settle what looks like the same question differently. A price gap is an indicative price discrepancy until every executable gate passes.
Use asOf, not your own clock
Section titled “Use asOf, not your own clock”A timestamp you generate on receipt describes your request. asOf describes the data.
Persist marketId, not slug
Section titled “Persist marketId, not slug”Slugs derive from titles and change when a venue renames a market. See Identifiers.
Request small event pages and rely on the event-list cap to limit child markets per event.
Page an event’s remaining markets through venue-scoped fetchMarkets?eventId=... with the same filters.
Follow cursors instead of parallelising offsets
Section titled “Follow cursors instead of parallelising offsets”Follow nextCursor sequentially. Parallel offset requests spend the rate allowance faster.
Market cursors capture membership and order at cursor creation.
Later pages serve the current contents of those rows in that order.
Deleted rows consume their captured positions.
Inserts, sort changes, and status updates cannot change the walk.
A market walk covers at most 5,000 markets.
Semantic and hybrid walks cover at most 5,000 results.
Lexical walks report the full matching total when counted; total is null if counting times out.
Hot-catalog walks retain their snapshot and its capture time.
Each cursor is kept for a limited time.
Restart from page one if the cursor expires or returns the documented expiry error.
Market cursor walks freeze membership and order when page one runs.
A cursor captures the ordered rows for the sort and filters, then reads those rows’ current
contents on later pages. Prices stay fresh, while membership, order, and the total stay fixed.
New markets do not enter the walk, and updates cannot remove an unvisited market or shrink its total.
Deleted rows consume their frozen positions and are skipped. An ID recreated behind the cursor is not revisited.
A market walk is limited to 5,000 matching markets; a larger result returns the existing
CATALOG_QUERY_TOO_BROAD refusal. Narrow the query or request the live catalog instead.
Offsets above 10,000 are rejected. Snapshot/offset cursors are signed; if a cursor fails validation, restart the walk from page one.
Cursors do not live forever: each one carries a TTL. On fetchArbitrage walks the service keeps a replaced page’s snapshot for up to ten minutes (600,000 ms) by default; it may keep a page for less under load, and the expiry error states the actual lifetime it had.
Market cursor walks keep one deadline from page one: snapshotTTL sets the lifetime in
milliseconds (60,000 by default).
If the snapshot expires or is no longer available, the cursor returns 400 VALIDATION_ERROR with
Cursor has expired: ... and the caller must restart from page one.
Other snapshot/offset cursors expire 60 seconds after issuance by default, measured per page hop, and snapshotTTL on page 1 sets the per-hop lifetime in milliseconds.
For filtered or other non-default requests, values up to 86,400,000 ms are accepted, and 0 disables the per-hop expiry. Whole-catalog market cursors have an effective one-hour cap (3,600,000 ms), including snapshotTTL=0; on fetchArbitrage walks 0 means the 600,000 ms cap, not forever.
A stale cursor returns 400 VALIDATION_ERROR with Cursor has expired: this page's snapshot was kept for <N> s; fetch the next page sooner, raise snapshotTTL on page 1 (up to <cap> ms), or restart without a cursor (cap: 600000 ms on fetchArbitrage walks, 3600000 ms on whole-catalog market cursors, 86400000 ms on other requests).
On expiry, the caller must discard the partial walk and restart from page 1 without a cursor.
Batch where a batch verb exists
Section titled “Batch where a batch verb exists”fetchOrderBooks takes many outcomes in one request. It is priced by items, so it saves
rate allowance rather than credits.
Stream rather than poll
Section titled “Stream rather than poll”A WebSocket subscription delivers book and trade updates without consuming the request window. Streaming is metered at 2 credits per connection-minute (800 while a Polymarket pending-fills subscription is held); polling also consumes the request allowance and the endpoint’s credits.
Cache what does not move
Section titled “Cache what does not move”Capability maps and taxonomy change rarely. Re-fetching them per
query is pure overhead. Authenticated API responses carry Cache-Control: no-store, so browsers
and shared HTTP caches do not store them; keep those values in your own application cache instead.
Request only the window you need
Section titled “Request only the window you need”History is priced per query regardless of range, but a narrower window returns faster and is less likely to hit a query limit.
Resilience
Section titled “Resilience”Branch on code and retryable, not on HTTP status
Section titled “Branch on code and retryable, not on HTTP status”Several codes share a status, and retryable is the field that answers the question you are
actually asking. See Errors.
Retry only when retryable is true, with exponential backoff and jitter
Section titled “Retry only when retryable is true, with exponential backoff and jitter”That includes retryable 502 upstream and relay failures as well as 429 and 503. Errors marked
non-retryable fail identically on the second attempt. INSUFFICIENT_CREDITS in particular will not
resolve by retrying.
Never auto-retry a write
Section titled “Never auto-retry a write”Expect empty results to be legitimate
Section titled “Expect empty results to be legitimate”A market with no trades today returns an empty tape. fetchSeries on a venue without the
concept returns an empty list. Neither is an error.
Handle 503 on billing-session writes while other routes keep flowing
Section titled “Handle 503 on billing-session writes while other routes keep flowing”During a brief platform degradation, billing-session writes can answer 503 PLATFORM_UNAVAILABLE
while reads and other writes keep working. Retry those billing calls shortly.
Keys and secrets
Section titled “Keys and secrets”Send keys in the Authorization header, never in a query string
Section titled “Send keys in the Authorization header, never in a query string”Query strings end up in request logs, browser history, and referrer headers.
Keep keys server-side
Section titled “Keep keys server-side”Only a hash of the key authenticates requests; the console keeps an encrypted copy solely so the API keys page can show it to its owner again. A key that reaches a browser bundle is disclosed permanently and must be revoked or regenerated.
Predictefy REST sends no CORS headers by design, so
proxy browser history calls through your server.
WebSocket first-frame authentication is the one
sanctioned browser use. Give that page a dedicated read-only key with no trade or sql
scope, treat it as disclosed, and be prepared to revoke it.
Use separate keys per environment
Section titled “Use separate keys per environment”Rate limits and credit spend are tracked per key, so one key across staging and production makes both untraceable and lets a test loop exhaust a production allowance.