Skip to contents

Cancels a batch of stop orders on the KuCoin Spot trading system asynchronously by sending a DELETE request to the /api/v1/stop-order/cancel endpoint. Returns a data.table with the IDs of the canceled stop orders.

Usage

cancel_stop_order_batch_impl(
  keys = get_api_keys(),
  base_url = get_base_url(),
  query = list(),
  .__coro_env_parent__ = <environment>
)

Arguments

keys

List; API configuration parameters from get_api_keys(). Defaults to get_api_keys().

base_url

Character string; base URL for the KuCoin API. Defaults to get_base_url().

query

Named list; optional query parameters for filtering (e.g., list(symbol = "ETH-BTC", orderIds = "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df")).

Value

Promise resolving to a data.table with one row containing:

  • cancelledOrderIds (list): A list of character strings representing the IDs of the canceled stop orders.

Details

What is a Stop Order and Batch Cancellation?

A stop order is a conditional order that triggers a market or limit order when a specified price (stop price) is reached, commonly used for:

  • Loss Limiting: Sell an asset if its price drops to a threshold (e.g., sell BTC at $48,000 if it falls from $50,000).

  • Breakout Trading: Buy an asset if its price rises past a resistance level (e.g., buy BTC at $52,000 if it breaks $51,000). Batch cancellation allows you to cancel multiple stop orders at once, which is useful for:

  • Portfolio Adjustment: Clear all stop orders for a symbol (e.g., "BTC-USDT") if market conditions shift unexpectedly.

  • Strategy Reset: Cancel outdated stop orders across multiple pairs or IDs when refining your trading plan.

  • Risk Management: Remove pending stops during high volatility to avoid unintended triggers (e.g., canceling stops on ETH-BTC during a flash crash). For example, if you have stop orders at $48,000 and $47,000 for BTC-USDT but anticipate a rally, batch canceling them prevents premature sales.

Description

This function cancels multiple stop orders using optional filters (symbol, tradeType, orderIds) via a DELETE request, returning the canceled order IDs in a data.table.

Workflow

  1. Parameter Validation: Ensures query is a named list, validates symbol if provided, and checks tradeType enum.

  2. Request Construction: Builds the endpoint URL with query parameters (symbol, tradeType, orderIds) using build_query.

  3. Authentication: Generates private API headers using build_headers() with the DELETE method and endpoint.

  4. API Request: Sends a DELETE request to the KuCoin API with a 3-second timeout via httr::DELETE.

  5. Response Processing: Parses the response with process_kucoin_response, confirms success ("200000"), and converts the cancelledOrderIds array to a data.table column as a list.

API Details

  • Endpoint: DELETE https://api.kucoin.com/api/v1/stop-order/cancel

  • Domain: Spot

  • API Channel: Private

  • API Permission: Spot

  • Rate Limit Pool: Spot

  • Rate Limit Weight: 3

  • SDK Service: Spot

  • SDK Sub-Service: Order

  • SDK Method Name: batchCancelStopOrder

  • Official Documentation: KuCoin Batch Cancel Stop Orders

Request

Query Parameters

  • symbol: String (optional) - Filter by trading pair symbol (e.g., "ETH-BTC"). Cancels all stop orders for this symbol if specified.

  • tradeType: Enum (optional) - Transaction type: "TRADE" (Spot), "MARGIN_TRADE" (Cross Margin), "MARGIN_ISOLATED_TRADE" (Isolated Margin). Defaults to "TRADE".

  • orderIds: String (optional) - Comma-separated list of stop order IDs (e.g., "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df").

Example Request

curl --location --request DELETE 'https://api.kucoin.com/api/v1/stop-order/cancel?symbol=ETH-BTC&tradeType=TRADE&orderIds=5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df'

Response

HTTP Code: 200

  • Content Type: application/json

Data Schema

  • code: String (required) - Response code ("200000" indicates success).

  • data: Object (required) - Contains:

    • cancelledOrderIds: ArrayString (required) - List of canceled stop order IDs.

JSON Response Example

{
  "code": "200000",
  "data": {
    "cancelledOrderIds": [
      "671124f9365ccb00073debd4"
    ]
  }
}

Examples

if (FALSE) { # \dontrun{
library(coro)
library(data.table)

main_async <- coro::async(function() {
  # Batch cancel stop orders for ETH-BTC
  canceled_orders <- await(cancel_stop_order_batch_impl(
    query = list(
      symbol = "ETH-BTC",
      tradeType = "TRADE",
      orderIds = "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df"
    )
  ))
  print(canceled_orders)
})

# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }