Kucoin API Guide

Developer documentation for Kucoin trading API. Authentication, endpoints, and code examples.

Kucoin API Overview

Kucoin offers a powerful API with competitive fees. Their API is popular among algorithmic traders for its reliability and comprehensive endpoints.

API Base URL: https://api.kucoin.com
WebSocket: wss://ws-api.kucoin.com

Authentication

import hmac
import hashlib
import base64
import time
import requests

def kucoin_signature(method, path, body, secret, timestamp):
    message = timestamp + method + path + body
    signature = base64.b64encode(
        hmac.new(secret.encode(), message.encode(), hashlib.sha256).digest()
    ).decode()
    return signature

# Get API keys from https://www.kucoin.com/account/api
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
api_passphrase = "YOUR_API_PASSPHRASE"

Core Endpoints

EndpointMethodDescription
/api/v1/ordersPOSTCreate order
/api/v1/orders/{orderId}DELETECancel order
/api/v1/accountsGETGet account balance
/api/v1/market/orderbookGETGet order book

Code Examples

Python - Get Ticker

import requests

url = "https://api.kucoin.com/api/v1/market/orderbook"
params = {"type": "BUY", "symbol": "BTC-USDT", "size": 100}

response = requests.get(url, params=params)
data = response.json()
print(data["data"])

Python - Place Order

import requests
import hmac
import hashlib
import base64
import time
import uuid

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
api_passphrase = "YOUR_API_PASSPHRASE"

url = "https://api.kucoin.com/api/v1/orders"
timestamp = str(int(time.time() * 1000))
client_oid = str(uuid.uuid4())

order = {
    "type": "limit",
    "side": "buy",
    "symbol": "BTC-USDT",
    "price": "50000",
    "size": "0.001"
}

body = json.dumps(order)
signature = kucoin_signature("POST", "/api/v1/orders", body, api_secret, timestamp)

headers = {
    "KC-API-KEY": api_key,
    "KC-API-SIGN": signature,
    "KC-API-TIMESTAMP": timestamp,
    "KC-API-PASSPHRASE": api_passphrase
}

response = requests.post(url, data=body, headers=headers)

Rate Limits