Welcome to the client [library](https://github.com/Theezr/kucoin-node-ts-sdk) for Kucoin REST and WebSocket API with typescript support
npm install kucoin-node-ts-sdkbash
npm install kucoin-node-ts-sdk
`
Next, create a new client with your API secret, API password, API key.
`javascript
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:
`javascript
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:
`javascript
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:
`javascript
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
`javascript
const tokenInfo = await client.websocket.getPublicWebsocketToken();
const { token, instanceServers } = tokenInfo.data.data;
`
Then create a webSocket with those credentials
`javascript
const ws = client.websocket.openWebsocket({
endpoint: instanceServers[0].endpoint,
token: token,
});
``