Skip to contents

Retrieves basic information about an OCO order using its system-generated order ID (orderId) from the KuCoin Spot trading system asynchronously by sending a GET request to the /api/v3/oco/order/{orderId} endpoint.

Usage

get_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 retrieve (e.g., "674c3b6e688dea0007c7bab2"). Required.

Value

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

  • orderId (character): Unique order ID generated by the KuCoin system.

  • symbol (character): Trading pair symbol (e.g., "BTC-USDT").

  • clientOid (character): Client-assigned order ID.

  • orderTime (integer): Order placement time in milliseconds.

  • status (character): Order status ("NEW", "DONE", "TRIGGERED", "CANCELED").

Details

What is an OCO Order?

An OCO order combines a limit order (e.g., to take profits) with a stop-limit order (e.g., to limit losses), canceling one when the other executes. Retrieving this info is useful for:

  • Status Monitoring: Check if the order is "NEW", "TRIGGERED", or "CANCELED" to assess its current state.

  • Trade Review: Confirm order details like symbol and placement time match your strategy.

  • Decision Making: Use status to decide whether to adjust or cancel (e.g., if still "NEW" during a trend shift). For example, checking an OCO order placed at $50,000 for BTC might show it’s still "NEW", prompting a tighter stop if volatility rises.

Description

This function fetches basic OCO order details (orderId, symbol, clientOid, orderTime, status) and returns them in a data.table.

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 GET method and endpoint.

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

  5. Response Processing: Parses the response, confirms success ("200000"), and converts the data object to a data.table.

API Details

  • Endpoint: GET https://api.kucoin.com/api/v3/oco/order/{orderId}

  • Domain: Spot

  • API Channel: Private

  • API Permission: General

  • Rate Limit Pool: Spot

  • Rate Limit Weight: 2

  • SDK Service: Spot

  • SDK Sub-Service: Order

  • SDK Method Name: getOcoOrderByOrderId

  • Official Documentation: KuCoin Get OCO Order By OrderId

Request

Path Parameters

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

Example Request

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

Response

HTTP Code: 200

  • Content Type: application/json

Data Schema

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

  • data: Object (required) - Contains:

    • symbol: String (required) - Trading pair symbol.

    • clientOid: String (required) - Client-assigned order ID.

    • orderId: String (required) - System-generated order ID.

    • orderTime: Integer (required) - Order placement time in milliseconds.

    • status: Enum (required) - Order status: "NEW", "DONE", "TRIGGERED", "CANCELED".

JSON Response Example

{
  "code": "200000",
  "data": {
    "orderId": "674c3b6e688dea0007c7bab2",
    "symbol": "BTC-USDT",
    "clientOid": "5c52e1203aa6f37f1e493fb",
    "orderTime": 1733049198863,
    "status": "NEW"
  }
}

Examples

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

main_async <- coro::async(function() {
  # Retrieve OCO order by orderId
  oco_order <- await(get_oco_order_by_order_id_impl(
    orderId = "674c3b6e688dea0007c7bab2"
  ))
  print(oco_order)
})

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