Signature
client.cancel_orders(order_id: str = None) -> Dict
Parameters
| Parameter | Type | Description |
|---|
order_id | string | Specific order to cancel. If None, cancels all open orders |
Returns
Single order:
| Field | Type | Description |
|---|
message | string | Status message |
refund_amount | float | USDC refunded (for buy orders) |
All orders:
| Field | Type | Description |
|---|
cancelled | int | Number of orders cancelled |
total | int | Total open orders processed |
total_refund | float | Total USDC refunded |
errors | list | List of errors (empty if all succeeded) |
Each error object in the errors list contains:
order_id: The order that failed to cancel
error: Reason for the failure
Example
from polyhush import PolyhushClient
client = PolyhushClient(api_key="your-api-key")
# Cancel a specific order
result = client.cancel_orders(order_id="ord_abc123")
print(f"Refunded: ${result.get('refund_amount', 0):.2f}")
# Cancel all open orders
result = client.cancel_orders()
print(f"Cancelled {result['cancelled']} of {result['total']} orders")
print(f"Total refund: ${result['total_refund']:.2f}")
# Check for any errors
if result.get('errors'):
print(f"\nWarning: {len(result['errors'])} orders failed to cancel:")
for err in result['errors']:
print(f" Order {err['order_id']}: {err['error']}")
Cancelling buy orders releases reserved funds back to your available balance. Cancelling sell orders releases reserved shares.