Skip to contents

Retrieves a paginated list of current OCO orders from the KuCoin Spot trading system asynchronously by sending a GET request to the /api/v3/oco/orders endpoint.

Usage

get_oco_order_list_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 and pagination (e.g., list(symbol = "BTC-USDT", pageSize = 10)).

Value

Promise resolving to a data.table 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 (profit target) with a stop-limit order (loss limit), canceling one when the other executes. Listing all OCO orders is useful for:

  • Portfolio Oversight: Review all active OCO strategies across trading pairs to ensure alignment with market conditions.

  • Bulk Management: Identify orders to adjust or cancel based on status (e.g., canceling "NEW" orders if a trend reverses).

  • Historical Insight: Filter by time to analyze past OCO performance for strategy refinement. For example, listing OCO orders might show multiple BTC-USDT pairs with varying profit/loss levels, helping you optimize risk across your portfolio.

Description

This function fetches a list of OCO orders with optional filters (symbol, startAt, etc.), sorted by latest first, and returns them in a data.table.

Workflow

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

  2. Request Construction: Constructs the endpoint URL with query parameters from build_query.

  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 items array to a data.table, returning an empty structured table if no items exist.

API Details

  • Endpoint: GET https://api.kucoin.com/api/v3/oco/orders

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

  • Official Documentation: KuCoin Get OCO Order List

Request

Query Parameters

  • symbol: String (optional) - Filter by trading pair symbol (e.g., "BTC-USDT").

  • startAt: Integer (optional) - Start time in milliseconds.

  • endAt: Integer (optional) - End time in milliseconds.

  • orderIds: String (optional) - Comma-separated list of order IDs (up to 500).

  • pageSize: Integer (optional) - Results per page (10–500, default 50).

  • currentPage: Integer (optional) - Page number (minimum 1, default 1).

Example Request

curl --location --request GET 'https://api.kucoin.com/api/v3/oco/orders?symbol=BTC-USDT&pageSize=10&currentPage=1'

Response

HTTP Code: 200

  • Content Type: application/json

Data Schema

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

  • data: Object (required) - Contains:

    • currentPage: Integer (required) - Current page number.

    • pageSize: Integer (required) - Number of items per page.

    • totalNum: Integer (required) - Total number of OCO orders.

    • totalPage: Integer (required) - Total number of pages.

    • items: ArrayObject (required) - List of OCO orders, each with:

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

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

      • clientOid: String (required) - Client-assigned 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": {
    "currentPage": 1,
    "pageSize": 50,
    "totalNum": 1,
    "totalPage": 1,
    "items": [
      {
        "orderId": "674c3cfa72cf2800072ee7ce",
        "symbol": "BTC-USDT",
        "clientOid": "5c52e1203aa6f3g7f1e493fb",
        "orderTime": 1733049594803,
        "status": "NEW"
      }
    ]
  }
}

Examples

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

main_async <- coro::async(function() {
  # Retrieve OCO order list with filter
  oco_list <- await(get_oco_order_list_impl(
    query = list(symbol = "BTC-USDT", pageSize = 10, currentPage = 1)
  ))
  print(oco_list)
})

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