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.0A 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.
Note: This SDK has been deprecated in favor of the KuCoin Universal SDK, but remains functional for existing integrations.
pip install kucoin-pythonfrom kucoin.client import Market, Trade, User, Margin, Lending, Earn, WsTokenFor WebSocket functionality:
from kucoin.ws_client import KucoinWsClientfrom kucoin.client import Market, Trade, User
# Initialize clients with API credentials
api_key = 'your-api-key'
api_secret = 'your-api-secret'
api_passphrase = 'your-api-passphrase'
is_sandbox = False # Set to True for sandbox environment
# Market data (no authentication required)
market = Market()
symbols = market.get_symbol_list()
ticker = market.get_ticker('BTC-USDT')
# Trading operations (authentication required)
trade = Trade(api_key, api_secret, api_passphrase, is_sandbox)
order = trade.create_limit_order(
symbol='BTC-USDT',
side='buy',
size='0.001',
price='30000'
)
# Account management (authentication required)
user = User(api_key, api_secret, api_passphrase, is_sandbox)
accounts = user.get_account_list()
balance = user.get_account('account-id')The SDK is organized into specialized client classes, each inheriting from KucoinBaseRestApi:
This modular design allows selective usage of only the needed functionality while maintaining consistent authentication and error handling patterns across all API categories.
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.
def get_symbol_list(**kwargs): ...
def get_ticker(symbol: str): ...
def get_all_tickers(): ...
def get_24h_stats(symbol: str): ...
def get_kline(symbol: str, kline_type: str, **kwargs): ...
def get_currencies(): ...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.
def create_limit_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs): ...
def create_market_order(symbol: str, side: str, clientOid: str = '', size: str = None, funds: str = None, **kwargs): ...
def cancel_order(orderId: str): ...
def get_order_list(**kwargs): ...
def get_fill_list(tradeType: str, **kwargs): ...User account operations including balance management, transfers, deposits, withdrawals, sub-account management, and fee information. Comprehensive account ledger and transaction history access.
def get_account_list(currency: str = None, account_type: str = None): ...
def get_account(accountId: str): ...
def inner_transfer(currency: str, from_payer: str, to_payee: str, amount: str, clientOid: str = '', **kwargs): ...
def apply_withdrawal(currency: str, address: str, amount: float, **kwargs): ...Cross and isolated margin trading with borrowing, repayment, and position management. Supports margin order placement, risk management, and lending market operations.
def get_margin_account(): ...
def margin_borrowing(currency: str, timeinforce: str, size: str, isHf: bool = False, **kwargs): ...
def repayment(currency: str, size: str, isIsolated: bool = None, symbol: str = None, isHf: bool = False): ...
def create_limit_margin_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs): ...Lending market operations for earning interest on cryptocurrency holdings. Supports subscription, redemption, and portfolio management for various lending products.
def get_currency_information(currency: str): ...
def subscription(currency: str, interest_rate: str, size: str): ...
def redemption(currency: str, purchase_order_no: str, size: str): ...Access to KuCoin's earning products including savings, staking, and fixed income products. Comprehensive portfolio management for various cryptocurrency earning opportunities.
def get_earn_savings_products(): ...
def get_earn_staking_products(): ...
def get_earn_fixed_income_current_holdings(): ...Real-time market data and account updates through WebSocket connections. Supports automatic reconnection, subscription management, and comprehensive event handling.
class KucoinWsClient:
@classmethod
async def create(cls, loop, client, callback, private: bool = False, sock=None): ...
async def subscribe(self, topic: str): ...
async def unsubscribe(self, topic: str): ...
@property
def topics(self): ...The SDK provides comprehensive error handling for:
All methods may raise exceptions that should be handled appropriately in production code.
class KucoinBaseRestApi:
"""Base class for all KuCoin API clients with authentication and request handling."""
def __init__(self, key: str = '', secret: str = '', passphrase: str = '', is_sandbox: bool = False, url: str = ''):
"""
Initialize client with API credentials.
Args:
key (str): API key
secret (str): API secret
passphrase (str): API passphrase
is_sandbox (bool): Use sandbox environment
url (str): Custom API base URL
"""
def _request(self, method: str, endpoint: str, params: dict = None, auth: bool = True): ...
@property
def return_unique_id(self) -> str:
"""Generate a unique client order ID."""