Cancel Order
Cancels an existing open order on Gate.io exchange. This node is useful for managing your active orders and implementing dynamic trading strategies.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Client Id - The unique client identifier from the Connect node. Can be left empty if using direct credentials.
- Order ID - The unique identifier of the order to cancel (obtained from Buy Order, Sell Order, or Get Order nodes).
- Currency Pair - The trading pair of the order (e.g.,
BTC_USDT,ETH_USDT). Must match the original order's pair.
Options
- Api Key - Gate.io API key credential (optional if using Client Id from Connect node).
- Secret Key - Gate.io API secret key credential (optional if using Client Id from Connect node).
Output
- Result - An object containing the cancelled order details with all order information including:
- Order ID and status
- Currency pair
- Order type and side
- Amount and price
- Filled amount (if partially executed)
- Creation and cancellation timestamps
- And other order-related fields
How It Works
The Cancel Order node executes the following steps:
- Authenticates using either Client Id or direct credentials
- Validates that Order ID is not empty
- Validates that Currency Pair is not empty
- Sends a cancellation request to Gate.io API for the specified order
- Returns the complete order details after cancellation
Requirements
- Either a valid Client Id from Connect node OR API credentials
- Valid Order ID from a previously created order
- Correct Currency Pair matching the original order
- The order must be in an open/active state (not already filled or cancelled)
Error Handling
The node will return specific errors in the following cases:
- ErrInternal - Failed to retrieve input parameters
- ErrInvalidArg - Order ID or Currency Pair is empty
- ErrCancelOrder - Failed to cancel the order (order may not exist, already filled, already cancelled, or wrong currency pair)
Usage Notes
- You can only cancel orders that are still open (not filled or already cancelled)
- The Order ID must match an order you created with your API credentials
- The Currency Pair must exactly match the original order
- Partially filled orders can be cancelled (unfilled portion will be cancelled)
- The returned result includes information about any partial fills
- Cancelled orders cannot be reactivated; you must create a new order
Best Practices
- Store Order IDs when creating orders to cancel them later
- Implement error handling for orders that may already be filled
- Use Get Order to check order status before attempting cancellation
- Cancel orders before flow termination to avoid unwanted executions
- Use List My Orders to find orders to cancel
- Implement timeout logic to cancel orders that aren't filled within expected time
- Consider partial fills when cancelling orders
Example Usage Scenarios
Cancel a Specific Order
Inputs:
- Client Id: (from Connect node)
- Order ID: 12345678
- Currency Pair: BTC_USDT
Result: Cancels order 12345678 for BTC_USDT pair
Cancel Order Created Earlier in Flow
[Buy Order] -> Store order_id
|
+-> [Wait 5 minutes]
|
+-> [Get Order: check if filled]
|
+-> [If: status = "open"]
|
+-> [Cancel Order using stored order_id]
Cancel with Direct Credentials
Inputs:
- Client Id: (empty)
- Order ID: 12345678
- Currency Pair: ETH_USDT
Options:
- Api Key: (your credential)
- Secret Key: (your credential)
Result: Cancels without Connect node using direct authentication
Example Flow: Conditional Order Cancellation
[Connect]
|
+-> [Buy Order: BTC at $50000]
| |
| +-> [Store: order_id]
|
+-> [Loop Every 30 seconds]
| |
| +-> [Get Price: BTC_USDT]
| |
| +-> [If: price > $52000]
| |
| +-> True: [Cancel Order]
| | |
| | +-> [Buy Order at new price]
| | +-> [Break Loop]
| |
| +-> False: [Continue Loop]
|
+-> [Disconnect]
Example Flow: Timeout Cancellation
[Connect]
|
+-> [Buy Order]
| |
| +-> [Store: order_id, timestamp]
|
+-> [Wait 10 minutes]
|
+-> [Get Order: check status]
|
+-> [If: status = "open"]
| |
| +-> [Cancel Order]
| +-> [Log: Order timeout, cancelled]
|
+-> [Disconnect]
Example Flow: Cancel All Open Orders
[Connect]
|
+-> [List My Orders]
|
+-> [For Each: order in orders]
| |
| +-> [Cancel Order]
| Inputs:
| - Order ID: order.id
| - Currency Pair: order.currency_pair
|
+-> [Log: All orders cancelled]
|
+-> [Disconnect]
Example Flow: Smart Order Management
[Connect]
|
+-> [Buy Order: limit order below market]
| |
| +-> [Store: order_id]
|
+-> [Loop for 1 hour, check every minute]
| |
| +-> [Get Order: order_id]
| |
| +-> [Check status]
| |
| +-> If filled: [Break loop, success]
| +-> If open and price moved: [Cancel] -> [New order]
| +-> If timeout: [Cancel] -> [Exit]
|
+-> [Disconnect]
Understanding Order States
Orders can be in different states:
- open - Order is active and awaiting execution
- closed - Order has been completely filled
- cancelled - Order has been cancelled (by you or system)
You can only cancel orders in the open state.
Handling Partial Fills
If an order is partially filled when you cancel it:
- The filled portion cannot be reversed
- Only the unfilled portion is cancelled
- The result object shows both filled and unfilled amounts
- Fees are charged only on the filled portion
Example:
Original Order: Buy 1.0 BTC at $50,000
Filled: 0.3 BTC
Cancelled: 0.7 BTC (unfilled portion)
Result: You received 0.3 BTC, order for 0.7 BTC is cancelled
Common Errors and Solutions
Order Not Found
Error: ErrCancelOrder - Order not found
Solutions:
- Verify the Order ID is correct
- Check the Currency Pair matches the original order
- Order may have already been filled or cancelled
- Use Get Order to check current status
Order Already Cancelled
Error: ErrCancelOrder - Order already cancelled
Solutions:
- Check order status before attempting cancellation
- Implement error handling for already-cancelled orders
- Use List My Orders to see current open orders
Order Already Filled
Error: ErrCancelOrder - Order already filled
Solutions:
- Order executed before cancellation request
- This is a race condition - implement proper status checks
- Accept that order was filled and handle accordingly
Best Practice Pattern
[Get Order to check status]
|
+-> [If: status = "open"]
| |
| +-> Try:
| | +-> [Cancel Order]
| | +-> [Log: Successfully cancelled]
| |
| +-> Catch:
| +-> [Log: Cancellation failed, may be filled]
| +-> [Get Order: verify final status]
|
+-> [Else: Log: Order already completed]
Related Nodes
- Connect - Establishes the client session needed for this node
- Buy Order - Creates buy orders that can be cancelled
- Sell Order - Creates sell orders that can be cancelled
- Get Order - Check order status before or after cancellation
- List My Orders - Find open orders that can be cancelled