kucoin-api
Version:
Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.
419 lines • 15.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnifiedAPIClient = void 0;
const BaseRestClient_js_1 = require("./lib/BaseRestClient.js");
const requestUtils_js_1 = require("./lib/requestUtils.js");
/**
* Unified Trading Account Client
*
* This client provides access to the Unified Trading Account API endpoints
* that unify market data access across Spot, Futures, and Margin trading.
*/
class UnifiedAPIClient extends BaseRestClient_js_1.BaseRestClient {
getClientType() {
return requestUtils_js_1.REST_CLIENT_TYPE_ENUM.unifiedTradingAccount;
}
/**
*
* REST - Unified Trading Account - Market Data
*
*/
/**
* Get Announcements
* This interface can obtain the latest news announcements, and the default
* page search is for announcements within a month.
*/
getAnnouncements(params) {
return this.get('api/ua/v1/market/announcement', params);
}
/**
* Get Currency
* Request the currency details of a specified currency via this endpoint.
*/
getCurrency(params) {
return this.get('api/ua/v1/market/currency', params);
}
/**
* Get Third-Party Custody Currencies
* Query settlement currencies supported by third-party (OES) custodian institutions.
*/
getThirdPartyCustodyCurrencies(params) {
return this.get('api/ua/v1/oes/currency', params);
}
/**
* Get Symbol
* Request a list of available currency pairs for trading via this endpoint.
*/
getSymbols(params) {
return this.get('api/ua/v1/market/instrument', params);
}
/**
* Get Ticker
* Request market tickers for the trading pairs in the market (including 24h volume).
*/
getTickers(params) {
return this.get('api/ua/v1/market/ticker', params);
}
/**
* Get Trades
* Request via this endpoint to get the latest 100 public trades of the specified symbol.
*/
getTrades(params) {
return this.get('api/ua/v1/market/trade', params);
}
/**
* Get OrderBook
* Query order book depth information (aggregated by price).
*/
getOrderBook(params) {
return this.get('api/ua/v1/market/orderbook', params);
}
/**
* Get Klines
* Get the Kline of the symbol. Data are returned in grouped buckets based on requested type.
*/
getKlines(params) {
return this.get('api/ua/v1/market/kline', params);
}
/**
* Get Current Funding Rate
* Get current Futures funding fee rate.
*/
getCurrentFundingRate(params) {
return this.get('api/ua/v1/market/funding-rate', params);
}
/**
* Get History Funding Rate
* Query the Futures funding rate at each settlement time point within a certain time range.
*/
getHistoryFundingRate(params) {
return this.get('api/ua/v1/market/funding-rate-history', params);
}
/**
* Get Cross Margin Config
* Request the configure info of the 'spot cross margin' via this endpoint.
*/
getCrossMarginConfig() {
return this.get('api/ua/v1/market/cross-config');
}
/**
* Get Borrowable Currencies
* List of borrowable currencies (UTA / public).
*/
getBorrowableCurrencies() {
return this.get('api/ua/v1/market/borrowable-currency');
}
/**
* Get Service Status
* Get the service status.
*/
getServiceStatus(params) {
return this.get('api/ua/v1/server/status', params);
}
/**
*
* REST - Unified Trading Account - Account
*
*/
/**
* Get Account (Classic)
* Get information for Classic Account (FUNDING, SPOT, FUTURES, CROSS, ISOLATED).
* Note: AccountType enum value changed from TRADING to SPOT as of 2026.01.17.
*/
getClassicAccount(params) {
return this.getPrivate('api/ua/v1/account/balance', params);
}
/**
* Get Account (UTA)
* Get information for Unified Trading Account.
*/
getAccount() {
return this.getPrivate('api/ua/v1/unified/account/balance');
}
/**
* Get Account Overview (UTA)
* Get account overview for Unified Trading Account.
*/
getAccountOverview() {
return this.getPrivate('api/ua/v1/unified/account/overview');
}
/**
* Get Sub Account
* Request sub account info via this endpoint.
*/
getSubAccount(params) {
return this.getPrivate('api/ua/v1/sub-account/balance', params);
}
/**
* Get Transfer Quotas
* This endpoint returns the transferable balance of a specified account.
* Note: AccountType enum value changed from TRADING to SPOT as of 2026.01.17.
*/
getTransferQuotas(params) {
return this.getPrivate('api/ua/v1/account/transfer-quota', params);
}
/**
* Flex Transfer
* This interface can be used for transfers between master- and sub-accounts and transfers.
* Note: AccountType enum value changed from TRADING to SPOT as of 2026.01.17.
*/
flexTransfer(params) {
return this.postPrivate('api/ua/v1/account/transfer', params);
}
/**
* Set Sub Account Transfer Permission
* This endpoint supports setting whether the specified sub-account needs to open the SUB_TO_SUB transfer permission.
*/
setSubAccountTransferPermission(params) {
return this.postPrivate('api/ua/v1/sub-account/canTransferOut', params);
}
/**
* Get Account Mode
* This interface supports query the list of unified and classic sub-accounts and current account mode.
*/
getAccountMode() {
return this.getPrivate('api/ua/v1/account/mode');
}
/**
* Set Account Mode
* This interface supports set account mode to UTA.
*/
setAccountMode(params) {
return this.postPrivate('api/ua/v1/account/mode', params);
}
/**
* Get Fee Rate
* This interface is for the trading pair's actual fee rate.
* You can inquire about fee rates of 10 trading pairs each time at most for Spot.
* Futures only supports 1 symbol at a time.
*/
getFeeRate(params) {
return this.getPrivate('api/ua/v1/user/fee-rate', params);
}
/**
* Get Account Ledger
* This API endpoint returns all transfer (in and out) records and supports multi-coin queries.
* The query results are sorted in descending order by createdAt and ID.
* Note: AccountType enum value changed from TRADING to SPOT as of 2026.01.17.
* Note: direction values unified to uppercase IN/OUT as of 2026.01.17.
* Note: For Futures - id changed from Number to String, balance/amount changed from Number to String as of 2026.01.17.
* Note: ts standardized to nanoseconds as of 2026.01.12.
*/
getAccountLedger(params) {
return this.getPrivate('api/ua/v1/account/ledger', params);
}
/**
* Get Interest History (UTA)
* Request the interest records via this endpoint.
*/
getInterestHistory(params) {
return this.getPrivate('api/ua/v1/account/interest-history', params);
}
/**
* Get Borrowing Rates and Limits
* Hourly/daily rates and borrow limits (UTA).
*/
getBorrowingRatesAndLimits(params) {
return this.getPrivate('api/ua/v1/account/interest-limits', params);
}
/**
* Modify Leverage (UTA)
* This interface supports modify leverage of the specified symbol.
*/
modifyLeverage(params) {
return this.postPrivate('api/ua/v1/unified/account/modify-leverage', params);
}
/**
* Modify Leverage Margin Cross (UTA)
* Update leverage for a currency in UTA cross margin.
*/
modifyMarginCrossLeverage(params, accountMode = 'unified') {
return this.postPrivate(`api/ua/v1/${accountMode}/account/modify-leverage-margin-cross`, params);
}
/**
* Get Leverage (UTA)
* Query leverage for MARGIN (currency) or FUTURES (symbol).
*/
getLeverage(params) {
return this.getPrivate('api/ua/v1/unified/account/leverage', params);
}
/**
* Get Deposit Address
* Return a deposit address; when both currency and chain are provided,
* the address will be created if it does not exist.
* URL unified to GET /api/ua/v1/asset/deposit/address as of 2026.01.17.
*/
getDepositAddress(params) {
return this.getPrivate('api/ua/v1/asset/deposit/address', params);
}
/**
* Get Third-Party Custody Account Currency Limits
* OES remaining custody quota per custodian and settlement currency.
*/
getThirdPartyCustodyQuota(params) {
return this.getPrivate('api/ua/v1/oes/custody-quota', params);
}
/**
*
* REST - Unified Trading Account - Orders
*
*/
/**
* Place Order
* This interface can be used to place orders.
* Supports RPI (Retail Price Improvement) orders for Futures as of 2025.01.02.
* Note: timeInForce supports 'RPI' value for Futures only (Phase 1).
* Note: For Classic mode, tradeType is required in query param.
* Note: For Unified mode, tradeType is sent in the request body (incl. MARGIN as of 2026.04.19).
*/
placeOrder(params, accountMode = 'unified') {
const { tradeType, ...bodyParams } = params;
const url = accountMode === 'classic'
? `api/ua/v1/${accountMode}/order/place?tradeType=${tradeType}`
: `api/ua/v1/${accountMode}/order/place`;
if (accountMode === 'unified') {
return this.postPrivate(url, { ...bodyParams, tradeType });
}
return this.postPrivate(url, bodyParams);
}
/**
* Batch Place Order (Classic)
* This interface can be used for placing batch orders.
* URL changed to /api/ua/v1/{accountMode}/order/place-batch as of 2026.01.17.
* Note: timeInForce supports 'RPI' value for Futures as of 2025.01.02.
*/
batchPlaceOrder(params, accountMode = 'classic') {
const url = accountMode === 'classic'
? `api/ua/v1/${accountMode}/order/place-batch?tradeType=${params.tradeType}`
: `api/ua/v1/${accountMode}/order/place-batch`;
return this.postPrivate(url, params);
}
/**
* Get Order Details
* This interface can be used getting single order details.
* Note: timeInForce returns 'RPI' value for Futures RPI orders as of 2025.01.02.
* Note: status changed from String to Number for UTA as of 2026.01.17.
* Note: orderTime/updatedTime standardized to nanoseconds as of 2026.01.12.
*/
getOrderDetails(params, accountMode = 'unified') {
return this.getPrivate(`api/ua/v1/${accountMode}/order/detail`, params);
}
/**
* Get Open Order List
* This interface can be used getting open order list.
* Note: timeInForce returns 'RPI' value for Futures RPI orders as of 2025.01.02.
* Note: status changed from String to Number for UTA as of 2026.01.17.
* Note: orderTime/updatedTime standardized to nanoseconds as of 2026.01.12.
*/
getOpenOrderList(params, accountMode = 'unified') {
return this.getPrivate(`api/ua/v1/${accountMode}/order/open-list`, params);
}
/**
* Get Order History
* This interface can be used for getting order history.
* Note: timeInForce returns 'RPI' value for Futures RPI orders as of 2025.01.02.
* Note: status changed from String to Number for UTA as of 2026.01.17.
* Note: orderTime/updatedTime standardized to nanoseconds as of 2026.01.12.
*/
getOrderHistory(params, accountMode = 'unified') {
return this.getPrivate(`api/ua/v1/${accountMode}/order/history`, params);
}
/**
* Get Trade History
* This interface can be used for getting trade execution history.
* Note: executionTime standardized to nanoseconds as of 2026.01.12.
* Note: isRpiTrade added for Futures as of 2025.01.02.
*/
getTradeHistory(params, accountMode = 'unified') {
return this.getPrivate(`api/ua/v1/${accountMode}/order/execution`, params);
}
/**
* Cancel Order
* This interface can be used to cancel orders.
* Note: ts (timestamp in nanoseconds) only effective for unified account mode.
*/
cancelOrder(params, accountMode = 'unified') {
const url = accountMode === 'classic'
? `api/ua/v1/${accountMode}/order/cancel?tradeType=${params.tradeType}`
: `api/ua/v1/${accountMode}/order/cancel`;
return this.postPrivate(url, params);
}
/**
* Batch Cancel Orders
* This interface can be used for batch cancel orders (maximum 20 orders).
* Note: tradeType required for Classic accounts only; ignored in UTA (UNIFIED) mode.
* Note: ts (timestamp in nanoseconds) not supported for classic accounts.
*/
batchCancelOrders(params, accountMode = 'unified') {
const url = accountMode === 'classic'
? `api/ua/v1/${accountMode}/order/cancel-batch?tradeType=${params.tradeType}`
: `api/ua/v1/${accountMode}/order/cancel-batch`;
return this.postPrivate(url, params);
}
/**
* Batch Cancel Orders By Symbol
* Cancels orders in batch by symbol. UTA only. Supports SPOT (non-margin) and Futures Cross Margin.
*/
batchCancelOrdersBySymbol(params) {
return this.postPrivate('api/ua/v1/unified/order/cancel-all', params);
}
/**
* Set DCP (Disconnection Protect / Deadman Switch) - Classic Only
* Set automatic order cancellation after specified time.
* Call this interface to automatically cancel all orders of the set trading pair after the specified time.
* Note: Order cancellation delay is between 0 and 10 seconds.
* Note: timeout range: -1 (unset) or 5 <= timeout <= 86400 seconds.
*/
setDCP(params) {
return this.postPrivate('api/ua/v1/dcp/set', params);
}
/**
* Get DCP (Disconnection Protect / Deadman Switch) - Classic Only
* Get automatic order cancellation settings.
* If data is empty, it means DCP is not set.
*/
getDCP(params) {
return this.getPrivate('api/ua/v1/dcp/query', params);
}
/**
*
* REST - Unified Trading Account - Positions
*
*/
/**
* Get Position List (UTA)
* Get the position details of all open positions.
* Note: creationTime standardized to nanoseconds as of 2026.01.12.
* Note: pageNumber, pageSize query params and liquidationPrice in each position (as of 2026.04.09).
*/
getPositionList(params) {
return this.getPrivate('api/ua/v1/unified/position/open-list', params);
}
/**
* Get Positions History (UTA)
* Query position history information records.
* Note: Data retained for up to 3 months.
* Note: Each query limited to 7 days time range.
* Note: creationTime and closingTime standardized to nanoseconds as of 2026.01.12.
*/
getPositionsHistory(params) {
return this.getPrivate('api/ua/v1/position/history', params);
}
/**
* Get Private Funding Fee History
* Settled funding fee records for the current account.
*/
getPrivateFundingFeeHistory(params) {
return this.getPrivate('api/ua/v1/position/funding-history', params);
}
/**
* Get Account Position Tiers
* Request account position tiers (risk limit) info.
* Note: Currently only queries of classic - futures isolated margin are supported.
*/
getAccountPositionTiers(params, accountMode = 'classic') {
return this.getPrivate(`api/ua/v1/${accountMode}/position/tiers`, params);
}
}
exports.UnifiedAPIClient = UnifiedAPIClient;
//# sourceMappingURL=UnifiedAPIClient.js.map