API Kucoin

Kucoin

 

Kucoin is an international multi-language cryptocurrency exchange. It offers some APIs to access Kucoin data. The following APIs are supported:

 

  1. WebSocket streams: allows to subscribe to some methods and get data in real-time. Events are pushed to clients by server to subscribers. Uses WebSocket as protocol.
  2. REST API: clients can request to server market and account data. Requires an API Key, Secret and Passphrase to authenticate and uses HTTPs as protocol.

 

 

Properties

Kucoin API has 2 types of methods: public and private. Public methods can be accessed without authentication, example: get ticker prices. Private and related to user data methods requires the use of Kucoin API keys.

 

 

Most common uses

 

WebSocket Feed

To subscribe channel messages from a certain server, the client side should send subscription message to the server.

If the subscription succeeds, the system will send ack messages to you, when the response is set as true.

{
    "id":"1545910660739",
    "type":"ack"
}
While there are topic messages generated, the system will send the corresponding messages to the client side.

 

The following Subscription / Unsubscription methods are supported.

 

Public Channels

 

Method Parameters Description
SubscribeSymbolTicker Symbol Subscribe to this topic to get the push of BBO changes. If there is no change within one second, it will not be pushed. It will be pushed per 100ms with the newest BBO. If there was no change compared with last data, it will not be pushed.
SubscribeAllSymbolsTicker   Subscribe to this topic to get the push of all market symbols BBO change.
SubscribeSymbolSnapshot Symbol Subscribe to get snapshot data for a single symbol. The snapshot data is pushed at 2 seconds intervals.
SubscribeMarketSnapshot Market Subscribe this topic to get the snapshot data of for the entire market. The snapshot data is pushed at 2 seconds intervals.
SubscribeLevel2MarketData Symbol Subscribe to this topic to get Level2 order book data. When the websocket subscription is successful, the system would send the increment change data pushed by the websocket to you.
SubscribeLevel2_5BestAskBid Symbol The system will return the 5 best ask/bid orders data, which is the snapshot data of every 100 milliseconds (in other words, the 5 best ask/bid orders data returned every 100 milliseconds in real-time).
SubscribeLevel2_50BestAskBid Symbol The system will return the 50 best ask/bid orders data, which is the snapshot data of every 100 milliseconds (in other words, the 50 best ask/bid orders data returned every 100 milliseconds in real-time).
SubscribeKlines Symbol Subscribe to this topic to get K-Line data.
SubscribeMatchExecutionData Symbol Subscribe to this topic to get the matching event data flow of Level 3. For each order traded, the system would send you the match messages in the following format.
SubscribeIndexPrice Symbol Subscribe to this topic to get the index price for the margin trading.
SubscribeMarkPrice Symbol Subscribe to this topic to get the mark price for margin trading.
SubscribeOrderBookChanged Symbol Subscribe to this topic to get the order book changes on margin trade.

 

If ACK parameter is sent to true, after a successful subcription / unsubscription, client receives a message about it.

 

Private Channels

Requires a valid ApiKey obtained from your Kucoin account. The ApiKey, ApiSecret and Passphrase must be set in the Kucoin property of the client API component.

 

The following data is pushed to client every time there is a change. There is no need to subscribe to any method, this is done automatically if you set a valid ApiKey.

 

Method Description
SubscribeTradeOrders This topic will push all change events of your orders.
SubscribeAccountBalance

You will receive this message when an account balance changes. The message contains the details of the change.

SubscribePositionStatus The system will push the change event when the position status changes.
SubscribeMarginTradeOrders The system will push this message to the lenders when the order enters the order book.
SubscribeStopOrder When a stop order is received by the system, you will receive a message with "open" type. It means that this order entered the system and waited to be triggered.

 

 

REST API

All endpoints return either a JSON object or array. 

 

Public API EndPoints

 

These endpoints can be accessed without any authorization.

 

General EndPoints

 

Method Parameters Description
GetServiceStatus   Test connectivity to the Rest API and get the Service STatus
GetServerTime   Test connectivity to the Rest API and get the current server time.

 

 

Market Data EndPoints

 

Method Parameters Description
GetSymbolList Market Request via this endpoint to get a list of available currency pairs for trading. If you want to get the market information of the trading symbol
GetTicker Symbol Request via this endpoint to get Level 1 Market Data. The returned value includes the best bid price and size, the best ask price and size as well as the last traded price and the last traded size.
GetAllTickers   Request market tickers for all the trading pairs in the market (including 24h volume).
Get24hrStats Symbol Request via this endpoint to get the statistics of the specified ticker in the last 24 hours.
GetMarketList   Request via this endpoint to get the transaction currency for the entire trading market.
GetPartOrderBook20 Symbol Request via this endpoint to get a list of open orders for a symbol. Level-2 order book includes all bids and asks (aggregated by price), this level returns only one size for each active price (as if there was only a single order for that price). The system will return you 20 pieces of data (ask and bid data) on the order book.
GetPartOrderBook100 Symbol Request via this endpoint to get a list of open orders for a symbol. Level-2 order book includes all bids and asks (aggregated by price), this level returns only one size for each active price (as if there was only a single order for that price). The system will return you 100 pieces of data (ask and bid data) on the order book.
GetFullOrderBook Symbol Request via this endpoint to get the order book of the specified symbol. Level 2 order book includes all bids and asks (aggregated by price). This level returns only one aggregated size for each price (as if there was only one single order for that price). This API will return data with full depth.
GetKLines Symbol Request via this endpoint to get the kline of the specified symbol. Data are returned in grouped buckets based on requested type.
GetCurrencies   Request via this endpoint to get the currency list.
GetCurrencyDetail Currency Request via this endpoint to get the currency details of a specified currency
GetFiatPrice   Request via this endpoint to get the currency details of a specified currency

 

 

 

Private API EndPoints

 

Requires an APIKey and APISecret to get authorized by server.

 

User EndPoints

 

Method Parameters Description
GetAllSubAccounts   You can get the user info of all sub-users via this interface.
GetListAccounts   Get a list of accounts.
GetAccount AccountId Information for a single account. Use this endpoint when you know the accountId.
GetAccountBalanceSubAccount SubUserId This endpoint returns the account info of a sub-user specified by the subUserId.
InnerTransfer   This API endpoint can be used to transfer funds between accounts internally. Users can transfer funds between their main account, trading account, cross margin account, and isolated margin account free of charge. Transfer of funds from the main account, cross margin account, and trading account to the futures account is supported, but transfer of funds from futures accounts to other accounts is not supported.

 

 

Withdraw EndPoints

 

Method Parameters Description
GetWithdrawalsList   Get a list of the Withdrawals.
GetHistoricalWithdrawalsList   List of KuCoin V1 historical withdrawals.
GetWithdrawalsQuotas Currency Get Withdrawals Quotas
ApplyWithdraw Currency, Address, Amount Create a Withdraw
CancelWithdraw WithdrawalId Only withdrawals requests of PROCESSING status could be canceled.

 

 

Trade Endpoints

 

Method Parameters Description
PlaceOrder   You can place two types of orders: limit and market. Orders can only be placed if your account has sufficient funds. Once an order is placed, your account funds will be put on hold for the duration of the order. How much and which funds are put on hold depends on the order type and parameters specified
PlaceMarketOrder   Places a Market Order.
PlaceLimitOrder   Places a Limit Order.
PlaceMarginOrder   Places a Margin Order.
CancelOrder   Cancels an Order by Order Id.
CancelOrderByClientOid   Cancels an Order by Client Order Id.
CancelAllOrders   Cancel all open orders.
ListOrders   Request via this endpoint to get your current order list. Items are paginated and sorted to show the latest first
GetRecentOrders   Request via this endpoint to get 1000 orders in the last 24 hours.
GetOrder   Request via this endpoint to get a single order info by order ID.
GetOrderByClientOid   Request via this endpoint to get a single order info by Client order ID.
ListFills   Request via this endpoint to get the recent fills.
GetRecentFills   Request via this endpoint to get a list of 1000 fills in the last 24 hours.
PlaceStopOrder   Places a Stop Order.
PlaceStopMarketOrder   Places a Stop Market Order.
PlaceStopLimitOrder   Places a Stop Limit Order.
CancelStopOrder   Cancels a Open Stop Order by Order Id
CancelStopOrderByClientOid   Cancels a Open Stop Order by Client Order Id
CancelAllStopOrders   Cancel All Stop Orders
GetStopOrder   Request via this interface to get a stop order information via the order ID.
GetStopOrderByClientOid   Request via this interface to get a stop order information via the Client order ID.
ListStopOrders   Request via this endpoint to get your current untriggered stop order list. Items are paginated and sorted to show the latest first.

 

 

Events

Kucoin Messages are received in TsgcWebSocketClient component, you can use the following events:

 

OnConnect

After a successful connection to Kucoin server.

OnDisconnect

After a disconnection from Kucoin server

OnMessage

Messages sent by server to client are handled in this event.

OnError

If there is any error in protocol, this event will be called.

OnException

If there is an unhandled exception, this event will be called.

 

Additionally, there is a specific event in Kucoin API Component, called OnKucoinHTTPException, which is raised every time there is an error calling an HTTP Request (REST API or WebSocket Feeds).