0

I tried to make an exchange code in python for Kucoin.I checked that the Key,Secret are correct and the endpoint is correct so why do i get the error 400005?The Kucoin documentation says that there is a bug is the code but i cant see any bug.

import requests
import json
import hmac
import hashlib
import time

# Get the API key, secret key, and passphrase from the user
api_key = input('Enter your API key: ')
secret_key = input('Enter your secret key: ')
passphrase = input('Enter your passphrase: ')

# Specify the currency pair, amount, and the type of the order (buy or sell)
symbol = input('Enter the symbol you want to trade: ')
amount = float(input('Enter the amount you want to trade: '))
order_type = input('Enter the type of the order (buy or sell): ')

# Get the current timestamp
timestamp = str(int(time.time() * 1000))

# Build the request body
data = {
    'symbol': symbol,
    'type': order_type,
    'price': 'market',
    'amount': amount
}

# Create the signature
message = 'POST/api/v1/orders\n' + timestamp + '\n'
json.dumps(data)
signature = hmac.new(secret_key.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).hexdigest()

# Build the request headers
headers = {
    'Content-Type': 'application/json',
    'KC-API-KEY': api_key,
    'KC-API-SIGN': signature,
    'KC-API-TIMESTAMP': timestamp,
    'KC-API-PASSPHRASE': passphrase
}

# Send the request to place the order
response = requests.post('https://openapi-v2.kucoin.com/api/v1/orders', headers=headers, json=data)

# Print the response
print(response.json())


0 Answers0