feat: add helpers to fetch all markets #200
Open
+46
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two convenience methods to
ClobClient:get_all_marketsget_all_simplified_marketsBoth methods iterate through the paginated CLOB API using the
next_cursorandEND_CURSORconvention and return a flat list of all markets.Motivation
Currently,
get_marketsandget_simplified_marketsonly return a singlepage of results and require client code to implement pagination manually.
These helpers provide a simple, ergonomic way to fetch all markets without
breaking the existing API surface.
Implementation details
get_all_marketscallsget_marketsin a loop and aggregatesresponse["data"]until
next_cursor == END_CURSOR.get_all_simplified_marketsdoes the same usingget_simplified_markets.Testing
Manually tested against the CLOB API by verifying that:
END_CURSOR,Note
Introduce
get_all_marketsandget_all_simplified_marketsto iterate pagination and return full market lists; clarify and type-hint single-pageget_marketsandget_simplified_markets.py_clob_client/client.py):get_all_markets(next_cursor: str = "MA=="): loops through cursors untilEND_CURSOR, aggregatesresponse["data"].get_all_simplified_markets(next_cursor: str = "MA=="): same for simplified markets.strtype hints and clarify docs forget_marketsandget_simplified_marketsas single-page fetches.Written by Cursor Bugbot for commit b748724. This will update automatically on new commits. Configure here.