eSeGeCe
software
The TsgcWSAPI_Kucoin and TsgcWSAPI_Kucoin_Futures components deliver comprehensive Delphi access to the KuCoin exchange, spanning real-time WebSocket market data, private account streams, and a full REST API for trading, withdrawals, and market queries. This guide covers every method available across both spot and futures, with configuration details and working code examples.
The spot WebSocket API provides real-time streaming for market data and private account events. Public channels are available without authentication, while private channels require valid API credentials.
Public channels stream market data to all connected clients without requiring authentication. Each subscribe method has a corresponding unsubscribe method.
| Method | Description |
|---|---|
SubscribeSymbolTicker |
Subscribes to real-time ticker updates for a specific trading symbol. |
SubscribeAllSymbolsTicker |
Subscribes to ticker updates for all symbols on the exchange. |
SubscribeSymbolSnapshot |
Subscribes to snapshot data for a specific symbol, including 24h statistics. |
SubscribeMarketSnapshot |
Subscribes to market-wide snapshot updates. |
SubscribeLevel2MarketData |
Subscribes to Level 2 order book changes (full depth). |
SubscribeLevel2_5BestAskBid |
Subscribes to the top 5 best ask and bid levels of the order book. |
SubscribeLevel2_50BestAskBid |
Subscribes to the top 50 best ask and bid levels of the order book. |
SubscribeKlines |
Subscribes to candlestick/kline data for a symbol at the specified interval. |
SubscribeMatchExecutionData |
Subscribes to real-time match/execution data for trades on a symbol. |
SubscribeIndexPrice |
Subscribes to index price updates for a symbol. |
SubscribeMarkPrice |
Subscribes to mark price updates for a symbol. |
SubscribeOrderBookChanged |
Subscribes to order book change events for a symbol. |
UnSubscribe counterpart (e.g., UnSubscribeSymbolTicker) to stop receiving updates for that channel.
Private channels require valid API credentials and provide real-time updates on your orders, balances, positions, and margin activity.
| Method | Description |
|---|---|
SubscribeTradeOrders |
Subscribes to real-time updates on your trade orders (open, filled, cancelled). |
SubscribeAccountBalance |
Subscribes to real-time account balance changes. |
SubscribePositionStatus |
Subscribes to position status updates for margin trading. |
SubscribeMarginTradeOrders |
Subscribes to margin trade order updates. |
SubscribeStopOrder |
Subscribes to stop order trigger and status updates. |
The spot REST API is accessed via the REST_API property of TsgcWSAPI_Kucoin. All methods return JSON strings. The API covers accounts, withdrawals, order management, stop orders, and market data.
| Method | Description |
|---|---|
GetAccounts |
Returns a list of all accounts (main, trade, margin). |
GetAccount |
Returns details for a specific account by account ID. |
GetAccountBalanceSubAccount |
Returns the balance of a sub-account. |
InnerTransfer |
Transfers funds between your internal accounts (e.g., main to trade). |
| Method | Description |
|---|---|
GetWithdrawalsList |
Returns a list of recent withdrawal records. |
GetHistoricalWithdrawalsList |
Returns historical withdrawal records beyond the recent window. |
GetWithdrawalsQuotas |
Returns the withdrawal quota and limits for a given currency. |
ApplyWithdraw |
Initiates a withdrawal to an external address. |
CancelWithdraw |
Cancels a pending withdrawal by its ID. |
| Method | Description |
|---|---|
PlaceOrder |
Places a new spot order (market or limit, buy or sell). |
PlaceMarginOrder |
Places a margin order with borrowed funds. |
CancelOrderByClientOid |
Cancels an order using the client-assigned order ID. |
GetOrder |
Returns details for a specific order by its exchange-assigned ID. |
GetOrderByClientOid |
Returns details for a specific order by its client-assigned ID. |
ListFills |
Returns a list of filled orders (trade executions). |
GetRecentFills |
Returns the most recent fill records. |
| Method | Description |
|---|---|
PlaceStopOrder |
Places a stop order that triggers when the stop price is reached. |
PlaceStopMarketOrder |
Places a stop-market order that executes at market price once triggered. |
PlaceStopLimitOrder |
Places a stop-limit order that creates a limit order once triggered. |
CancelStopOrder |
Cancels a stop order by its exchange-assigned ID. |
CancelStopOrderByClientOid |
Cancels a stop order by its client-assigned ID. |
CancelAllStopOrders |
Cancels all active stop orders, optionally filtered by symbol. |
GetStopOrder |
Returns details for a specific stop order by its exchange-assigned ID. |
GetStopOrderByClientOid |
Returns details for a specific stop order by its client-assigned ID. |
ListStopOrders |
Returns a list of all active stop orders. |
| Method | Description |
|---|---|
GetSymbolList |
Returns a list of available trading symbols. |
GetAllTickers |
Returns ticker data for all trading pairs. |
GetMarketList |
Returns a list of available markets. |
GetPartOrderBook100 |
Returns the top 100 entries of the order book for a symbol. |
GetFullOrderBook |
Returns the full order book for a symbol (Level 3 data). |
GetHistories |
Returns recent trade history for a symbol. |
GetKLines |
Returns candlestick/kline data for a symbol at a given interval. |
GetCurrencies |
Returns a list of all supported currencies. |
GetCurrencyDetail |
Returns details for a specific currency (chain info, precision, etc.). |
GetFiatPrice |
Returns the fiat price for specified currencies (e.g., USD value of BTC). |
The futures WebSocket API is provided by TsgcWSAPI_Kucoin_Futures and offers real-time streaming for futures contract data and private account events.
| Method | Description |
|---|---|
SubscribeSymbolTickerV2 |
Subscribes to V2 ticker updates for a futures contract symbol. |
SubscribeSymbolTicker |
Subscribes to ticker updates for a futures contract symbol. |
SubscribeLevel2MarketData |
Subscribes to Level 2 order book data for a futures contract. |
SubscribeExecutionData |
Subscribes to real-time match/execution data for futures trades. |
SubscribeLevel2_5BestAskBid |
Subscribes to the top 5 best ask/bid levels for a futures contract. |
SubscribeLevel2_50BestAskBid |
Subscribes to the top 50 best ask/bid levels for a futures contract. |
SubscribeContractMarketData |
Subscribes to contract-level market data (funding rate, mark price, etc.). |
SubscribeSystemAnnouncements |
Subscribes to system-wide announcements and maintenance notices. |
SubscribeTransactionStatistics |
Subscribes to aggregated transaction statistics for a futures contract. |
UnSubscribe counterpart to stop receiving updates for that channel.
| Method | Description |
|---|---|
SubscribeTradeOrders |
Subscribes to real-time updates on your futures trade orders. |
SubscribeStopOrder |
Subscribes to stop order trigger and status updates for futures. |
SubscribeAccountBalance |
Subscribes to real-time futures account balance changes. |
SubscribePositionChange |
Subscribes to position change events (open, close, liquidation). |
The futures REST API is accessed via the REST_API property of TsgcWSAPI_Kucoin_Futures. These methods cover margin management, risk limits, funding history, and order book queries.
| Method | Description |
|---|---|
AddMarginManually |
Manually adds margin to a futures position. |
ObtainFuturesRiskLimitLevel |
Returns the current risk limit level for a futures contract. |
AdjustRiskLimitLevel |
Adjusts the risk limit level for a futures contract. |
GetFundingHistory |
Returns the funding rate history for a futures contract. |
GetPartOrderBook100 |
Returns the top 100 entries of the futures order book. |
GetFullOrderBook |
Returns the full futures order book. |
GetLevel2PullingMessages |
Returns Level 2 pulling messages for incremental order book updates. |
GetInterestRateList |
Returns the interest rate list used for funding calculations. |
GetIndexList |
Returns the index composition list for a futures contract. |
The following example demonstrates how to create and configure the TsgcWSAPI_Kucoin component for spot trading, authenticate with the API, retrieve tickers via REST, place an order, and subscribe to a real-time ticker stream via WebSocket.
var
oClient: TsgcWebSocketClient;
oKucoin: TsgcWSAPI_Kucoin;
begin
// Create the WebSocket client
oClient := TsgcWebSocketClient.Create(nil);
oKucoin := TsgcWSAPI_Kucoin.Create(nil);
oKucoin.Client := oClient;
// Configure API credentials
oKucoin.Kucoin.ApiKey := 'your_api_key';
oKucoin.Kucoin.ApiSecret := 'your_api_secret';
oKucoin.Kucoin.Passphrase := 'your_passphrase';
// Connect to KuCoin
oClient.Active := True;
// REST: Get all tickers
ShowMessage(oKucoin.REST_API.GetAllTickers);
// REST: Place a limit order
ShowMessage(oKucoin.REST_API.PlaceOrder(myOrder));
// WebSocket: Subscribe to BTC-USDT ticker
oKucoin.SubscribeSymbolTicker('BTC-USDT');
end;
Assign an event handler to process incoming messages. The event provides the topic, subject, and JSON data for each update.
procedure TForm1.OnKucoinEvent(Sender: TObject;
const aTopic, aSubject, aData: string);
begin
// aTopic identifies the channel
// aSubject provides the specific symbol or identifier
// aData contains the JSON payload
Memo1.Lines.Add(aTopic + ' [' + aSubject + ']: ' + aData);
end;
Both TsgcWSAPI_Kucoin (spot) and TsgcWSAPI_Kucoin_Futures (futures) share the same authentication properties, accessed through the Kucoin property.
| Property | Type | Description |
|---|---|---|
Kucoin.ApiKey |
String | Your KuCoin API key. Generate this from the KuCoin API Management page. |
Kucoin.ApiSecret |
String | Your KuCoin API secret. Keep this value secure and never expose it in client-side code. |
Kucoin.Passphrase |
String | The passphrase you set when creating the API key. Required for all authenticated requests. |
TsgcWSAPI_Kucoin for spot trading and TsgcWSAPI_Kucoin_Futures for futures trading. Each component connects to a different KuCoin endpoint.Passphrase property is mandatory for KuCoin and is set during API key creation on the KuCoin website.TJSONObject from System.JSON) to parse responses.When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.