2

I'm building a multi-exchange bot in C++ and I'm having one small problem. KuCoin exchange has proven to be frustrating to say the least, one of the headers is a signature header where you encode the string with HMAC sha256 and then encode THAT with base64. However I'm not concerned with the encoding, I can do all that. What is stumping me is the string KuCoins API is expecting, I've scoured their documentation 100 times over and I still can't get it right, here are the instructions

For the header of KC-API-KEY:

Use API-Secret to encrypt the prehash string {timestamp+method+endpoint+body} with sha256 HMAC. The request body is a JSON string and need to be the same with the parameters passed by the API. After that, use base64-encode to encrypt the result in step 1 again.

I've attempted to craft this string in every way possible, and the documentation provides no examples on what a good string should look like, here are the strings I've crafted BEFORE encoding that DO NOT work.

EXAMPLE 1: 1616096476134POST/api/v1/orders?clientOid=55be5&side=BUY&symbol=BTC-USDT&type=MARKET&funds=0.005000

EXAMPLE 2: 1616099932367POST/api/v1/orders{"clientOid":"55be5","side":"BUY","symbol":"BTC-USDT","type":"MARKET","funds":"0"}

As you can see, in the 2nd example I tried to make the body a JSON string with all the correct parameters, but still, I'm getting a bad signature error returned. Literally all I need is to know what the string is supposed to look like so I can craft it properly. Thanks.

beyron
  • 21
  • 1

2 Answers2

2

I take the assumption that your code works for a private request without parameters (like getting the balance for instance).

I also struggled a bit for POST requests, but managed to get it right after a few attempts. You need to dump the parameters as a JSON string without spaces, exactly like in your example 2.

Since that time, have you managed to solve it ? I have a code on my application that works if you are interested.

Also, don't forget to add in the headers of the curl request:

Content-Type: application/json
Stéphane Janel
  • 326
  • 1
  • 10
0

Solved with Kucoin support and pythone example. The "body" also must be included in POST request. Was:

reply = netman->post(req, "");

Become:

tradereply = trademan->post(req, data);
slesar
  • 1