KuCoin JavaScript SDK example: rest-spot-private-trade.ts

KuCoin REST spot private trade JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.

This example uses kucoin-api, the JavaScript and TypeScript SDK for KuCoin. Install it with npm install kucoin-api.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Kucoin/Rest/rest-spot-private-trade.ts

What this example covers

  • KuCoin REST API JavaScript example.
  • Uses the Siebly KuCoin SDK package kucoin-api instead of hand-written HTTP request plumbing.
  • Source path: Kucoin/Rest/rest-spot-private-trade.ts.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as submitHFOrder(), generateNewOrderID().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { SpotClient } from 'kucoin-api'; async function start() {  const account = {    key: 'keyHere',    secret: 'secretHere',    passphrase: 'memoHere',  };   const client = new SpotClient({    apiKey: account.key,    apiSecret: account.secret,    apiPassphrase: account.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(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.