Skip to main content

Signature

client.cancel_orders(order_id: str = None) -> Dict

Parameters

ParameterTypeDescription
order_idstringSpecific order to cancel. If None, cancels all open orders

Returns

Single order:
FieldTypeDescription
messagestringStatus message
refund_amountfloatUSDC refunded (for buy orders)
All orders:
FieldTypeDescription
cancelledintNumber of orders cancelled
totalintTotal open orders processed
total_refundfloatTotal USDC refunded
errorslistList 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.