This guide walks you through everything required to go from a blank project to a running integration with KuCoin’s REST and WebSocket APIs. You will install the package, import the clients, fetch public market data without credentials, and then make an authenticated private call — all in a few dozen lines of code.Documentation 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.
Always store your API credentials in environment variables. Never hardcode
apiKey, apiSecret, or apiPassphrase directly in source files that may be committed to version control.Prerequisites
- Node.js 18 or later (the SDK uses the Web Crypto API for signing, which is built into Node 18+).
- A KuCoin account. Create API keys at kucoin.com/account/api.
- (Optional) A
.envfile or shell environment withKUCOIN_API_KEY,KUCOIN_API_SECRET, andKUCOIN_API_PASSPHRASEset.
Public endpoints do not require API credentials. Instantiate
SpotClient with no arguments and call any market data method:import { SpotClient } from 'kucoin-api';
async function start() {
const client = new SpotClient();
try {
// Fetch all symbols
const symbols = await client.getSymbols();
console.log('symbols:', JSON.stringify(symbols, null, 2));
// Fetch ticker for a specific symbol
const ticker = await client.getTicker({ symbol: 'BTC-USDT' });
console.log('ticker:', JSON.stringify(ticker, null, 2));
// Fetch daily klines
const klines = await client.getKlines({
symbol: 'BTC-USDT',
type: '1day',
});
console.log(klines);
} catch (e) {
console.error('Req error: ', e);
}
}
start();
getSymbols(), getTicker(), getTickers(), getKlines(), and all order-book methods are public and work without API credentials.Provide your API credentials via environment variables and pass them to the
SpotClient constructor. Once authenticated, you can call private endpoints like getBalances():import { SpotClient } from 'kucoin-api';
async function start() {
const client = new SpotClient({
apiKey: process.env.KUCOIN_API_KEY,
apiSecret: process.env.KUCOIN_API_SECRET,
apiPassphrase: process.env.KUCOIN_API_PASSPHRASE,
});
try {
// Fetch all account balances
const balances = await client.getBalances();
console.log('balances:', JSON.stringify(balances, null, 2));
} catch (e) {
console.error('Req error: ', e);
}
}
start();
Use
submitHFOrder() for high-frequency spot trading. The generateNewOrderID() helper produces a unique client order ID:import { SpotClient } from 'kucoin-api';
async function start() {
const client = new SpotClient({
apiKey: process.env.KUCOIN_API_KEY,
apiSecret: process.env.KUCOIN_API_SECRET,
apiPassphrase: process.env.KUCOIN_API_PASSPHRASE,
});
try {
const spotBuyResult = await client.submitHFOrder({
clientOid: client.generateNewOrderID(),
side: 'buy',
type: 'market',
symbol: 'BTC-USDT',
size: '0.00001',
});
console.log('spotBuy ', JSON.stringify(spotBuyResult, null, 2));
const spotSellResult = await client.submitHFOrder({
clientOid: client.generateNewOrderID(),
side: 'sell',
type: 'market',
symbol: 'BTC-USDT',
size: '0.00001',
});
console.log('spotSellResult ', JSON.stringify(spotSellResult, null, 2));
} catch (e) {
console.error('Req error: ', e);
}
}
start();
The
WebsocketClient manages connections, heartbeats, and reconnections automatically. Subscribe to a topic with a WsKey string that identifies the connection type:import { WebsocketClient } from 'kucoin-api';
const client = new WebsocketClient();
client.on('open', (data) => {
console.log('open: ', data?.wsKey);
});
// All market data arrives here
client.on('update', (data) => {
console.info('data received: ', JSON.stringify(data));
});
client.on('reconnect', (data) => {
console.log('reconnect: ', data);
});
client.on('reconnected', (data) => {
console.log('reconnected: ', data?.wsKey);
});
client.on('close', (data) => {
console.error('close: ', data);
});
client.on('response', (data) => {
console.info('response: ', data);
});
client.on('exception', (data) => {
console.error('exception: ', data);
});
// Subscribe to BTC-USDT and ETH-USDT tickers on the spot V1 connection
client.subscribe('/market/ticker:BTC-USDT,ETH-USDT', 'spotPublicV1');
Complete Working Example
The following combines a public call, private balance fetch, and a WebSocket subscription in a single script:What’s Next
Authentication
Deep-dive into API key options, access tokens, custom signing, and regional configuration.
KuCoin API Docs
Official KuCoin REST API reference for all endpoint parameters and response schemas.