A Python SDK for KuCoin cryptocurrency exchange API providing REST endpoints implementation, simple authentication handling, response exception handling, and websocket support for trading, market data, user account management, margin trading, lending, and earning features
npx @tessl/cli install tessl/pypi-kucoin-python@1.0.00
# KuCoin Python SDK
1
2
A comprehensive Python SDK for the KuCoin cryptocurrency exchange API. Provides complete access to KuCoin's trading, market data, account management, margin trading, lending, and earning features through REST endpoints and WebSocket streaming.
3
4
**Note**: This SDK has been deprecated in favor of the KuCoin Universal SDK, but remains functional for existing integrations.
5
6
## Package Information
7
8
- **Package Name**: kucoin-python
9
- **Language**: Python
10
- **Installation**: `pip install kucoin-python`
11
- **Minimum Python Version**: 3.6+
12
13
## Core Imports
14
15
```python
16
from kucoin.client import Market, Trade, User, Margin, Lending, Earn, WsToken
17
```
18
19
For WebSocket functionality:
20
21
```python
22
from kucoin.ws_client import KucoinWsClient
23
```
24
25
## Basic Usage
26
27
```python
28
from kucoin.client import Market, Trade, User
29
30
# Initialize clients with API credentials
31
api_key = 'your-api-key'
32
api_secret = 'your-api-secret'
33
api_passphrase = 'your-api-passphrase'
34
is_sandbox = False # Set to True for sandbox environment
35
36
# Market data (no authentication required)
37
market = Market()
38
symbols = market.get_symbol_list()
39
ticker = market.get_ticker('BTC-USDT')
40
41
# Trading operations (authentication required)
42
trade = Trade(api_key, api_secret, api_passphrase, is_sandbox)
43
order = trade.create_limit_order(
44
symbol='BTC-USDT',
45
side='buy',
46
size='0.001',
47
price='30000'
48
)
49
50
# Account management (authentication required)
51
user = User(api_key, api_secret, api_passphrase, is_sandbox)
52
accounts = user.get_account_list()
53
balance = user.get_account('account-id')
54
```
55
56
## Architecture
57
58
The SDK is organized into specialized client classes, each inheriting from `KucoinBaseRestApi`:
59
60
- **Core Request Handler**: Base class handling authentication, HTTP requests, and error handling
61
- **Client Classes**: High-level interfaces for different API categories
62
- **WebSocket Support**: Real-time data streaming with automatic reconnection
63
- **Authentication**: Built-in signature generation and request signing
64
65
This modular design allows selective usage of only the needed functionality while maintaining consistent authentication and error handling patterns across all API categories.
66
67
## Capabilities
68
69
### Market Data
70
71
Access to comprehensive market information including symbols, tickers, order books, trade history, candlestick data, and currency details. No authentication required for public market data endpoints.
72
73
```python { .api }
74
def get_symbol_list(**kwargs): ...
75
def get_ticker(symbol: str): ...
76
def get_all_tickers(): ...
77
def get_24h_stats(symbol: str): ...
78
def get_kline(symbol: str, kline_type: str, **kwargs): ...
79
def get_currencies(): ...
80
```
81
82
[Market Data](./market-data.md)
83
84
### Spot Trading
85
86
Complete spot trading functionality including order placement, cancellation, management, and trade history. Supports limit orders, market orders, stop orders, bulk operations, and high-frequency trading.
87
88
```python { .api }
89
def create_limit_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs): ...
90
def create_market_order(symbol: str, side: str, clientOid: str = '', size: str = None, funds: str = None, **kwargs): ...
91
def cancel_order(orderId: str): ...
92
def get_order_list(**kwargs): ...
93
def get_fill_list(tradeType: str, **kwargs): ...
94
```
95
96
[Spot Trading](./spot-trading.md)
97
98
### Account Management
99
100
User account operations including balance management, transfers, deposits, withdrawals, sub-account management, and fee information. Comprehensive account ledger and transaction history access.
101
102
```python { .api }
103
def get_account_list(currency: str = None, account_type: str = None): ...
104
def get_account(accountId: str): ...
105
def inner_transfer(currency: str, from_payer: str, to_payee: str, amount: str, clientOid: str = '', **kwargs): ...
106
def apply_withdrawal(currency: str, address: str, amount: float, **kwargs): ...
107
```
108
109
[Account Management](./account-management.md)
110
111
### Margin Trading
112
113
Cross and isolated margin trading with borrowing, repayment, and position management. Supports margin order placement, risk management, and lending market operations.
114
115
```python { .api }
116
def get_margin_account(): ...
117
def margin_borrowing(currency: str, timeinforce: str, size: str, isHf: bool = False, **kwargs): ...
118
def repayment(currency: str, size: str, isIsolated: bool = None, symbol: str = None, isHf: bool = False): ...
119
def create_limit_margin_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs): ...
120
```
121
122
[Margin Trading](./margin-trading.md)
123
124
### Lending Market
125
126
Lending market operations for earning interest on cryptocurrency holdings. Supports subscription, redemption, and portfolio management for various lending products.
127
128
```python { .api }
129
def get_currency_information(currency: str): ...
130
def subscription(currency: str, interest_rate: str, size: str): ...
131
def redemption(currency: str, purchase_order_no: str, size: str): ...
132
```
133
134
[Lending](./lending.md)
135
136
### Earn Products
137
138
Access to KuCoin's earning products including savings, staking, and fixed income products. Comprehensive portfolio management for various cryptocurrency earning opportunities.
139
140
```python { .api }
141
def get_earn_savings_products(): ...
142
def get_earn_staking_products(): ...
143
def get_earn_fixed_income_current_holdings(): ...
144
```
145
146
[Earn Products](./earn-products.md)
147
148
### WebSocket Streaming
149
150
Real-time market data and account updates through WebSocket connections. Supports automatic reconnection, subscription management, and comprehensive event handling.
151
152
```python { .api }
153
class KucoinWsClient:
154
@classmethod
155
async def create(cls, loop, client, callback, private: bool = False, sock=None): ...
156
async def subscribe(self, topic: str): ...
157
async def unsubscribe(self, topic: str): ...
158
@property
159
def topics(self): ...
160
```
161
162
[WebSocket Streaming](./websocket.md)
163
164
## Error Handling
165
166
The SDK provides comprehensive error handling for:
167
168
- HTTP request errors and timeouts
169
- API response errors with detailed error codes
170
- Authentication failures and invalid signatures
171
- Rate limiting and quota exceeded errors
172
- WebSocket connection and subscription errors
173
174
All methods may raise exceptions that should be handled appropriately in production code.
175
176
## Types
177
178
```python { .api }
179
class KucoinBaseRestApi:
180
"""Base class for all KuCoin API clients with authentication and request handling."""
181
182
def __init__(self, key: str = '', secret: str = '', passphrase: str = '', is_sandbox: bool = False, url: str = ''):
183
"""
184
Initialize client with API credentials.
185
186
Args:
187
key (str): API key
188
secret (str): API secret
189
passphrase (str): API passphrase
190
is_sandbox (bool): Use sandbox environment
191
url (str): Custom API base URL
192
"""
193
194
def _request(self, method: str, endpoint: str, params: dict = None, auth: bool = True): ...
195
196
@property
197
def return_unique_id(self) -> str:
198
"""Generate a unique client order ID."""
199
```