Skip to content

Theezr/kucoin-node-ts-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KuCoin JS Client

Welcome to the client library for Kucoin REST and WebSocket API with typescript support

Getting started

First off, install the library

npm install kucoin-node-ts-sdk

Next, create a new client with your API secret, API password, API key.

import { Client } from 'kucoin-node-ts-sdk';
const client = new Client({
  secret: process.env.SECRET as string,
  password: process.env.PASS as string,
  key: process.env.KEY as string,
});

REST Calls

After creating the client, making calls is a breeze. We follow the KuCoin docs structure. So the client is followed by the header in the docs. For example, getting an account or deposit address:

const { data } = await client.account.getAnAccount({
  accountId: '12345',
});
console.log(data);

const depositAddress = await client.deposit.getDepositAddresses({
  currency: 'USDT',
});
const marginInfo = await client.marginInfo.getMarginConfigurationInfo();

Making an inner transfer:

const { data } = await client.account.innerTransfer({
  clientOid: Date.now().toString(),
  currency: 'USDT',
  from: 'trade',
  to: 'isolated',
  amount: '1',
  toTag: 'USDC-BTC',
});

console.log(data);

At last, placing an order:

const { data } = await client.orders.placeNewOrder({
  clientOid: Date.now().toString(),
  side: 'buy',
  symbol: 'BTC-USDT',
  price: '12',
  size: '12',
});

console.log(data);

WebSocket Client

For full webSocket examples, check out the examples folder.

First you need a public or private token

const tokenInfo = await client.websocket.getPublicWebsocketToken();
const { token, instanceServers } = tokenInfo.data.data;

Then create a webSocket with those credentials

const ws = client.websocket.openWebsocket({
  endpoint: instanceServers[0].endpoint,
  token: token,
});

About

KuCoin JS Client with TS support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published