or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account-management.mdearn-products.mdindex.mdlending.mdmargin-trading.mdmarket-data.mdspot-trading.mdwebsocket.md
tile.json

tessl/pypi-kucoin-python

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/kucoin-python@1.0.x

To install, run

npx @tessl/cli install tessl/pypi-kucoin-python@1.0.0

index.mddocs/

KuCoin Python SDK

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.

Note: This SDK has been deprecated in favor of the KuCoin Universal SDK, but remains functional for existing integrations.

Package Information

  • Package Name: kucoin-python
  • Language: Python
  • Installation: pip install kucoin-python
  • Minimum Python Version: 3.6+

Core Imports

from kucoin.client import Market, Trade, User, Margin, Lending, Earn, WsToken

For WebSocket functionality:

from kucoin.ws_client import KucoinWsClient

Basic Usage

from 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')

Architecture

The SDK is organized into specialized client classes, each inheriting from KucoinBaseRestApi:

  • Core Request Handler: Base class handling authentication, HTTP requests, and error handling
  • Client Classes: High-level interfaces for different API categories
  • WebSocket Support: Real-time data streaming with automatic reconnection
  • Authentication: Built-in signature generation and request signing

This modular design allows selective usage of only the needed functionality while maintaining consistent authentication and error handling patterns across all API categories.

Capabilities

Market Data

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(): ...

Market Data

Spot Trading

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): ...

Spot Trading

Account Management

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): ...

Account Management

Margin Trading

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): ...

Margin Trading

Lending Market

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): ...

Lending

Earn Products

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(): ...

Earn Products

WebSocket Streaming

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): ...

WebSocket Streaming

Error Handling

The SDK provides comprehensive error handling for:

  • HTTP request errors and timeouts
  • API response errors with detailed error codes
  • Authentication failures and invalid signatures
  • Rate limiting and quota exceeded errors
  • WebSocket connection and subscription errors

All methods may raise exceptions that should be handled appropriately in production code.

Types

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."""