TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/kucoin-api/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketAPIClient wraps KuCoin’s WebSocket API for order management, giving you REST-like method calls that are transmitted over a persistent WebSocket connection instead of HTTP. This dramatically reduces round-trip latency compared to traditional REST endpoints, making it ideal for high-frequency spot and margin order workflows. All methods return typed Promises and handle connection management, authentication, and reconnection automatically.
Initialization
Instantiate the client with your API credentials. The underlying WebSocket connection is established on first use.To connect to the testnet, pass
testnet: true in the constructor options rather than using a custom wsKey.attachEventListeners option (default true) automatically logs connection lifecycle events — open, reconnect, reconnected, authenticated, and exception — to the console. Disable it and call client.getWSClient().on(...) to attach your own handlers.
The wsKey Parameter
Every method accepts an optional wsKey parameter of type WSAPIWsKey. This lets you specify which underlying WebSocket connection should carry the request. Valid values are:
WS_KEY_MAP.wsApiSpotV1— default for all spot and margin methodsWS_KEY_MAP.wsApiFuturesV1— default for futures methods
wsKey if you want to route a request over an alternative supported connection (for example, a secondary domain). Omit it in normal usage.
Spot Order Methods
submitNewSpotOrder
Submit a new High-Frequency (HF) spot limit or market order.
SubmitHFOrderRequest parameters
SubmitHFOrderRequest parameters
Order type.
'limit' requires price; 'market' requires either size or funds.Trading pair, e.g.
'BTC-USDT'.Order side.
Unique client-generated order ID (UUID recommended). Used for deduplication.
Required for limit orders. Order price as a string.
Order quantity in base currency. Required for limit orders; optional for market orders if
funds is provided.Quote currency amount to spend (market buy) or receive (market sell). Used instead of
size for market orders.Time-in-force policy. Defaults to
'GTC' (Good Till Cancelled).Seconds until the order is cancelled (requires
timeInForce: 'GTT').If
true, the order will only be added to the order book, never matched immediately.If
true, the order is not visible in the order book.If
true, only visibleSize of the order is shown in the order book.Maximum visible quantity for iceberg orders.
Self-Trade Prevention strategy.
Order tag (max 20 characters).
Order remark (max 20 characters).
Client-side timestamp (milliseconds). Required when
iceberg is specified.Maximum milliseconds the order is valid after
clientTimestamp. Orders received after clientTimestamp + allowMaxTimeWindow are rejected.WSAPIOrderResponse fields
WSAPIOrderResponse fields
submitSyncSpotOrder
Submit a spot order and receive full fill details in the response (synchronous mode). Unlike submitNewSpotOrder, this waits for matching to complete and returns order status, fill size, remaining size, and match time.
SubmitHFOrderSyncResponse fields
SubmitHFOrderSyncResponse fields
Server-assigned order ID.
Client order ID.
Time the order was placed (milliseconds).
Original order quantity.
Filled quantity.
Remaining unfilled quantity.
Cumulative cancelled quantity.
'open' — order is active; 'done' — order is completed.Time of last match (milliseconds).
modifySpotOrder
Modify the price or size of an existing open spot order. Either orderId or clientOid must be provided.
ModifyHFOrderRequest parameters
ModifyHFOrderRequest parameters
Trading pair of the order to modify, e.g.
'BTC-USDT'.Server order ID of the order to modify. Either
orderId or clientOid is required.Client order ID of the order to modify.
New limit price for the order.
New quantity for the order.
cancelSpotOrder
Cancel an open spot order by order ID or client order ID.
WSAPICancelOrderRequest parameters
WSAPICancelOrderRequest parameters
cancelSyncSpotOrder
Cancel a spot order and receive full order status details in the response (synchronous mode).
SyncCancelHFOrderResponse fields
SyncCancelHFOrderResponse fields
Margin Order Methods
submitMarginOrder
Submit a new High-Frequency margin order (cross or isolated margin).
SubmitHFMarginOrderRequest parameters
SubmitHFMarginOrderRequest parameters
Unique client-generated order ID.
Order side.
Trading pair, e.g.
'BTC-USDT'.Order type. Defaults to
'limit'.false for cross margin (default), true for isolated margin.If
true, automatically borrows funds if the account balance is insufficient.If
true, automatically repays the loan when the order is filled.Required for limit orders.
Order quantity in base currency.
Quote currency amount (used instead of
size for market orders).Time-in-force policy.
Self-Trade Prevention strategy.
MarginSubmitOrderV3Response fields
MarginSubmitOrderV3Response fields
cancelMarginOrder
Cancel an open margin order by order ID or client order ID.
WSAPICancelOrderRequest shape as cancelSpotOrder — provide symbol plus either orderId or clientOid.
Common Response Envelope
All methods return aWSAPIResponse<T> wrapper:
WSAPIResponse fields
WSAPIResponse fields
Auto-generated request correlation ID.
The WS API operation that was executed (e.g.
'spot.order').'200000' on success; an error code string on failure.Human-readable error message (only present on failure).
The method-specific response payload.
Gateway request receipt time (milliseconds).
Gateway response dispatch time (milliseconds).
Optional rate-limit metadata:
{ limit, reset, remaining }.The WebSocket key used for this request.
Always
true for WS API responses, used internally to differentiate from streaming updates.Method Summary
| Method | WS Operation | Request Type | Response Data |
|---|---|---|---|
submitNewSpotOrder | spot.order | SubmitHFOrderRequest | WSAPIOrderResponse |
submitSyncSpotOrder | spot.sync_order | SubmitHFOrderRequest | SubmitHFOrderSyncResponse |
modifySpotOrder | spot.modify | ModifyHFOrderRequest | { newOrderId, clientOid } |
cancelSpotOrder | spot.cancel | WSAPICancelOrderRequest | WSAPIOrderResponse |
cancelSyncSpotOrder | spot.sync_cancel | WSAPICancelOrderRequest | SyncCancelHFOrderResponse |
submitMarginOrder | margin.order | SubmitHFMarginOrderRequest | MarginSubmitOrderV3Response |
cancelMarginOrder | margin.cancel | WSAPICancelOrderRequest | WSAPIOrderResponse |