feat: cancel and cancel_orders return full order objects with sizeMatched#320
feat: cancel and cancel_orders return full order objects with sizeMatched#320skyc1e wants to merge 1 commit intoPolymarket:mainfrom
Conversation
…ched After a successful cancellation, fetch the complete order via get_order so callers can inspect size_matched without waiting for a fill event. Falls back to the raw API response if get_order fails. Closes Polymarket#316
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| return self.get_order(order_id) | ||
| except Exception: | ||
| return response | ||
| return response |
There was a problem hiding this comment.
cancel() returns incompatible dict shapes across code paths
Medium Severity
cancel() returns two structurally incompatible dict types: on success it returns a full order object (e.g. keys id, status, size_matched), but on failure or get_order error it returns the raw API response (keys canceled, not_canceled). Callers who previously inspected result.get("canceled") to determine outcome will silently get None on a successful cancel, incorrectly concluding the cancel failed. In contrast, cancel_orders() always returns a consistent {"canceled": [...], "not_canceled": {...}} structure. The asymmetry between cancel() and cancel_orders() makes uniform handling impossible without brittle key-sniffing.
|
I need this change on backend so that I don't need to make another RT to get filled size. I probably need to post this issue somewhere else, this can not be solved on sdk level. Thanks for the PR anyways! |


Summary
Closes #316.
After a successful cancellation the CLOB API returns only order IDs. Callers often need the full order object — in particular — to know how much was filled before the cancel, without waiting for a fill event.
This PR enriches the return value of and by fetching each canceled order via :
Test plan
Note
Medium Risk
Changes the return shape/behavior of
cancelandcancel_ordersby adding follow-upget_orderfetches, which may break callers relying on the prior raw cancel response and adds extra network calls/failure modes.Overview
After a successful cancel,
ClobClient.cancelnow fetches and returns the full order object (so callers can read fields likesizeMatched), while falling back to the raw cancel response if the order wasn’t canceled or the follow-upget_orderfails.ClobClient.cancel_ordersnow returns{canceled, not_canceled}wherecanceledcontains full order objects for each successfully canceled ID (degrading to{"id": <orderId>}per-order onget_orderfailure), and adds unit tests covering success/fallback and partial-failure scenarios.Written by Cursor Bugbot for commit 374a4f7. This will update automatically on new commits. Configure here.