kucoin

Crates.iokucoin
lib.rskucoin
version0.7.4
created_at2025-11-26 16:00:11.672997+00
updated_at2026-01-07 14:03:10.510543+00
descriptionA robust and asynchronous Rust client for the KuCoin exchange API.
homepage
repositoryhttps://github.com/blackh-t/kucoin
max_upload_size
id1951625
size181,407
N-Choo (blackh-t)

documentation

https://docs.rs/kucoin

README

KuCoin Rust Client

An asynchronous, strongly typed Rust client for the KuCoin REST API.

Designed for reliability and production use, this crate provides ergonomic wrappers for KuCoin endpoints covering spot trading, wallet activity, and sub-account management.


Features

  • Async-first — built on tokio and reqwest

  • Spot trading

    • Market & limit orders
    • Batch orders
    • Order cancellation
    • Retrieve open orders
  • Wallet & deposits

    • Deposit history with filters
    • Lookup by transaction hash
  • Sub-accounts

    • List sub-accounts
    • Create API keys
    • Configure permissions & IP whitelists
    • Query sub-account balances
  • Typed requests

    • Builder-pattern request structs
    • Compile-time parameter validation

Installation

[dependencies]
kucoin = "0.4.0"
tokio = { version = "1", features = ["full"] }
dotenv = "0.15" # optional

Quick Start

Client Initialization

use std::env;
use kucoin::client::rest::{Credentials, KuCoinClient};

#[tokio::main]
async fn main() {
    let credentials = Credentials::new(
        &env::var("API_KEY").expect("API_KEY not set"),
        &env::var("API_SECRET").expect("API_SECRET not set"),
        &env::var("API_PASSPHRASE").expect("API_PASSPHRASE not set"),
    );

    let client = KuCoinClient::new(credentials);
}

Spot Trading

Place an Order

use kucoin::types::spot::{SpotOrderRequest, TradeType, Side};

async fn place_order(client: &KuCoinClient) {
    let order = SpotOrderRequest::new(TradeType::Market, "BTC-USDT", Side::Buy)
        .set_funds(100.0)
        .set_remark("example-order");

    client.spot().place_order(order).await.unwrap();
}

Batch Orders

use kucoin::types::spot::{BatchSpotContract, SpotOrderRequest, TradeType, Side};

async fn batch_orders(client: &KuCoinClient) {
    let batch = BatchSpotContract::new()
        .add_order(
            SpotOrderRequest::new(TradeType::Market, "BTC-USDT", Side::Buy)
                .set_funds(50.0),
        )
        .add_order(
            SpotOrderRequest::new(TradeType::Market, "SOL-USDT", Side::Buy)
                .set_funds(20.0),
        );

    client.spot().place_multi_orders(batch).await.unwrap();
}

Cancel & List Orders

use kucoin::types::spot::SpotCancelRequest;

async fn cancel(client: &KuCoinClient, order_id: &str) {
    let req = SpotCancelRequest::new(order_id, 0.0, "BTC-USDT");
    client.spot().cancel_order(req).await.unwrap();
}

async fn open_orders(client: &KuCoinClient) {
    let res = client.spot().list_orders_open("BTC-USDT").await.unwrap();
    println!("{:#?}", res.data);
}

Deposits

use kucoin::types::deposit::{DepositHistoryRequest, DepositStatus};

async fn deposits(client: &KuCoinClient) {
    let req = DepositHistoryRequest::new("SOL")
        .set_status(DepositStatus::Success)
        .set_page_size(20);

    client.deposit().history(req).await.unwrap();
}
async fn lookup(client: &KuCoinClient, tx: &str) {
    let res = client.deposit().by_tx_hash(tx).await.unwrap();
    println!("{:#?}", res);
}

Sub-Accounts

use kucoin::types::sup_account::{SubAccRequest, Expire};

async fn create_sub(client: &KuCoinClient) {
    let req = SubAccRequest::new("SubUser01", "Trading Bot", "StrongPass123!")
        .set_permission("General,Spot")
        .add_ipwhitelist("192.168.1.1")
        .set_expire(Expire::Never);

    client.sub_account().add_api(req).await.unwrap();
}
async fn list_subs(client: &KuCoinClient) {
    let res = client.sub_account().fetchall().await.unwrap();
    println!("{:#?}", res.data);
}
async fn balance(client: &KuCoinClient, uid: &str) {
    let res = client.sub_account().balance(uid).await.unwrap();
    println!("{:#?}", res.data);
}

Real-World Usage

This crate is used in CoinBot, an automated crypto trading platform built in Rust.

This serves as a production reference for high-frequency and automated trading workloads.


Project Structure

  • client/ — authentication & HTTP layer
  • endpoints/ — KuCoin API endpoints
  • types/ — request and response models
  • utils/ — shared helpers

Contributing

Issues and pull requests are welcome.


Commit count: 40

cargo fmt