Skip to contents

Cancels a batch of OCO (One-Cancels-the-Other) orders on the KuCoin Spot trading system asynchronously by sending a DELETE request to the /api/v3/oco/orders endpoint. Returns a data.table with the IDs of the canceled limit and stop-limit orders associated with the OCO orders.

Usage

cancel_oco_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(orderIds = "674c388172cf2800072ee746,674c38bdfd8300000795167e", symbol = "BTC-USDT")).

Value

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

  • cancelledOrderIds (list): A list of character strings representing the IDs of the canceled limit and stop-limit orders associated with the OCO orders.

Details

What is an OCO Order and Batch Cancellation?

An OCO (One-Cancels-the-Other) order pairs a limit order (e.g., to secure profits) with a stop-limit order (e.g., to cap losses), canceling one when the other executes. Batch cancellation of OCO orders is useful for:

  • Portfolio Cleanup: Remove all OCO orders for a symbol (e.g., "BTC-USDT") or specific IDs if market conditions no longer favor your strategy.

  • Risk Adjustment: Cancel multiple OCOs during unexpected volatility to avoid unintended triggers (e.g., canceling BTC-USDT OCOs during a flash crash).

  • Strategy Overhaul: Reset all OCO orders across trading pairs to implement a new trading plan without manual intervention. For example, if you have OCO orders on BTC-USDT to sell at $55,000 (profit) or $48,000 (stop-loss) but anticipate a breakout, batch canceling them prevents premature execution.

Description

This function cancels multiple OCO orders using optional filters (orderIds, symbol) via a DELETE request. If no parameters are provided, all OCO orders are canceled by default. The response includes the IDs of the canceled limit and stop-limit orders.

Workflow

  1. Parameter Validation: Ensures query is a named list and validates symbol and orderIds if provided.

  2. Request Construction: Builds the endpoint URL with query parameters (orderIds, symbol) 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/v3/oco/orders

  • 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: batchCancelOcoOrders

  • Official Documentation: KuCoin Batch Cancel OCO Order

Request

Query Parameters

  • orderIds: String (optional) - Comma-separated list of OCO order IDs (e.g., "674c388172cf2800072ee746,674c38bdfd8300000795167e"). If omitted, all OCO orders are canceled.

  • symbol: String (optional) - Trading pair symbol (e.g., "BTC-USDT"). If omitted, OCO orders for all symbols are canceled.

Example Request

curl --location --request DELETE 'https://api.kucoin.com/api/v3/oco/orders?orderIds=674c388172cf2800072ee746,674c38bdfd8300000795167e&symbol=BTC-USDT'

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 order IDs (typically two per OCO order: limit and stop-limit components).

JSON Response Example

{
  "code": "200000",
  "data": {
    "cancelledOrderIds": [
      "vs93gpqc750mkk57003gok6i",
      "vs93gpqc750mkk57003gok6j",
      "vs93gpqc75c39p83003tnriu",
      "vs93gpqc75c39p83003tnriv"
    ]
  }
}

Examples

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

main_async <- coro::async(function() {
  # Batch cancel specific OCO orders for BTC-USDT
  canceled_orders <- await(cancel_oco_order_batch_impl(
    query = list(
      orderIds = "674c388172cf2800072ee746,674c38bdfd8300000795167e",
      symbol = "BTC-USDT"
    )
  ))
  print(canceled_orders)
})

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