cancel_all_orders
Cancel all open trading orders on Hyperliquid DEX to manage positions and clear pending transactions.
Instructions
Cancel all open orders
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Python handler function for the 'cancel_all_orders' tool. It calls the HyperliquidClient's cancel_all_orders method and returns a formatted success or error response.async def handle_cancel_all_orders(client: HyperliquidClient, args: Dict[str, Any]) -> Dict[str, Any]: """Handle cancel all orders request.""" result = await client.cancel_all_orders() if not result.success: raise ValueError(f"Failed to cancel all orders: {result.error}") return { "content": [ TextContent( type="text", text=f"All orders cancelled successfully!\n\n{json.dumps(result.data, indent=2)}", ) ] }
- hyperliquid_mcp_server/tools/trading.py:126-134 (registration)Python tool registration for 'cancel_all_orders' including schema (empty input) and description.cancel_all_orders_tool = Tool( name="cancel_all_orders", description="Cancel all open orders", inputSchema={ "type": "object", "properties": {}, "required": [], }, )
- Core helper method in HyperliquidClient that performs the API call to cancel all orders using 'cancelByCloid' with empty cancels list.async def cancel_all_orders(self) -> ApiResponse[Any]: """Cancel all orders.""" try: if not self.account: raise ValueError("Private key required for trading operations") action = {"type": "cancelByCloid", "cancels": []} nonce = self._generate_nonce() signature = await self._sign_action(action, nonce) payload = { "action": action, "nonce": nonce, "signature": signature, "vaultAddress": self.config.wallet_address, } response = await self.client.post("/exchange", json=payload) response.raise_for_status() return ApiResponse(success=True, data=response.json()) except Exception as e: return ApiResponse(success=False, error=str(e))
- src/tools/trading.ts:259-274 (handler)TypeScript handler function for the 'cancel_all_orders' tool. Mirrors the Python version, calling client.cancelAllOrders() and formatting response.export async function handleCancelAllOrders(client: HyperliquidClient, args: any) { const result = await client.cancelAllOrders(); if (!result.success) { throw new Error(`Failed to cancel all orders: ${result.error}`); } return { content: [ { type: 'text', text: `All orders cancelled successfully!\n\n${JSON.stringify(result.data, null, 2)}` } ] }; }
- src/tools/trading.ts:112-120 (registration)TypeScript tool registration for 'cancel_all_orders' including empty input schema.export const cancelAllOrdersTool: Tool = { name: 'cancel_all_orders', description: 'Cancel all open orders', inputSchema: { type: 'object', properties: {}, required: [] } };