Skip to contents

Retrieves all active spot orders for a specified symbol from the KuCoin Spot trading system asynchronously. This function returns a data.table with detailed information about each active order, sorted by the latest update time in descending order.

Usage

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

symbol

Character string; the trading pair symbol (e.g., "BTC-USDT"). Required.

Value

Promise resolving to a data.table with columns corresponding to the order fields, including:

  • id (character): Unique order ID.

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

  • symbol (character): Trading pair.

  • opType (character): Operation type.

  • type (character): Order type ("limit" or "market").

  • side (character): Order side ("buy" or "sell").

  • price (character): Order price.

  • size (character): Order size.

  • funds (character): Order funds.

  • dealSize (character): Filled quantity.

  • dealFunds (character): Filled funds.

  • cancelledSize (character): Canceled quantity.

  • cancelledFunds (character): Canceled funds.

  • remainSize (character): Remaining quantity.

  • remainFunds (character): Remaining funds.

  • fee (character): Handling fees.

  • feeCurrency (character): Fee currency.

  • stp (character or NA): Self Trade Prevention strategy.

  • timeInForce (character): Time in force.

  • postOnly (logical): Post-only flag.

  • hidden (logical): Hidden order flag.

  • iceberg (logical): Iceberg order flag.

  • visibleSize (character): Visible size for iceberg orders.

  • cancelAfter (integer): Seconds until cancellation for GTT.

  • channel (character): Order channel.

  • remark (character or NA): Order remarks.

  • tags (character or NA): Order tags.

  • cancelExist (logical): Indicates a cancellation record.

  • tradeType (character): Trade type.

  • inOrderBook (logical): Whether in the order book.

  • tax (character): Tax information.

  • active (logical): Order status (true = active).

  • createdAt (integer): Creation timestamp (milliseconds).

  • lastUpdatedAt (integer): Last update timestamp (milliseconds).

  • createdAtDatetime (POSIXct): Creation time in UTC.

  • lastUpdatedAtDatetime (POSIXct): Last update time in UTC.

Details

Description

This endpoint fetches all active orders for a given trading pair (e.g., "BTC-USDT"). Active orders are those currently in the order book and not fully filled or canceled. The orders are returned in descending order based on their last update time.

Workflow

  1. Parameter Validation: Ensures symbol is a non-empty string and a valid trading pair.

  2. Request Construction: Builds the endpoint URL with symbol as a query 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.

  5. Response Processing: Parses the response, converts the array of orders to a data.table, and adds createdAtDatetime and lastUpdatedAtDatetime columns.

API Details

  • Endpoint: GET https://api.kucoin.com/api/v1/hf/orders/active?symbol={symbol}

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

  • Official Documentation: KuCoin Get Open Orders

Request

Query Parameters

  • symbol: String (required) - The trading pair symbol (e.g., "BTC-USDT").

Example Request

curl --location --request GET 'https://api.kucoin.com/api/v1/hf/orders/active?symbol=BTC-USDT'

Response

HTTP Code: 200

  • Content Type: application/json

Data Schema

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

  • data: Array of objects (required) - List of active orders, each with fields such as:

    • id: String - Unique order ID.

    • clientOid: String - Client-assigned order ID.

    • symbol: String - Trading pair.

    • opType: String - Operation type.

    • type: Enum - Order type: "limit" or "market".

    • side: Enum - Order side: "buy" or "sell".

    • price: String - Order price.

    • size: String - Order size.

    • funds: String - Order funds.

    • dealSize: String - Filled quantity.

    • dealFunds: String - Filled funds.

    • cancelledSize: String - Canceled quantity.

    • cancelledFunds: String - Canceled funds.

    • remainSize: String - Remaining quantity.

    • remainFunds: String - Remaining funds.

    • fee: String - Handling fees.

    • feeCurrency: String - Fee currency.

    • stp: Enum - Self Trade Prevention: "DC", "CO", "CN", "CB" or null.

    • timeInForce: Enum - Time in force: "GTC", "GTT", "IOC", "FOK".

    • postOnly: Boolean - Post-only flag.

    • hidden: Boolean - Hidden order flag.

    • iceberg: Boolean - Iceberg order flag.

    • visibleSize: String - Visible size for iceberg orders.

    • cancelAfter: Integer - Seconds until cancellation for GTT.

    • channel: String - Order channel.

    • remark: String or null - Order remarks.

    • tags: String or null - Order tags.

    • cancelExist: Boolean - Indicates a cancellation record.

    • tradeType: String - Trade type.

    • inOrderBook: Boolean - Whether in the order book.

    • tax: String - Tax information.

    • active: Boolean - Order status (true = active).

    • createdAt: Integer - Creation timestamp in milliseconds.

    • lastUpdatedAt: Integer - Last update timestamp in milliseconds.

JSON Response Example

{
  "code": "200000",
  "data": [
    {
      "id": "67120bbef094e200070976f6",
      "clientOid": "5c52e11203aa677f33e493fb",
      "symbol": "BTC-USDT",
      "opType": "DEAL",
      "type": "limit",
      "side": "buy",
      "price": "50000",
      "size": "0.00001",
      "funds": "0.5",
      "dealSize": "0",
      "dealFunds": "0",
      "fee": "0",
      "feeCurrency": "USDT",
      "stp": null,
      "timeInForce": "GTC",
      "postOnly": false,
      "hidden": false,
      "iceberg": false,
      "visibleSize": "0",
      "cancelAfter": 0,
      "channel": "API",
      "remark": "order remarks",
      "tags": "order tags",
      "cancelExist": false,
      "tradeType": "TRADE",
      "inOrderBook": true,
      "cancelledSize": "0",
      "cancelledFunds": "0",
      "remainSize": "0.00001",
      "remainFunds": "0.5",
      "tax": "0",
      "active": true,
      "createdAt": 1729235902748,
      "lastUpdatedAt": 1729235909862
    }
  ]
}

Examples

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

main_async <- coro::async(function() {
  # Retrieve open orders for BTC-USDT
  open_orders <- await(get_open_orders_impl(symbol = "BTC-USDT"))
  print(open_orders)
})

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