Skip to contents

Places multiple new orders (up to 20) to the KuCoin Spot trading system asynchronously. This function validates a list of orders, constructs a batch request, and returns the placement results for each order.

Usage

add_order_batch_impl(
  keys = get_api_keys(),
  base_url = get_base_url(),
  order_list,
  .__coro_env_parent__ = <environment>
)

Arguments

keys

List; API configuration parameters from get_api_keys(), including:

  • api_key (character): KuCoin API key.

  • api_secret (character): KuCoin API secret.

  • api_passphrase (character): KuCoin API passphrase.

  • key_version (character): API key version (e.g., "2"). Defaults to get_api_keys().

base_url

Character string; base URL for the KuCoin API. Defaults to get_base_url().

order_list

List; a list of orders, where each order is a list with parameters:

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

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

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

  • clientOid (character): Unique client order ID (max 40 chars). Optional.

  • price (character): Price for limit orders. Required for limit.

  • size (character): Quantity for limit or market orders. Required for limit, optional for market.

  • funds (character): Funds for market orders. Optional for market, mutually exclusive with size.

  • stp (character): Self-trade prevention: "CN", "CO", "CB", or "DC". Optional.

  • tags (character): Order tag (max 20 ASCII chars). Optional.

  • remark (character): Order remarks (max 20 ASCII chars). Optional.

  • timeInForce (character): Time-in-force: "GTC", "GTT", "IOC", or "FOK". Optional, defaults to "GTC".

  • cancelAfter (integer): Cancel after n seconds (for GTT). Optional.

  • postOnly (logical): Passive order flag. Optional, defaults to FALSE.

  • hidden (logical): Hide order from order book. Optional, defaults to FALSE.

  • iceberg (logical): Iceberg order flag. Optional, defaults to FALSE.

  • visibleSize (character): Visible quantity for iceberg orders. Optional.

Value

Promise resolving to a data.table containing results for each order, with columns:

  • success (logical): Whether the order placement was successful.

  • orderId (character): Unique order ID (if successful).

  • clientOid (character): Client-specified order ID (if provided).

  • failMsg (character): Error message (if failed).

Details

Workflow Overview

  1. Parameter Validation: Ensures the order_list contains 1–20 valid orders, each validated via validate_order().

  2. Request Body Construction: Builds a JSON body with the orderList key containing validated orders.

  3. Authentication: Generates headers with API credentials using build_headers().

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

  5. Response Processing: Parses the response and returns results as a data.table.

API Endpoint

POST https://api.kucoin.com/api/v1/hf/orders/multi

Usage

Used to place multiple spot trading orders on KuCoin in a single request. Each order can be a limit or market order, with appropriate parameters. Requires sufficient funds and adheres to KuCoin's limits (e.g., max 20 orders per request, 2000 active orders per account).

Official Documentation

KuCoin Batch Add Orders

Examples

if (FALSE) { # \dontrun{
main_async <- coro::async(function() {
  # Define two orders
  order1 <- list(
    clientOid = uuid::UUIDgenerate(),
    symbol = "BTC-USDT",
    type = "limit",
    side = "buy",
    price = "30000",
    size = "0.00001",
    remark = "Batch buy"
  )
  order2 <- list(
    clientOid = uuid::UUIDgenerate(),
    symbol = "ETH-USDT",
    type = "market",
    side = "sell",
    size = "0.01"
  )
  # Place batch orders
  result <- await(add_order_batch_impl(order_list = list(order1, order2)))
  print(result)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }