kucoin-node-api
This is an open source project created to utilize the Kucoin v2 API to support automated, algorithmic trading. The project was made and tested for Node 8.0+.
There are no guarentees towards the stability or effectiveness of this project. Comments,
contributions, stars and donations are, however, all welcome.
Installation
npm install kucoin-node-api
Alternatively, you can clone/download the repository and import into your project by file path.
Getting Started
To begin using the API wrapper, require it, create a config object that contains your API key, Secret key and Passphrase provided by Kucoin. Then run the custom init() function with your config object as a parameter. If you are only using Public endpoints, the config object only requires the environment key/value pair.
Example code is as follows:
const api = require('kucoin-node-api')
const config = {
apiKey: 'xXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxXXX',
secretKey: 'xxxxxxxxXXXXXXXXXXXXXxxXXXXXXXXXXXXXxxxXXX',
passphrase: 'xxxxxx',
environment: 'live'
}
api.init(config)
Using the API Wrapper
Once the API wrapper object is created, you can call any of the associated functions. They will return a Promise which can be utlized with .then/.catch or async/await. Note that the Promise based approach will return directly whereas the async/await approach requires calling the function.
Simple example:
api.getAccounts().then((r) => {
console.log(r.data)
}).catch((e) => {
console.log(e)
})
async function getAccounts() {
try {
let r = await api.getAccounts()
console.log(r.data)
} catch(err) {
console.log(err)
}
}
This approach allows for more complex multi-call asynchronous functionality, especially useful for automated trading.
Market Endpoint (Public)
Public endpoints do not require an API Key, Secret Key or API Passphrase.
api.getSymbols(market)
api.getTicker(symbol)
api.getAllTickers()
api.get24hrStats(symbol)
api.getMarketList(symbol)
api.getPartOrderBook(params)
api.getFullOrderBook(symbol)
api.getFullOrderBookAtomic(symbol)
api.getTradeHistories(symbol)
api.getKlines(params)
api.getCurrencies()
api.getCurrency(currency)
api.getFiatPrices(params)
api.getServerTime()
User Endpoints (Private)
api.getAccounts()
api.getAccountById(params)
api.createAccount(params)
api.getAccountLedgers(params)
api.getHolds(params)
api.innerTransfer(params)
api.createDepositAddress(params)
api.getDepositAddress(params)
api.getDepositList(params)
api.getMarginAccount()
api.getWithdrawalsList(params)
api.getRepayRecord(params)
api.getWithdrawalQuotas(params)
api.applyForWithdrawal(params)
api.cancelWithdrawal(params)
api.getV1HistoricalWithdrawls(params)
api.getV1HistoricalDeposits(params)
Trade Endpoints (Private)
api.placeOrder(params)
api.cancelOrder(params)
api.cancelAllOrders(params)
api.getOrders(params)
api.getOrderById(params)
api.listFills(params)
api.getV1HistoricalOrders(params)
api.getPosition()
api.getPosition(params)
Websockets
The websocket component of the API wrapper is utilized by initializing websockets based on topics that match Kucoin endpoints. These include:
- 'ticker'
- 'allTicker'
- 'symbolSnapshot'
- 'marketSnapshot'
- 'orderbook'
- 'match'
- 'fullMatch' (optional - private)
- 'orders' (private)
- 'balances' (private)
To initialize a websocket, provide the paramaters and an event handler. A simple example is as follows:
params = {
topic: enum (see above)
symbols: array (ignored if not required by the endpoint, single array element if single, multiple if desired)
}
api.initSocket({topic: "orderbook", symbols: ['KCS-BTC']}, (msg) => {
let data = JSON.parse(msg)
console.log(data)
})
api.initSocket({topic: "balances"}, (msg) => {
let data = JSON.parse(msg)
console.log(data)
})
The event handler can be programmed to manipulate/store the returned websocket stream data as desired.
Donation Addresses
BTC: 3KvTuAnv7o2VAf4LGgg1MiDURd2DgjFGaa
ETH: 0x7713a223e0e86355ac02b1e0de77695e822071cf
NEO: AWngpjmoXPHiJH6rtf81brPiyPomYAqe8j
Contact me for any other specific cryptocurrencies you'd prefer to use.
License
This project is open source and uses the ISC license. Feel free to utilize it in whatever way you see fit.