-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add combo market catalog #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from collections.abc import Sequence | ||
| from typing import cast | ||
|
|
||
| from polymarket._internal.request import KeysetPagePayload, KeysetPaginatedSpec, QueryParamValue | ||
| from polymarket.errors import UnexpectedResponseError, UserInputError | ||
| from polymarket.models.rfq import ComboMarket | ||
| from polymarket.models.types import validate_ctf_condition_id | ||
|
|
||
| _MAX_COMBO_MARKETS_PAGE_SIZE = 100 | ||
|
|
||
|
|
||
| def list_combo_markets_spec( | ||
| *, | ||
| exclude: str | Sequence[str] | None = None, | ||
| ) -> KeysetPaginatedSpec[ComboMarket]: | ||
| params: dict[str, QueryParamValue] = {} | ||
| excluded = _coerce_excluded_condition_ids(exclude) | ||
| if excluded: | ||
| params["exclude"] = ",".join(excluded) | ||
|
|
||
| return KeysetPaginatedSpec( | ||
| service="rfq", | ||
| path="/v1/rfq/combo-markets", | ||
| parse_page=_parse_combo_markets_page, | ||
| base_params=params or None, | ||
| cursor_param="cursor", | ||
| ) | ||
|
|
||
|
|
||
| def validate_combo_markets_page_size(page_size: int) -> None: | ||
| if type(page_size) is not int: | ||
| raise UserInputError("page_size must be an int.") | ||
| if page_size < 1 or page_size > _MAX_COMBO_MARKETS_PAGE_SIZE: | ||
| raise UserInputError(f"page_size must be between 1 and {_MAX_COMBO_MARKETS_PAGE_SIZE}.") | ||
|
|
||
|
|
||
| def _parse_combo_markets_page(data: object) -> KeysetPagePayload[ComboMarket]: | ||
| if not isinstance(data, dict): | ||
| raise UnexpectedResponseError("Combo market response did not match expected shape") | ||
| payload = cast(dict[str, object], data) | ||
|
|
||
| raw_markets = payload.get("markets") | ||
| if not isinstance(raw_markets, list): | ||
| raise UnexpectedResponseError("Combo market response is missing markets array") | ||
| market_items = cast(list[object], raw_markets) | ||
| markets = tuple(ComboMarket.parse_response(item) for item in market_items) | ||
|
|
||
| raw_cursor = payload.get("next_cursor") | ||
| if raw_cursor is None: | ||
| next_cursor = None | ||
| elif isinstance(raw_cursor, str) and raw_cursor: | ||
| next_cursor = raw_cursor | ||
| else: | ||
| raise UnexpectedResponseError("Combo market next_cursor did not match expected shape") | ||
|
|
||
| return KeysetPagePayload(items=markets, server_next_cursor=next_cursor) | ||
|
|
||
|
|
||
| def _coerce_excluded_condition_ids(exclude: str | Sequence[str] | None) -> tuple[str, ...]: | ||
| if exclude is None: | ||
| return () | ||
| if isinstance(exclude, str): | ||
| return (validate_ctf_condition_id(exclude),) | ||
| if isinstance(exclude, bytes): | ||
| raise UserInputError("exclude does not accept bytes") | ||
| return tuple(validate_ctf_condition_id(value) for value in exclude) | ||
|
|
||
|
|
||
| __all__ = ["list_combo_markets_spec", "validate_combo_markets_page_size"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing LTE pagination sentinel
Medium Severity
_parse_combo_markets_pagetreats any non-emptynext_cursorstring as a real cursor. Elsewhere in this SDK,LTE=is the documented end-of-pagination sentinel and is normalized to no next page vianext_cursor_or_none. If the RFQ combo-markets API uses that sentinel, callers will seehas_moretrue and issue another request withcursor=LTE=instead of stopping.Reviewed by Cursor Bugbot for commit 0fbae90. Configure here.