# Pagination

List endpoints use cursor pagination, which stays consistent while new articles keep arriving.

## How it works

1. Make a request with `limit` (1–100, default 20).
2. If `meta.next_cursor` is not `null`, there are more results.
3. Repeat the request with the same filters plus `cursor=<next_cursor>`.

Cursors encode the position of the last item, so new articles published while you page don't shift or duplicate results. Cursors don't expire, but they only work with the filters they were created with.

## Example: walk every page

```python
import os

import requests

URL = "https://api.marketnewsapi.com/v1/news"
HEADERS = {"Authorization": f"Bearer {os.environ['MARKETNEWSAPI_KEY']}"}
params = {"tickers": "NVDA", "from": "2026-09-01", "to": "2026-09-30", "limit": 100}

articles = []
while True:
 page = requests.get(URL, headers=HEADERS, params=params, timeout=10).json()
 articles += page["data"]
 if not page["meta"]["next_cursor"]:
 break
 params["cursor"] = page["meta"]["next_cursor"]

print(len(articles), "articles")
```

## Backfilling large ranges

For big historical pulls, split the range into days or weeks and fetch them in parallel (stay under 20 requests per second). Use `sort=published_asc` if you want to process oldest first.

## Polling for new articles

To poll for news since your last check, don't page backwards. Pass `from` set to the newest `published_at` you've seen, with `sort=published_asc`, and de-duplicate by `id`.
