Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsure how to authenticate my api key Kucoin

I am learning how to use the Kucoin and am having trouble with the authenticating myself to the API server.

I am trying to load all of the active orders however keep getting a 401 error.

The Kucoin API documentation states that I need to add this:

{
    "KC-API-KEY": "59c5ecfe18497f5394ded813",  
    "KC-API-NONCE" : 1506219855000   //Client timestamp (exact to 
milliseconds), before using the calibration time, the server does not 
accept calls with a time difference of more than 3 seconds
    "KC-API-SIGNATURE" : 
"fd83147802c361575bbe72fef32ba90dcb364d388d05cb909c1a6e832f6ca3ac"   
//signature after client encryption
}

as a parameter to headers of request. I am unsure what this means. Any help will be appreciated.

like image 747
Sumtinlazy Avatar asked Nov 28 '25 12:11

Sumtinlazy


1 Answers

Creating the header can be a little tricky.

For the nonce value, or any millisecond timestamp value, I've found the best way to generate this is like this

import time
int(time.time() * 1000)

The signature requires you to order the parameters alphabetically in a query string format, combine that with the path and nonce and then hash the string using sha256 with your secret key.

If you'd like to implement it yourself feel free to copy the code from here, it's split over a few functions and should be quite readable https://github.com/sammchardy/python-kucoin/blob/0ece729c406056a428a57853345c9931d449be02/kucoin/client.py#L117

Or alternatively you may be best off just using that library. (Note: I'm the author and maintainer of python-kucoin)

like image 138
Sam McHardy Avatar answered Nov 30 '25 01:11

Sam McHardy