KuCoin API Documentation: A Comprehensive Guide
1. Authentication
To access the KuCoin API, you need to authenticate your requests. KuCoin uses API keys for authentication, which consist of an API Key, a Secret Key, and a Passphrase. Here's how to get started:
- Generate API Keys: Log in to your KuCoin account and navigate to the API Management page. Create a new API key and make note of your API Key, Secret Key, and Passphrase.
- Include Keys in Requests: All API requests must include these keys. The Secret Key is used to generate a signature for each request, which ensures the request is from a legitimate source.
Example Authentication Request
bashcurl -X GET "https://api.kucoin.com/api/v1/market/allSymbols" \ -H "KC-API-KEY:
" \ -H "KC-API-SIGN:" \ -H "KC-API-TIMESTAMP:" \ -H "KC-API-PASSPHRASE:" \ -H "KC-API-KEY-VERSION: 2"
2. Market Data Endpoints
The Market Data Endpoints provide information about trading pairs, order book data, and recent trades. Key endpoints include:
Get All Symbols: Retrieve information about all trading pairs available on KuCoin.
- Endpoint:
/api/v1/market/allSymbols
- Method: GET
- Response: Provides a list of all trading pairs, including their base and quote currencies.
- Endpoint:
Get Order Book: Fetch the order book for a specific trading pair.
- Endpoint:
/api/v1/market/orderbook/level2
- Method: GET
- Parameters:
symbol
(e.g., BTC-USDT) - Response: Includes bids and asks, their respective prices, and quantities.
- Endpoint:
Get Recent Trades: Retrieve recent trades for a given trading pair.
- Endpoint:
/api/v1/market/histories
- Method: GET
- Parameters:
symbol
(e.g., BTC-USDT) - Response: Includes trade history with timestamps, prices, and quantities.
- Endpoint:
Example Market Data Request
bashcurl -X GET "https://api.kucoin.com/api/v1/market/orderbook/level2?symbol=BTC-USDT"
3. Trading Endpoints
Trading Endpoints allow users to place and manage orders. The main endpoints are:
Place an Order: Submit a new order to buy or sell a trading pair.
- Endpoint:
/api/v1/orders
- Method: POST
- Parameters:
symbol
,side
(buy/sell),type
(limit/market),price
,size
- Response: Confirmation of the order with details.
- Endpoint:
Get Order Details: Retrieve details of a specific order.
- Endpoint:
/api/v1/orders/
- Method: GET
- Response: Information about the order, including its status and execution details.
- Endpoint:
Cancel an Order: Cancel an existing order.
- Endpoint:
/api/v1/orders/
/cancel - Method: POST
- Response: Confirmation of the cancellation.
- Endpoint:
Example Trading Request
bashcurl -X POST "https://api.kucoin.com/api/v1/orders" \ -H "KC-API-KEY:
" \ -H "KC-API-SIGN:" \ -H "KC-API-TIMESTAMP:" \ -H "KC-API-PASSPHRASE:" \ -H "KC-API-KEY-VERSION: 2" \ -d '{"symbol": "BTC-USDT", "side": "buy", "type": "limit", "price": "30000", "size": "0.01"}'
4. Account Endpoints
Account Endpoints are used to manage your account information, including balances and transaction history.
Get Account Balance: Retrieve the balance of your account for each currency.
- Endpoint:
/api/v1/accounts
- Method: GET
- Response: Balance details for each currency.
- Endpoint:
Get Transaction History: Fetch your transaction history, including deposits and withdrawals.
- Endpoint:
/api/v1/accounts/
/transactions - Method: GET
- Response: Details of each transaction.
- Endpoint:
Example Account Request
bashcurl -X GET "https://api.kucoin.com/api/v1/accounts" \ -H "KC-API-KEY:
" \ -H "KC-API-SIGN:" \ -H "KC-API-TIMESTAMP:" \ -H "KC-API-PASSPHRASE:" \ -H "KC-API-KEY-VERSION: 2"
5. Error Handling
Understanding how to handle errors effectively is crucial for developing robust applications. KuCoin API provides error codes to help diagnose issues.
Common Error Codes:
200000
: Invalid Request300000
: Permission Denied500000
: Server Error
Handling Errors: Ensure your application can handle different error responses gracefully. Implement retry logic for transient errors and log errors for debugging.
Example Error Response
json{ "code": "200000", "message": "Invalid Request" }
Conclusion
The KuCoin API offers a comprehensive set of endpoints to interact with the KuCoin exchange. By understanding authentication, market data, trading, account management, and error handling, you can build robust trading applications and tools. Refer to the official KuCoin API documentation for the latest updates and detailed information.
Hot Comments
No Comments Yet