Reputation: 1
I'm trying to fetch my Kucoin spot trading balance using their REST API, but I'm encountering a 401 error with the message 'Invalid KC-API-SIGN'. Here's my Python code and the steps I've taken from Kucoin Docs API:
import hmac
import hashlib
import base64
import requests
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
api_passphrase = 'YOUR_API_PASSPHRASE'
url = 'https://api.kucoin.com/api/v1/accounts'
now = str(int(time.time() * 1000))
str_to_sign = now + 'GET' + '/api/v1/accounts'
signature = hmac.new(api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).hexdigest()
passphrase = base64.b64encode(hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())
headers = {
"KC-API-SIGN": signature,
"KC-API-TIMESTAMP": now,
"KC-API-KEY": api_key,
"KC-API-PASSPHRASE": passphrase,
"KC-API-KEY-VERSION": "2"
}
response = requests.request('get', url, headers=headers)
print(response.status_code)
print(response.json())
Double-checked API credentials:- I've meticulously verified my API key, secret, and passphrase. Reviewed timestamp generation:- I've ensured that the timestamp is in the correct format (milliseconds since Unix epoch). Examined Kucoin documentation:- I've carefully studied Kucoin's API docs for potential errors in my signature generation process.
Upvotes: 0
Views: 216