I'm new to apis but I've been trying to write a code to place a spot order for crypto through the kucoin api but I keep getting a status code of 400, "Bad request". I'm not really sure where the problem is from. This is all in python by the way.
signature = hmac.new(api_secret.encode(), (endpoint + '/' + nonce + payload_json).encode(), hashlib.sha256).hexdigest()
This is the code for the signature. Not sure if it's accurate or the cause of the problem.
if you need to see my full code, here:
import hashlib
import hmac
import json
import requests
import time
api_key = '***********'
api_secret = '***-***-***'
#parameters
symbol = 'BTC-USDT'
side = 'buy'
type = 'limit'
size = '0.2'
price = '60000'
endpoint = '/api/v1/orders'
url = 'https://api.kucoin.com' + endpoint
nonce = str(int(time.time() * 1000))
payload = {
'clientOid': str(int(time.time() * 1000)),
'side': side,
'symbol': symbol,
'type': spot,
'size': size,
'price': price,
}
payload_json = json.dumps(payload)
signature = hmac.new(api_secret.encode(), (endpoint + '/' + nonce + payload_json).encode(), hashlib.sha256).hexdigest()
# Send the API request
headers = {
'Content-Type': 'application/json',
'KC-API-SIGNATURE': signature,
'KC-API-TIMESTAMP': nonce,
'KC-API-KEY': api_key,
}
response = requests.post(url, headers=headers, data=payload_json)