kucoin / kucoin-node-sdk Goto Github PK
View Code? Open in Web Editor NEWKuCoin API SDK for Node.js language.
License: Apache License 2.0
KuCoin API SDK for Node.js language.
License: Apache License 2.0
Hello, Please make the package support typescript.
I am having trouble making api requests for anything that requires a signature. I am under the impression that I need to use base64 and hmac to encode the 'api_secret' and timestamp, as well as the 'api_secret' and the 'api_passphrase.' this is from the kucoin api docs:
signature = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest())
passphrase = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())
and then the request object includes
headers = {
"KC-API-SIGN": signature,
"KC-API-TIMESTAMP": str(now),
"KC-API-KEY": api_key,
"KC-API-PASSPHRASE": passphrase,
"KC-API-KEY-VERSION": 2
"Content-Type": "application/json" # specifying content type or using json=data in request
}
Do I have a second export in config.js for this?
I'm trying to cancel my order with the custom client order id using rest.Trade.Orders.cancelOrderByClientOid(), but it doesn't do anything.
I was looking in the code, and it seems the function arguments are incorrect:
exports.cancelOrderByClientOid = async function cancelOrderByClientOid({ symbol, tradeType } = {}) {
return await Http().DEL(`/api/v1/order/client-order/${clientOid}`);
};
Should be something like:
exports.cancelOrderByClientOid = async function cancelOrderByClientOid(clientOid) {
return await Http().DEL(`/api/v1/order/client-order/${clientOid}`);
};
For now I have to use the unique order id with cancelOrder() as returned by postOrder(), but it's not ideal.
Hi, thanks for the package!
I have an app that works the following way: people trust me with their api keys and secrets, I add them to my app, the app makes api calls using their api credentials. Since the app makes calls on behalf of multiple different users, the shared config object becomes an issue. I have to be extra careful to not have simultaneous api calls with different user configs, because I'm afraid when calling init for request B while request A hasn't been sent yet, request A will use request B config. Can you please confirm that this sort of error is in fact possible during simultaneous requests ? If yes, is it possible to initiate multiple instances, each with their own config ?
Can you add pageSize as a parameter for the endpoints that support it? Or default the API to 500. It takes to long to fetch the data if we use 50 at a time.
I apologize as I am not experienced with javascript at all. I keep getting this error. I am running the code from index.js and I have already filled the config file with my API Key, secret, and passphrase. However I keep getting this error. I have looked into it extensively and can't seem to figure it out.
/Users/mustafasoby/node_modules/node-fetch/lib/index.js:273 return Body.Promise.reject(new FetchError(
invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
^
FetchError: invalid json response body at https://sandbox.kucoin.com/api/v1/timestamp? reason: Unexpected token < in JSON at position 0
at /Users/mustafasoby/node_modules/node-fetch/lib/index.js:273:32
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async HttpBase.makeRequest (/Users/mustafasoby/node_modules/kucoin-node-sdk/src/lib/createHttp.js:88:20)
at async Object.getTimestamp (/Users/mustafasoby/node_modules/kucoin-node-sdk/src/rest/Others.js:17:10)
at async main (/Users/mustafasoby/Documents/coding/JavaScript/KuCoinBot/demo/index.js:6:28) {
type: 'invalid-json'
}
Node.js v17.0.1 `
In my code:
console.log(await API.rest.Market.OrderBook.getLevel2_full('BTC-USDT'))
In console I see { code: '404', msg: 'not exist' }
What should I do?
Receiving error in node_modules/kucoin-node-sdk/src/lib/datafeed.js:298 instanceServers
TypeError: Cannot destructure property 'instanceServers' of 'server' as it is undefined.
hello everyone
I open WebSocket for my private account and get messages of order changes.
when I set buy order in Best Market Price Mode order filled but the message type:'canceled'
and when sell order filled the message type:'filled'
I think the 'type' of buying Best Market Price message is wrong And it should be 'filled' in Websocket messages
Hi,
I'm trying to compile demo.
I've installed lodash and now I've an error "Uncaught Error: Cannot find module './config'"
I launch the level2_demo from the demo directory.
Thanks for your help
I can subscribe to public channels (e.g. '/market/ticker:') but can not get any private channel like '/spotMarket/tradeOrders' to work.
An example call which I think would work:
feed.subscribe('/spotMarket/tradeOrders', (message) => { console.log(message) }, true)
Authentication should be correct since requesting any private account data through REST works.
Am I doing something wrong or are private channels not supported?
I can't find any way to set the parameters to expand the ticker list size. I expected to see ALL tickers, since that is the function's name, yet its only showing 14.
I have renamed the config file to config.js, and I've entered my API details but it seems like after each comma I'm getting a SyntaxError: Unexpected token.
Can't understand what the issue is.
{
baseUrl: '',
apiAuth: {
key: '', // KC-API-KEY
secret: '', // API-Secret
passphrase: '', // KC-API-PASSPHRASE
},
authVersion: 2, // KC-API-KEY-VERSION. Notice: for v2 API-KEY, not required for v1 version.
}
I've just entered my API details between the '' and tried using all the baseUrls suggested.
Excerpt of file http.js
around row 14:
if (!_baseUrl) {
_baseUrl = process.env.PRODUCTION === 'prod'
? 'https://api.kucoin.io'
: 'https://openapi-sandbox.kucoin.io';
}
The domain name kucoin.io
needs to be changed to kucoin.com
, otherwise GET requests are redirected to an HTML page, causing a JSON parse error:
get bullet error { FetchError: invalid json response body at https://www.kucoin.cc/api/v1/bullet-public reason: Unexpected token < in JSON at position 0
at /home/user/pulse/node_modules/node-fetch/lib/index.js:272:32
at process._tickCallback (internal/process/next_tick.js:68:7)
message:
'invalid json response body at https://www.kucoin.cc/api/v1/bullet-public reason: Unexpected token < in JSON at position 0',
type: 'invalid-json' }
The indicated functions return a 404 error code when used. Presumably this is due to StopOrder.js including a symbol in the delete request, while the current API documentation (https://docs.kucoin.com/#cancel-an-order-2) does not mention symbol for these request routes
Hello , there are a @types module avalaible for kucoin-node-sdk ?
I'm attempting to use applyWithdraw on USDC to ALGO and there is no response and no record of withdrawal action
const result = await kucoin.rest.User.Withdrawals.applyWithdraw('USDC', address, availableAmount, {chain: 'ALGO'})
node_modules\kucoin-node-sdk\src\lib\utils.js:19
const signature = sign(timestamp + method.toUpperCase() + url + data, ApiKey.secret);
TypeError: Cannot read properties of undefined (reading 'secret')
The websocket doesn't connect due to a timeout.
The handshake timeout is set to 30ms which is a bit short.
It might have been the intention to set this to 30sec so it should be 30000 instead.
datafeed.js line 307
I'm able to pull the deposit and withdrawal transactions. When trying to pull the orders list, Im getting empty data
/** Require SDK */
const API = require('kucoin-node-sdk');
/** Init Configure */
API.init({
"baseUrl": "https://api.kucoin.com",
"apiAuth": {
"key": "key", // KC-API-KEY
"secret": "secret", // API-Secret
"passphrase": passphrase", // KC-API-PASSPHRASE
},
"authVersion": 2, // KC-API-KEY-VERSION. Notice: for v2 API-KEY, not required for v1 version.
});
/** API use */
const main = async () => {
const getTimestampRl = await API.rest.Others.getTimestamp();
console.log(getTimestampRl.data);
const orders = await API.rest.Trade.Orders.getOrdersList('TRADE')
console.log(JSON.stringify(orders))
};
/** Run Demo */
main();
When I make an overload test, calling getOrderById too many times in shot amount of time, i can't catch request limit error.
My intention is to catch this error, wait 10 seconds or more and retry the request.
But using a Try-Catch block to make this happen I get always next error:
FetchError: invalid json response body at https://api.kucoin.com/api/v1/orders/62d99d248d3eb700016140dc? reason: Unexpected token < in JSON at position 0
I was digging into the createHttp lib, I think this can be the problem
kucoin-node-sdk/src/lib/createHttp.js
Line 92 in 8a79c5d
Can anyone give me some help on this?
Is there a reason why the config is a global variable?
This scheme makes it difficult to create different connections, as the config is centralized and there is no way to override it.
It is relatively insecure or at least not ideal to be replacing the config to be able to keep different connections.
I would like to recommend having an approach where you can create a client instance with a configuration and set of parameters.
This will allow the user to create diverse connections on the same node instance if required.
Latest version 1.1.0 can not available for use on package managers yarn and npm
Any idea?
I'm not receiving the data in the susbcriber callback and datafeed.trustConnected
is always false
API.init(config);
const datafeed = new API.websocket.Datafeed();
// close callback
datafeed.onClose(() => {
console.log('ws closed, status ', datafeed.trustConnected);
});
// connect
await datafeed.connectSocket();
// subscribe
setTimeout(() => {
console.log(datafeed.trustConnected);
const topic = `/market/level2:BTC-EUR`;
const callbackId = datafeed.subscribe(topic, (message) => {
console.log(message);
if (message.topic === topic) {
console.log(message.data);
}
});
console.log( `subscribe id: ${callbackId}` );
}, 5000);
Hi,
I'm using the sandbox to test out this SDK. Set up an account in the Sandbox, created API credentials and used it as the config. Getting empty JSON responses from all the operations related to User and Account. I'm able get data back from getStatus and getSymbolsList which doesn't require a signature. I don't think I'm getting authorized correctly since even when I purporsely provide the wrong Secret, I still get an empty JSON response (I expected a 401 unauthorized error). Any idea what I might be missing?
Here's a sample of my code
`const API = require('kucoin-node-sdk');
const express = require('express');
const router = express.Router();
//Init configure
API.init({
baseUrl: 'https://openapi-sandbox.kucoin.com',
apiAuth: {
key: '', // KC-API-KEY
secret: '', // API-Secret
passphrase: '', // KC-API-PASSPHRASE
},
authVersion: 2, // KC-API-KEY-VERSION. Notice: for v2 API-KEY, not required for v1 version.
})
router.get('/subUsers', async(req,res)=> {
res.send(getSubUsers())
})
async function getSubUsers() {
const subUsers = await API.rest.User.UserInfo.getSubUsers()
return subUsers
}
router.get('/accountList', async(req,res)=> {
res.send(getAccountList())
})
async function getAccountList() {
const accountList = await API.rest.User.Account.getAccountsList()
return accountList
}
module.exports = router;`
The response I keep getting is this:
{}
Hi
Can I create several BTC wallet address to deposit and use them all in same time?
For example:
I create a BTC wallet for deposit, Then I create another wallet again. Is my first wallet still mine?
Thanks
Hey, I recently started playing with the kucoin bots, and I'd like to access the robots data via API to create some charts. (And perform actions too if that would be possible). The code would be open sourced BTW.
Is adding the robots data to the API in the plans?
Thanks.
How do I get response headers with result on successful call?
apiV1KC.get('/timestamp', async function(req, res) {
try {
const getTimestampRl = await KucoinAPI.rest.Others.getTimestamp();
//res.set(headers);
res.send(getTimestampRl); // Send the response back to the requester
} catch (error) {
res.status(500).send(error); // Send error response in case of an error
}
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.