Developer documentation for Kucoin trading API. Authentication, endpoints, and code examples.
Kucoin offers a powerful API with competitive fees. Their API is popular among algorithmic traders for its reliability and comprehensive endpoints.
https://api.kucoin.comwss://ws-api.kucoin.com
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"
| Endpoint | Method | Description |
|---|---|---|
| /api/v1/orders | POST | Create order |
| /api/v1/orders/{orderId} | DELETE | Cancel order |
| /api/v1/accounts | GET | Get account balance |
| /api/v1/market/orderbook | GET | Get order book |
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"])
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)