3. Fetch All Active Markets
Use Case: When you need to retrieve all available active markets, typically for broader analysis or market discovery.
The most efficient approach is to use the /events endpoint and work backwards, as events contain their associated markets.
Events Endpoint: GET /events
Markets Endpoint: GET /markets
Key Parameters
order=id- Order by event IDascending=false- Get newest events firstclosed=false- Only active marketslimit- Control response sizeoffset- For pagination
Examples
bash
curl "https://gamma-api.polymarket.com/events?order=id&ascending=false&closed=false&limit=100"This approach gives you all active markets ordered from newest to oldest, allowing you to systematically process all available trading opportunities.
Pagination
For large datasets, use pagination with limit and offset parameters:
limit=50- Return 50 results per pageoffset=0- Start from the beginning (increment by limit for subsequent pages)
Pagination Examples:
bash
# Page 1: First 50 results (offset=0)
curl "https://gamma-api.polymarket.com/events?order=id&ascending=false&closed=false&limit=50&offset=0"bash
# Page 2: Next 50 results (offset=50)
curl "https://gamma-api.polymarket.com/events?order=id&ascending=false&closed=false&limit=50&offset=50"bash
# Page 3: Next 50 results (offset=100)
curl "https://gamma-api.polymarket.com/events?order=id&ascending=false&closed=false&limit=50&offset=100"bash
# Paginating through markets with tag filtering
curl "https://gamma-api.polymarket.com/markets?tag_id=100381&closed=false&limit=25&offset=0"bash
# Next page of markets with tag filtering
curl "https://gamma-api.polymarket.com/markets?tag_id=100381&closed=false&limit=25&offset=25"