Skip to main content
The cancelOrder action enables Vincent Apps to cancel a specific open order on Hyperliquid’s spot or perpetuals market.

Prerequisites

Before executing the cancelOrder action, the following conditions must be met:
  • Open Order: There must be an open order with the specified order ID that belongs to the Vincent User Agent Wallet.
  • Order Details: You must provide the symbol (trading pair for spot or asset for perp) and the order ID to cancel.
To learn more about executing Vincent Abilities, see the Executing Abilities guide.

Executing the precheck Function

The precheck function validates some prerequisites for executing a cancel order, without actually performing the operation. For the cancelOrder action, the precheck function will validate the following:
  • Order with provided order ID must exist and be open.
  • Parameters
  • Implementation
  • Response
The precheck function requires the following parameters:
import { HyperliquidAction } from '@lit-protocol/vincent-ability-hyperliquid';

{
  /**
   * The action to perform (must be HyperliquidAction.CANCEL_ORDER)
   */
  action: HyperliquidAction.CANCEL_ORDER;
  /**
   * Whether to use Hyperliquid testnet (optional, defaults to false)
   */
  useTestnet?: boolean;
  /**
   * Cancel order parameters
   */
  cancelOrder: {
    /**
     * The symbol for the order to cancel.
     * For spot: trading pair (e.g., "PURR/USDC")
     * For perp: base asset (e.g., "SOL", "ETH")
     */
    symbol: string;
    /**
     * The order ID to cancel (oid from the order)
     */
    orderId: number;
  };
}

Executing the execute Function

The execute function performs the actual cancel operation, removing the specified order from Hyperliquid. For the cancelOrder action, the execute function will:
  • Cancel the specified order on Hyperliquid.
  • Return the cancellation result from Hyperliquid.
  • Parameters
  • Implementation
  • Response
The execute function requires the following parameters:
import { HyperliquidAction } from '@lit-protocol/vincent-ability-hyperliquid';

{
  /**
   * The action to perform (must be HyperliquidAction.CANCEL_ORDER)
   */
  action: HyperliquidAction.CANCEL_ORDER;
  /**
   * Whether to use Hyperliquid testnet (optional, defaults to false)
   */
  useTestnet?: boolean;
  /**
   * Cancel order parameters
   */
  cancelOrder: {
    /**
     * The symbol for the order to cancel.
     * For spot: trading pair (e.g., "PURR/USDC")
     * For perp: base asset (e.g., "SOL", "ETH")
     */
    symbol: string;
    /**
     * The order ID to cancel (oid from the order)
     */
    orderId: number;
  };
}
The arbitrumRpcUrl parameter is not required for the execute function, only for precheck.

Important Considerations

To cancel an order, you need its order ID (oid). You can find order IDs by:
The symbol format differs between spot and perpetual orders:
  • Spot orders: Use trading pair format (e.g., “PURR/USDC”, “ETH/USDC”)
  • Perp orders: Use base asset only (e.g., “SOL”, “ETH”, “BTC”)
Make sure to use the correct format for the type of order you’re cancelling.
The order must be an open order that:
  • Belongs to the Vincent User’s Agent Wallet
  • Has not already been filled, cancelled, or expired
  • Is for the specified symbol
If the order doesn’t exist or has already been cancelled/filled, the cancellation will fail.
After the cancellation is executed, you can verify it was successful by:
  • Checking the open orders list using the Hyperliquid API
  • Confirming the order ID no longer appears in the list
  • Reviewing the cancellation result response

Reference Implementation

For a complete working example showing the full cancel order workflow including verification, see the cancel-order.spec.ts end-to-end test in the ability-hyperliquid package.

Next Steps

Explore the rest of the supported Hyperliquid actions: