Skip to contents

Cancels an existing OCO order on the KuCoin Spot trading system using its system-generated order ID (orderId) asynchronously by sending a DELETE request to the /api/v3/oco/order/{orderId} endpoint.

Usage

cancel_oco_order_by_order_id_impl(
  keys = get_api_keys(),
  base_url = get_base_url(),
  orderId,
  .__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().

orderId

Character string; the unique order ID to cancel (e.g., "674c316e688dea0007c7b986"). Required.

Value

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

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

Details

What is an OCO Order?

An OCO (One-Cancels-the-Other) order pairs a limit order (profit target) with a stop-limit order (loss limit). Canceling an OCO order removes both components, which is useful when:

  • Strategy Adjustment: Market conditions shift, and you no longer want automated profit-taking or loss-limiting (e.g., news-driven volatility).

  • Manual Intervention: You decide to manage the position manually instead of relying on pre-set triggers.

  • Error Correction: You need to correct an OCO order placed with incorrect parameters. For instance, if you set an OCO to sell BTC at $55,000 (profit) or $48,000 (stop-loss) but BTC’s volatility decreases, you might cancel it to set tighter limits.

Description

This function initiates the cancellation of an OCO order identified by its orderId, returning a data.table with the IDs of the canceled limit and stop-limit orders.

Workflow

  1. Parameter Validation: Ensures orderId is a non-empty string.

  2. Request Construction: Constructs the endpoint URL by embedding orderId as a path parameter.

  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, 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/order/{orderId}

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

  • Official Documentation: KuCoin Cancel OCO Order By OrderId

Request

Path Parameters

  • orderId: String (required) - The unique order ID generated by the trading system (e.g., "674c316e688dea0007c7b986").

Example Request

curl --location --request DELETE 'https://api.kucoin.com/api/v3/oco/order/674c316e688dea0007c7b986'

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 two order IDs related to the canceled OCO order (limit and stop-limit components).

JSON Response Example

{
  "code": "200000",
  "data": {
    "cancelledOrderIds": [
      "vs93gpqc6kkmkk57003gok16",
      "vs93gpqc6kkmkk57003gok17"
    ]
  }
}

Examples

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

main_async <- coro::async(function() {
  # Cancel an OCO order by orderId
  canceled_orders <- await(cancel_oco_order_by_order_id_impl(
    orderId = "674c316e688dea0007c7b986"
  ))
  print(canceled_orders)
})

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