Skip to contents

Simulates placing a new order (limit or market) to the KuCoin Spot trading system asynchronously for testing purposes. This function validates parameters and checks the signature without actually placing an order. It returns the same response structure as the actual order placement endpoint.

Usage

add_order_test_impl(
  keys = get_api_keys(),
  base_url = get_base_url(),
  type,
  symbol,
  side,
  clientOid = NULL,
  price = NULL,
  size = NULL,
  funds = NULL,
  stp = NULL,
  tags = NULL,
  remark = NULL,
  timeInForce = NULL,
  cancelAfter = NULL,
  postOnly = NULL,
  hidden = NULL,
  iceberg = NULL,
  visibleSize = NULL,
  .__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().

type

Character string; order type: "limit" or "market". Required.

symbol

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

side

Character string; order side: "buy" or "sell". Required.

clientOid

Character string; unique client order ID (recommended UUID, max 40 chars). Optional.

price

Character string; price for limit orders (must align with priceIncrement). Required for limit orders.

size

Character string; quantity for limit or market orders (must align with baseIncrement). Required for limit, optional for market.

funds

Character string; funds for market orders (must align with quoteIncrement). Optional for market, mutually exclusive with size.

stp

Character string; self-trade prevention strategy: "CN", "CO", "CB", or "DC". Optional.

tags

Character string; order tag (max 20 ASCII chars). Optional.

remark

Character string; order remarks (max 20 ASCII chars). Optional.

timeInForce

Character string; time-in-force strategy: "GTC", "GTT", "IOC", or "FOK". Optional, defaults to "GTC".

cancelAfter

Integer; cancel after n seconds (for GTT). Optional.

postOnly

Logical; passive order flag (disabled for IOC/FOK). Optional, defaults to FALSE.

hidden

Logical; hide order from order book. Optional, defaults to FALSE.

iceberg

Logical; show only visible portion in iceberg orders. Optional, defaults to FALSE.

visibleSize

Character string; max visible quantity for iceberg orders. Optional.

Value

Promise resolving to a data.table containing:

  • orderId (character): Simulated unique order ID.

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

Details

Workflow Overview

  1. Parameter Validation: Validates required and optional parameters based on order type (limit/market) using rlang::arg_match0 for enumerated values.

  2. Request Body Construction: Builds a JSON body with mandatory and optional parameters.

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

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

  5. Response Processing: Parses the response, validates success, and returns simulated order details as a data.table.

API Endpoint

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

Usage

Utilised to test order placement logic and signature validity without affecting the actual trading system.

Official Documentation

KuCoin Add Order Test

Examples

if (FALSE) { # \dontrun{
main_async <- coro::async(function() {
  # Test a limit buy order
  test_order <- await(add_order_test_impl(
    type = "limit",
    symbol = "BTC-USDT",
    side = "buy",
    price = "50000",
    size = "0.0001",
    clientOid = uuid::UUIDgenerate(),
    remark = "Test limit order"
  ))
  print(test_order)

  # Test a market buy order with funds
  test_market_order <- await(add_order_test_impl(
    type = "market",
    symbol = "BTC-USDT",
    side = "buy",
    funds = "10",
    clientOid = uuid::UUIDgenerate()
  ))
  print(test_market_order)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }