Skip to content

feat: cancel and cancel_orders return full order objects with sizeMatched#320

Open
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/cancel-return-order-with-size-matched
Open

feat: cancel and cancel_orders return full order objects with sizeMatched#320
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/cancel-return-order-with-size-matched

Conversation

@skyc1e
Copy link
Copy Markdown

@skyc1e skyc1e commented Apr 1, 2026

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 :

  • **** — on success returns the full order dict (including ). Falls back to the raw API response if fails or the order was not canceled.
  • **** — returns . If fails for an individual order, that entry degrades to so one transient failure does not break the entire batch.

Test plan

  • Added with 8 unit tests (mocked HTTP):
    • cancel returns full order on success
    • cancel returns raw response when order not canceled
    • cancel returns raw response when get_order fails
    • cancel_orders returns full order objects
    • cancel_orders preserves not_canceled field
    • cancel_orders degrades gracefully when get_order fails
    • cancel_orders handles empty response
    • cancel_orders continues processing after single get_order failure

Note

Medium Risk
Changes the return shape/behavior of cancel and cancel_orders by adding follow-up get_order fetches, which may break callers relying on the prior raw cancel response and adds extra network calls/failure modes.

Overview
After a successful cancel, ClobClient.cancel now fetches and returns the full order object (so callers can read fields like sizeMatched), while falling back to the raw cancel response if the order wasn’t canceled or the follow-up get_order fails.

ClobClient.cancel_orders now returns {canceled, not_canceled} where canceled contains full order objects for each successfully canceled ID (degrading to {"id": <orderId>} per-order on get_order failure), 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.

…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
@skyc1e skyc1e requested a review from a team as a code owner April 1, 2026 20:18
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

@timurrakhimzhan
Copy link
Copy Markdown

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!

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.

Make cancelOrder/cancelOrders return orders instead of just ids

2 participants