Use this file to discover all available pages before exploring further.
The kucoin-api SDK surfaces errors from both the REST and WebSocket layers in distinct, predictable ways. REST errors are thrown as structured objects that include the HTTP status code, response body, and the original request context. WebSocket errors emit an exception event on the client so your application can react without crashing. Understanding both paths — and the options that control them — lets you write resilient trading applications from day one.
By default, parseExceptions is true. When a request fails — whether due to a network issue, an HTTP 4xx/5xx response, or a KuCoin business-logic error (e.g. insufficient balance, invalid symbol) — the SDK throws a structured object with the following shape:
{ code: number; // HTTP status code (e.g. 400, 401, 429) message: string; // HTTP status text (e.g. "Bad Request") body: object; // Full response body from KuCoin, includes .code and .msg headers: object; // Response headers requestOptions: object; // Copy of the RestClientOptions used (apiKey/apiSecret/apiPassphrase replaced with 'omittedFromError') requestParams: object; // The method, endpoint, requestUrl, and params that were sent}
KuCoin’s own error body always contains a code string and a msg string. For example:
{ "code": "400100", "msg": "Order size below the minimum requirement."}
KuCoin uses the HTTP 200 OK status for many business-logic errors. The SDK detects these by checking whether response.data.code is a string other than "200000" and throws accordingly — so a 200 response can still result in a thrown error.
If you need the raw caught error instead (for custom error pipelines), set parseExceptions: false. The SDK will re-throw whatever was caught — either a network-level error or the raw response object — without wrapping it in the structured shape described above:
const client = new SpotClient({ apiKey: 'apiKeyHere', apiSecret: 'apiSecretHere', apiPassphrase: 'apiPassPhraseHere', parseExceptions: false, // re-throw raw caught errors without wrapping});
By default, strictParamValidation is false, which means undefined values in a request object are silently stripped. Enable it to throw immediately if any request parameter is undefined — useful during development to catch typos and missing fields early:
const client = new SpotClient({ apiKey: 'apiKeyHere', apiSecret: 'apiSecretHere', apiPassphrase: 'apiPassPhraseHere', strictParamValidation: true,});try { // This will throw because `price` is undefined on a limit order await client.submitHFOrder({ clientOid: client.generateNewOrderID(), side: 'buy', type: 'limit', symbol: 'BTC-USDT', price: undefined as any, size: '0.001', });} catch (e) { // Error: "Failed to sign API request due to undefined parameter" console.error(e);}
Enable strictParamValidation in your development and staging environments to catch missing parameters before they reach production.
The WebsocketClient emits an exception event when a connection-level error occurs (e.g. DNS failure, TCP reset, authentication error). Listen to it on the client instance:
If you do not listen to the exception event, unhandled WebSocket errors may crash your Node.js process. Always attach an exception handler before subscribing to any topics.
KuCoin returns HTTP 429 when you exceed the rate limit for an endpoint. A simple exponential-backoff wrapper keeps your bot running without manual intervention: