CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Pending
Overview
Eval results
Files

lending.mddocs/

Lending

KuCoin Lending Market V3 operations for earning interest on cryptocurrency holdings. Provides subscription and redemption services for various lending products with flexible terms and competitive rates.

Capabilities

Currency Information

Access detailed information about lending currencies and their parameters.

def get_currency_information(currency: str):
    """
    Get detailed currency information for lending.
    
    Args:
        currency (str): Currency code (e.g., 'USDT', 'BTC')
    
    Returns:
        dict: Currency lending parameters including minimum amounts, rates, and terms
    """

Interest Rates

Current and historical interest rate information.

def get_interest_rates(currency: str):
    """
    Get current interest rates for lending currency.
    
    Args:
        currency (str): Currency code
    
    Returns:
        dict: Interest rate information with current rates and historical data
    """

Subscription Operations

Subscribe to lending products to start earning interest.

def subscription(currency: str, interest_rate: str, size: str):
    """
    Subscribe to a lending product.
    
    Args:
        currency (str): Currency to lend (e.g., 'USDT')
        size (str): Amount to lend
        interestRate (str): Expected interest rate
    
    Returns:
        dict: Subscription order information with order ID
    """

def modify_subscription_orders(currency: str, purchaseOrderNo: str, interestRate: str):
    """
    Modify existing subscription order interest rate.
    
    Args:
        currency (str): Currency code
        purchaseOrderNo (str): Purchase order number to modify
        interestRate (str): New interest rate
    
    Returns:
        dict: Modification result
    """

def get_subscription_orders(currency: str, **kwargs):
    """
    Get subscription order history.
    
    Args:
        currency (str): Currency code
        status (str, optional): Order status filter
        currentPage (int, optional): Page number
        pageSize (int, optional): Page size
    
    Returns:
        dict: Paginated subscription orders
    """

Redemption Operations

Redeem funds from lending products.

def redemption(currency: str, purchase_order_no: str, size: str):
    """
    Redeem funds from a lending subscription.
    
    Args:
        currency (str): Currency to redeem
        size (str): Amount to redeem
        purchaseOrderNo (str): Purchase order number for redemption
    
    Returns:
        dict: Redemption order information
    """

def get_redemption_orders(currency: str, **kwargs):
    """
    Get redemption order history.
    
    Args:
        currency (str): Currency code
        status (str, optional): Order status filter
        redeemOrderNo (str, optional): Specific redemption order number
        currentPage (int, optional): Page number
        pageSize (int, optional): Page size
    
    Returns:
        dict: Paginated redemption orders
    """

Usage Examples

Basic Lending Operations

from kucoin.client import Lending

# Initialize lending client
lending = Lending(api_key, api_secret, api_passphrase, is_sandbox=False)

# Get currency information for USDT lending
currency_info = lending.get_currency_info('USDT')
print(f"Min lending amount: {currency_info['minPurchaseSize']}")
print(f"Currency precision: {currency_info['precision']}")

# Check current interest rates
rates = lending.get_interest_rates('USDT')
print(f"Current rate: {rates['currentAnnualRate']}% annual")

Lending Subscription

# Subscribe to USDT lending
subscription = lending.post_subscription(
    currency='USDT',
    size='1000',
    interestRate='0.05'  # 5% annual rate
)
print(f"Subscription order: {subscription['orderNo']}")

# Check subscription orders
subscriptions = lending.get_subscription_orders('USDT')
for order in subscriptions['items']:
    print(f"Order {order['orderNo']}: {order['size']} USDT at {order['interestRate']}% rate")
    print(f"Status: {order['status']}, Interest earned: {order['interestAmount']}")

Modifying Subscriptions

# Modify interest rate for existing subscription
modify_result = lending.modify_subscription_orders(
    currency='USDT',
    purchaseOrderNo='order-123456',
    interestRate='0.06'  # Change to 6% annual rate
)
print(f"Modification result: {modify_result}")

Redemption Operations

# Redeem funds from lending
redemption = lending.post_redemption(
    currency='USDT',
    size='500',  # Redeem 500 USDT
    purchaseOrderNo='order-123456'
)
print(f"Redemption order: {redemption['orderNo']}")

# Check redemption history
redemptions = lending.get_redemption_orders('USDT')
for order in redemptions['items']:
    print(f"Redemption {order['redeemOrderNo']}: {order['size']} USDT")
    print(f"Status: {order['status']}, Processing time: {order['updatedAt']}")

Portfolio Management

# Monitor all active lending positions
active_subscriptions = lending.get_subscription_orders('USDT', status='ACTIVE')
total_lent = sum(float(order['size']) for order in active_subscriptions['items'])
total_interest = sum(float(order['interestAmount']) for order in active_subscriptions['items'])

print(f"Total amount lent: {total_lent} USDT")
print(f"Total interest earned: {total_interest} USDT")
print(f"Average return: {(total_interest / total_lent * 100):.2f}%")

# Diversify across different currencies
currencies = ['USDT', 'BTC', 'ETH']
for currency in currencies:
    try:
        info = lending.get_currency_info(currency)
        rates = lending.get_interest_rates(currency)
        print(f"{currency}: Min amount {info['minPurchaseSize']}, Current rate {rates['currentAnnualRate']}%")
    except Exception as e:
        print(f"Error getting {currency} info: {e}")

Advanced Rate Monitoring

# Compare rates across time periods
import time

def monitor_rates(currency, duration_minutes=60):
    """Monitor interest rates for a currency over time."""
    rates_history = []
    end_time = time.time() + (duration_minutes * 60)
    
    while time.time() < end_time:
        try:
            rates = lending.get_interest_rates(currency)
            current_rate = float(rates['currentAnnualRate'])
            rates_history.append({
                'timestamp': time.time(),
                'rate': current_rate
            })
            print(f"{currency} rate: {current_rate}%")
            time.sleep(300)  # Check every 5 minutes
        except Exception as e:
            print(f"Error monitoring rates: {e}")
            break
    
    return rates_history

# Monitor USDT rates for 1 hour
# usdt_rates = monitor_rates('USDT', 60)

Types

CurrencyInfo = dict
# {
#   "currency": str,         # Currency code
#   "purchaseEnable": bool,  # Subscription enabled
#   "redeemEnable": bool,    # Redemption enabled
#   "increment": str,        # Amount increment
#   "minPurchaseSize": str,  # Minimum subscription amount
#   "minInterestRate": str,  # Minimum interest rate
#   "maxInterestRate": str,  # Maximum interest rate
#   "interestIncrement": str, # Interest rate increment
#   "maxPurchaseSize": str,  # Maximum subscription amount
#   "marketInterestRate": str, # Market interest rate
#   "autoPurchaseEnable": bool, # Auto-purchase enabled
#   "precision": int         # Currency precision
# }

InterestRateInfo = dict
# {
#   "currentAnnualRate": str, # Current annual interest rate
#   "currency": str,          # Currency code
#   "marketInterestRate": str, # Market interest rate
#   "basicInterestRate": str, # Basic interest rate
#   "floatingInterestRate": str, # Floating interest rate
#   "annualInterestRate": str # Annual interest rate
# }

SubscriptionOrder = dict
# {
#   "orderNo": str,          # Order number
#   "currency": str,         # Currency
#   "size": str,             # Subscription amount
#   "lentAmount": str,       # Actually lent amount
#   "interestRate": str,     # Interest rate
#   "interestAmount": str,   # Interest earned
#   "incomeAmount": str,     # Total income
#   "applyTime": int,        # Application time
#   "status": str            # Order status ('PENDING', 'ACTIVE', 'DONE', 'CANCELED')
# }

RedemptionOrder = dict
# {
#   "redeemOrderNo": str,    # Redemption order number
#   "currency": str,         # Currency
#   "size": str,             # Redemption amount
#   "principal": str,        # Principal amount
#   "interestAmount": str,   # Interest amount
#   "applyTime": int,        # Application time
#   "status": str,           # Redemption status
#   "updatedAt": int         # Last update time
# }

SubscriptionResponse = dict
# {
#   "orderNo": str          # Subscription order number
# }

RedemptionResponse = dict
# {
#   "orderNo": str          # Redemption order number
# }

Install with Tessl CLI

npx tessl i tessl/pypi-kucoin-python

docs

account-management.md

earn-products.md

index.md

lending.md

margin-trading.md

market-data.md

spot-trading.md

websocket.md

tile.json