Authentication overview

KuCoin's API authentication system is designed to secure programmatic access to its trading platform and user data. It primarily relies on API keys and cryptographic signatures to verify the identity of the client making a request and to ensure the integrity of the request data. This approach is standard within the cryptocurrency exchange industry, balancing programmatic access with security requirements. Users interact with the KuCoin platform through a web interface, which employs traditional username/password authentication supplemented by multi-factor authentication (MFA). For automated interactions, such as those from trading bots or custom applications, KuCoin provides a robust API that necessitates a more technical authentication process.

The core principle of KuCoin API authentication involves generating a unique signature for each request using a secret key known only to the user and the KuCoin server. This signature, combined with an API key and a passphrase, allows the server to authenticate the request as legitimate and authorized. The system aims to prevent unauthorized access, replay attacks, and data tampering, which are critical considerations for financial transactions and sensitive user data. KuCoin offers comprehensive API documentation detailing the specific parameters and procedures for authentication across its various endpoints, including those for spot, futures, and margin trading.

Supported authentication methods

KuCoin employs several authentication methods to secure both user accounts on its web platform and API access for developers. The choice of method depends on the interaction type and the level of security required.

  • API Key (HMAC SHA256): This is the primary method for programmatic access to the KuCoin API. It involves generating a unique API Key, API Secret, and a Passphrase. Each API request must be signed using the API Secret with an HMAC SHA256 algorithm. This signature, along with the API Key and Passphrase, is included in the request headers. This method provides a high level of security by ensuring that only parties with knowledge of the secret key can generate valid signatures for requests. The HMAC SHA256 algorithm is a widely accepted cryptographic hash function used for message authentication, as described in RFC 2104 for HMAC.
  • Two-Factor Authentication (2FA): For web-based user accounts and critical operations like withdrawals or API key creation, KuCoin supports 2FA. This typically includes Google Authenticator (TOTP), SMS verification, and email verification. 2FA adds an extra layer of security beyond a password, requiring a second form of verification that only the legitimate user should possess.
  • Login Password: Standard username and password authentication is used for accessing the KuCoin web platform directly. This is the initial layer of security for user accounts before additional 2FA methods are applied.

Authentication Methods Table

Method When to Use Security Level
API Key (HMAC SHA256) Programmatic trading, data retrieval, automated tasks via API High (cryptographic signature, secret key)
Two-Factor Authentication (2FA) Web login, withdrawals, API key creation, security setting changes High (second verification factor required)
Login Password Initial access to KuCoin web platform Medium (requires strong password practices)

Getting your credentials

To interact with the KuCoin API programmatically, you need to generate an API Key, API Secret, and a Passphrase. These credentials are created and managed within your KuCoin account settings.

  1. Log In to KuCoin: Access your KuCoin account through the official website (KuCoin homepage). Ensure you are using the legitimate site to avoid phishing scams.
  2. Navigate to API Management: Once logged in, go to your account security settings or API management section. This is typically found under your profile icon or in the 'Security' section of the dashboard. Look for an option like 'API Management' or 'API Keys'.
  3. Create New API Key: Click on the 'Create API' or 'Create API Key' button. You will be prompted to set up your API key with specific permissions and a name.
  4. Configure API Permissions: When creating an API key, you can define its permissions. KuCoin typically allows you to grant separate permissions for 'Trade', 'View', and 'Transfer'.
    • Trade: Allows the API key to place and cancel orders, and access trading history.
    • View: Grants read-only access to account balances, order lists, and general market data.
    • Transfer: Enables withdrawals and internal transfers. This permission is highly sensitive and should be used with extreme caution, often requiring additional 2FA.
    It is a best practice to grant only the minimum necessary permissions for your application to reduce potential risk.
  5. Set API Key Name and Passphrase: Provide a descriptive name for your API key to easily identify its purpose later. You will also need to set an API Passphrase. This passphrase is used to encrypt your API Secret and must be specified in the header of API requests for authentication. Store this passphrase securely.
  6. Record API Key and Secret: After creation, KuCoin will display your API Key (e.g., KC-API-KEY) and API Secret (e.g., KC-API-SECRET). The API Secret is shown only once and cannot be retrieved if lost. It is crucial to copy and store both the API Key and API Secret securely immediately after generation. If you lose the API Secret, you will need to delete the existing API key and create a new one.
  7. IP Whitelisting (Optional but Recommended): For enhanced security, KuCoin allows you to specify a list of trusted IP addresses that are permitted to use the API key. If your application or server operates from a static IP address, whitelisting that IP significantly reduces the risk of unauthorized access even if your API key is compromised.
  8. Enable 2FA: Ensure that Two-Factor Authentication (Google Authenticator, SMS, or Email) is enabled on your KuCoin account before creating API keys and for any sensitive operations. The KuCoin developer documentation provides detailed steps for setting up API keys, including screenshots and specific configuration options.

Authenticated request example

To illustrate how to send an authenticated request to the KuCoin API, we will use a Python example. This example demonstrates how to sign a request using HMAC SHA256, include the necessary headers, and retrieve account information.

First, ensure you have your API Key, API Secret, and Passphrase. For this example, we'll assume you want to fetch your account balances.


import hmac
import hashlib
import base64
import time
import requests

# --- Replace with your actual credentials ---
API_KEY = "YOUR_KUCOIN_API_KEY"
API_SECRET = "YOUR_KUCOIN_API_SECRET"
API_PASSPHRASE = "YOUR_KUCOIN_API_PASSPHRASE"

# KuCoin API Base URL
BASE_URL = "https://api.kucoin.com"

def get_kucoin_signed_headers(endpoint, method, body_str=""):
    timestamp = str(int(time.time() * 1000)) # Milliseconds timestamp
    
    # Pre-hash the passphrase for the header
    passphrase_version = "1"
    passphrase_hashed = base64.b64encode(hmac.new(API_SECRET.encode('utf-8'), API_PASSPHRASE.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')

    # Construct the string to be signed
    # Format: timestamp + method + endpoint + body (if POST/PUT)
    message = timestamp + method + endpoint + body_str

    # Sign the message with the API Secret
    signature = base64.b64encode(hmac.new(API_SECRET.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')

    headers = {
        "KC-API-KEY": API_KEY,
        "KC-API-SIGN": signature,
        "KC-API-TIMESTAMP": timestamp,
        "KC-API-PASSPHRASE": passphrase_hashed, # Passphrase pre-hashed as per KuCoin docs
        "KC-API-VERSION": passphrase_version,
        "Content-Type": "application/json"
    }
    return headers

# Example: Get account list
endpoint = "/api/v1/accounts"
method = "GET"

headers = get_kucoin_signed_headers(endpoint, method)

try:
    response = requests.get(BASE_URL + endpoint, headers=headers)
    response.raise_for_status() # Raise an exception for HTTP errors
    print("Response Status Code:", response.status_code)
    print("Response Body:", response.json())
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")

This Python script defines a function get_kucoin_signed_headers that generates all necessary headers for an authenticated request. It calculates the HMAC SHA256 signature based on the timestamp, HTTP method, endpoint, and (optionally) the request body. The API Key, generated signature, timestamp, and a pre-hashed passphrase are then included in the request headers. The example then uses the requests library to send a GET request to the /api/v1/accounts endpoint to fetch account balances.

Security best practices

Implementing strong security practices is crucial when working with KuCoin's authentication and API, given the financial nature of the platform. Adhering to these guidelines can help protect your assets and data:

  1. Use Strong, Unique Passphrases: For API keys, always use a strong, unique passphrase that is different from your login password. This passphrase should be complex, combining uppercase and lowercase letters, numbers, and symbols.
  2. Enable Two-Factor Authentication (2FA): Always enable 2FA (Google Authenticator is recommended) on your KuCoin account. This adds a critical layer of security to your main account, protecting it even if your password is compromised.
  3. Restrict API Key Permissions: Grant API keys only the minimum necessary permissions required for their intended function. For example, if an API key is only used for viewing market data, do not grant it trading or withdrawal permissions. Avoid giving 'Transfer' permissions to API keys unless absolutely necessary, and if so, pair it with IP whitelisting.
  4. Implement IP Whitelisting: Whenever possible, restrict API key usage to a specific list of trusted IP addresses. If your application or server has a static IP, configure this in your KuCoin API key settings. This prevents unauthorized access even if your API key and secret are stolen.
  5. Securely Store Credentials: Never hardcode API keys or secrets directly into your application's source code. Store them in environment variables, secure configuration files, or a dedicated secret management service (e.g., AWS Secrets Manager, Google Secret Manager). Ensure these storage locations are protected with appropriate access controls.
  6. Rotate API Keys Regularly: Periodically rotate your API keys (e.g., every 90 days). This practice limits the window of exposure if a key is compromised without your knowledge. When rotating, generate a new key, update your application, and then delete the old key.
  7. Monitor API Key Usage: Regularly review the logs and activity associated with your API keys within your KuCoin account or via your application's logging. Look for unusual patterns or unauthorized access attempts.
  8. Use Secure Communication (HTTPS): All interactions with the KuCoin API should occur over HTTPS. This encrypts data in transit, protecting against eavesdropping and man-in-the-middle attacks. KuCoin's API endpoints are designed to only accept HTTPS connections.
  9. Handle Errors Securely: Ensure your application handles API errors and exceptions gracefully and securely. Avoid leaking sensitive information in error messages.
  10. Be Wary of Phishing Attacks: Always verify the URL when logging into KuCoin or accessing API management. Phishing sites can mimic legitimate platforms to steal your credentials.