offset. This guide shows the pattern for a complete backfill and the things to get right when the dataset is large.
Use the cursor, not offset
List endpoints return one page plus apagination block. To walk the whole dataset, feed each response’s pagination_key into the next request until has_more is false.
Reach for pagination_key here, never offset. The offset parameter is capped at a few thousand rows (typically the 3,000 to 5,000 range) and exists only so server-rendered pages can deep-link to a specific page. Cursor pagination has no such ceiling, so it is the only way to read a dataset end to end. See Pagination for the full comparison.
Fetching every market
The SDK’spaginate helper turns any list method into an async stream of individual items. It manages limit and pagination_key for you and stops when the server reports the last page.
Fetching every trade
The same pattern fetches a complete trade history. Trade endpoints caplimit at 250 per page, and every filter (condition_ids, builder_codes, from, to) composes with the cursor, so you can scope the backfill before you start.
Any list endpoint works
paginate accepts any list-style method bound to the client. The page size cap depends on the endpoint, so set the third argument to that endpoint’s maximum for the fewest round trips.
| Dataset | Method | Common filters |
|---|---|---|
| Markets | client.markets.getMarkets | tags, status, closed |
| Trades | client.markets.getTrades | condition_ids, builder_codes, from, to |
| Events | client.events.getEvents | tags, status |
| A trader’s trades | client.trader.getTraderTrades | address, builder_codes |
| A trader’s PnL rows | client.trader.getGlobalPnl | address |
Without the SDK
If you are not on the TypeScript SDK, drive the cursor yourself. Start with nopagination_key, then carry forward the value from each response until the server stops returning one.
pagination_key is an opaque resumable token. Persist the last one you saw and you can restart an interrupted backfill from that point instead of starting over.
Stopping early
Exiting the loop stops fetching the next page, so you only pay for the pages you actually read. This is useful when you want the first N rows of an ordered result rather than the whole set.Tips for large backfills
- Narrow before you scan. Apply
from/to,tags, orcondition_idsso you fetch only the slice you need. A filtered backfill is smaller and cheaper than fetching everything and discarding rows client-side. - Use the largest page size. Set the page size to the endpoint cap (250 for trades) to minimise the number of round trips.
- Back off on
429. A tight backfill loop can hit the rate limit. Retry with exponential backoff and jitter. See Rate Limits. - Persist the cursor. Save the last
pagination_keyso an interrupted job resumes instead of restarting. - Don’t re-fetch volatile data. Prices, PnL, and positions change continuously. If you need them live after the initial load, subscribe to the matching websocket room instead of re-running the backfill. See Best Practices.