KuCoin trading bot: the three-part key, ccxt and the sandbox
KuCoin is a popular altcoin-heavy exchange with built-in trading bots and an open API. The one thing that trips up newcomers is KuCoin's three-part credential: unlike most exchanges, a KuCoin API key needs a key, a secret and a passphrase you set yourself. Get all three into ccxt and the rest is familiar territory. This guide covers the credential, the connection, spot orders and KuCoin's sandbox.
Why traders pick KuCoin
- Wide altcoin coverage — many small-cap pairs list here before larger venues.
- Native exchange bots — built-in grid and DCA bots for users who don't want to code.
- Full ccxt support — for a custom bot, KuCoin's REST and WebSocket APIs are well-mapped in ccxt.
Altcoin liquidity is thinner than majors, so test how slippage eats your edge on the backtester before trading small caps live.
Step 1 — the three-part credential
When you create a KuCoin API key you set a passphrase yourself. That passphrase is required on every signed request alongside the key and secret — miss it and every private call returns an auth error.
Enable General and Trade permissions; leave Transfer/Withdraw off. Whitelist your server IP, and store the key, secret and passphrase as three separate environment variables.
Step 2 — connect with ccxt
python · kucoin_connect.pyimport ccxt, os
ex = ccxt.kucoin({
'apiKey': os.environ['KUCOIN_KEY'],
'secret': os.environ['KUCOIN_SECRET'],
'password': os.environ['KUCOIN_PASSPHRASE'], # the 3rd part!
'enableRateLimit': True,
})
print(ex.fetch_balance()['USDT']['free'])
Step 3 — use the sandbox
KuCoin offers a sandbox with separate credentials and fake funds. Point ccxt at it with set_sandbox_mode(True) and validate your full order flow before touching real balances.
python · kucoin_sandbox.pyex.set_sandbox_mode(True) # requires sandbox API keys
Step 4 — place a spot order
python · kucoin_order.pyif signal() == 'buy':
o = ex.create_market_buy_order('BTC/USDT', 0.001)
print('order', o['id'])
Thin books mean market orders can fill far from the last price. Use limit orders on small caps and size with the position calculator.
Safe-start checklist
- Edge survives fees and realistic slippage on the backtester.
- Key + secret + passphrase set; trade-only, no withdrawals.
- Full order loop validated in the sandbox.
- Limit orders on illiquid pairs; tiny size first.
- Kill switch on a max-drawdown threshold.
Frequently asked questions
Why does KuCoin need a passphrase for its API?
KuCoin uses a three-part credential: the API key, the secret and a passphrase you choose when creating the key. All three are required to sign every private request. In ccxt you pass the passphrase as the 'password' field — leaving it out causes authentication errors.
Does KuCoin have a sandbox for bots?
Yes. KuCoin provides a sandbox environment with separate API credentials and fake funds. Calling set_sandbox_mode(True) in ccxt points your bot there so you can validate the full order flow before risking real money.
Is KuCoin safe for automated trading?
KuCoin's API is reliable and supported by ccxt, but it lists many thin-liquidity altcoins where market orders can slip badly. Use trade-only keys with no withdrawal rights, prefer limit orders on small caps, and keep position sizes conservative.
Can I build a free KuCoin bot?
Yes. The KuCoin API is free apart from standard trading fees, and ccxt is open-source. A self-hosted Python or JavaScript bot costs nothing beyond hosting. Always backtest the strategy first on our free tool.