escwdev / kucoin-node-api

Node.js KuCoin Cryptocurrency Exchange v2 API Wrapper/SDK
89 stars 61 forks source link

Error 400005 #14

Closed eyefate closed 4 years ago

eyefate commented 4 years ago

Getting this error when trying api.placeOrder, not sure where it comes from, all the other endpoints work just fine (can get accounts, balances etc)

data: { code: '400005', msg: 'Invalid KC-API-SIGN' }

Anyone having the same problem? any solution?

escwdev commented 4 years ago

I've placed a lot of orders through this library and generally don't have issues apart from the occasional failures due to 503 Unavailable Server or insuffient balance etc...

That said I use pretty much the same parameters apart from side/symbol/quantity. This makes me think the issue may be related to the parameters. If one isn't inputted correctly, the header signature would be invalid and may send back the error you're getting.

Can we have an example of your call?

eyefate commented 4 years ago

api.placeOrder(side="buy",symbol="WXT-USDT",type="limit",price="0.007778",size="20").then((r) => { console.log(r.data) }).catch((e) => { console.log(e) })

eyefate commented 4 years ago

Formating as api.placeOrder({"side":"buy","symbol":"WXT-USDT","type":"limit","price":"0.007778","size":"20"})Returns undefined

escwdev commented 4 years ago

clientOid is a required parameter so that could be your issue. I use a uuid for it but it can be any unique value (i.e. if you use 1 and try to use 1 again the 2nd trade will fail). For quick testing and no added dependencies, Date.now() can work well since it should always be unique (unless you are sending a lot of orders at once in which case I recommend using uuid).

Also, you don't need to stringify your requests, the library handles that for you so this should work.

api.placeOrder({
  clientOid: Date.now(),
  side: "buy",
  symbol: "WXT-USDT",
  type: "limit",         // Note limit is default so this can be omitted
  price: 0.007778,
  size: 20
}).then(r => console.log(r.data)).catch(e => console.log(e));

Let me know if that works for you.

eyefate commented 4 years ago

Working now, was my fault, i had to move funds to trade account apparently and error showed as undefined, have a good one!

;)