Skip to content

feat: add auto-pagination iterators for list endpoints#4

Open
harley-poly wants to merge 3 commits into
mainfrom
harley/sdk-pagination
Open

feat: add auto-pagination iterators for list endpoints#4
harley-poly wants to merge 3 commits into
mainfrom
harley/sdk-pagination

Conversation

@harley-poly
Copy link
Copy Markdown
Member

@harley-poly harley-poly commented Jun 2, 2026

summary

adds iterate() helpers that transparently walk all pages so callers no longer hand-roll cursor/offset logic:

  • offset-paginated resources: events.iterate(), markets.iterate(), series.iterate() (page until a short page is returned).
  • cursor-paginated feed: portfolio.iterate_activities() (follow nextCursor until eof or an empty cursor).
  • shared helpers live in polymarket_us/pagination.py; both sync (Iterator) and async (AsyncIterator) variants are provided.

positions are intentionally not iterated (the endpoint returns the full set in one response).

test plan

  • ruff check / ruff format --check
  • mypy polymarket_us
  • pytest (125 passed; new tests/test_pagination.py covers offset paging until short/empty page, cursor paging until eof/no-next-cursor, and async variants)

Note

Low Risk
Additive client-side helpers and documentation; no changes to signing, orders, or server contracts beyond extra list requests when iterating.

Overview
Adds auto-pagination so callers can stream full list results without manual offset/cursor handling. Shared logic in polymarket_us/pagination.py covers offset pages (stop on short/empty page, clamp page_size to at least 1) and cursor pages (follow nextCursor until eof or missing cursor), with sync and async variants.

iterate() on events, markets, and series walks offset-paginated lists (optional filters + page_size). portfolio.iterate_activities() walks authenticated activity history via cursor. README documents sync/async for usage.

Tests in tests/test_pagination.py cover multi-page offset, empty pages, cursor/eof, and async mirrors. test_auth now builds a valid 64-byte base64 secret for the Ed25519 key-length test.

Reviewed by Cursor Bugbot for commit bfd4f37. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants