- KuCoin Futures Node SDK
// Install by npm
npm install kucoin-futures-node-sdk
// Install by yarn
yarn add kucoin-futures-node-sdk
/** Require SDK */
const KuCoinFutures = require('kucoin-futures-node-sdk').default;
const futuresSDK = new KuCoinFutures({
key: '', // KC-API-KEY
secret: '', // API-Secret
passphrase: '', // KC-API-PASSPHRASE
axiosProps: { // optional
env: 'prod', // default prod
version: '2' // default version 2
}
});
// Get Account Detail
futuresSDK.futuresAccount('XBT', console.log);
// Get All Accounts Balance
futuresSDK.futuresAccountOverview('XBT', console.log);
futuresSDK.futuresTransactionHistory(
{
startTime: new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
endTime: new Date().getTime(),
type: 'RealisedPNL',
maxCount: 100,
currency: 'XBT'
},
console.log
);
futuresSDK.futuresSubApi({ subName: '' }, console.log);
futuresSDK.futuresCreateSubApi(
{
subName: '[subName]',
passphrase: '[passphrase]',
remark: '[remark]'
},
console.log
);
futuresSDK.futuresUpdateSubApi(
{
subName: '[subName]',
passphrase: '[passphrase]',
apiKey: '[apiKey]'
},
console.log
);
futuresSDK.futureDeleteSubApi(
{
subName: '[subName]',
passphrase: '[passphrase]',
apiKey: '[apiKey]'
},
console.log
);
futuresSDK.futureTransferOut(
{ amount: 0.01, currency: 'USDT', recAccountType: 'MAIN' },
console.log
);
futuresSDK.futureTransferIn(
{ amount: 0.01, currency: 'USDT', payAccountType: 'MAIN' },
console.log
);
futuresSDK.futureTransfers(
{
startAt: new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
endAt: new Date().getTime(),
status: 'SUCCESS',
currentPage: 1,
pageSize: 100,
currency: 'USDT'
},
console.log
);
// Place an Order
// symbol, price, size, leverage = 1, clientOid = uuidV4(), optional
// Buy Limit Order
futuresSDK.futuresBuy(
{
symbol: 'ETHUSDTM',
price: 10000,
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
// Buy Market Order
futuresSDK.futuresBuy(
{
symbol: 'ETHUSDTM',
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
// Buy Stop Order
futuresSDK.futuresBuy(
{
symbol: 'ETHUSDTM',
price: 10000,
leverage: 5,
size: 1,
// clientOid: uuidV4(),
optional: {
stop: 'up',
stopPriceType: 'TP',
stopPrice: '10000'
// ...
}
},
console.log
);
// Sell Order
// futuresSDK.futuresBuy -> futuresSDK.futuresSell
futuresSDK.futuresSell(
{
symbol: 'ETHUSDTM',
price: 20000,
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
// Cancel an Order
futuresSDK.futuresCancel('orderId', console.log);
// Cancel All Order for Symbol
// limit order
futuresSDK.futuresCancelAllOpenOrders('ETHUSDTM', console.log);
// stop order
futuresSDK.futuresCancelAllStopOrders('ETHUSDTM', console.log);
// or cancelAll limit/stop order for symbol
futuresSDK.futuresCancelAll('ETHUSDTM', console.log);
// Cancel Order by clientOid
futuresSDK.futuresCancelOrderByClientOid({
symbol: '[symbol]',
clientOid: '[clientOid]',
}, console.log);
// Get Order List
futuresSDK.futuresOpenOrders({ status: 'active' }, console.log);
// Get Untriggered Stop Order List
futuresSDK.futuresStopOrders({ type: 'limit' }, console.log);
// Get List of Orders Completed in 24h
futuresSDK.futuresRecentDoneOrders('ETHUSDTM', console.log);
// Or Search All
futuresSDK.futuresRecentDoneOrders('', console.log);
// Get Details of a Single Order
futuresSDK.futuresOrderDetail({ clientOid: 'clientOid' }, console.log);
// Or By OrderId
futuresSDK.futuresOrderDetail('orderId', console.log);
Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
// Place Order Test
// symbol, price, size, leverage = 1, clientOid = uuidV4(), optional
// Buy Limit Order
futuresSDK.futuresBuyTest(
{
symbol: 'ETHUSDTM',
price: 10000,
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
// Buy Market Order
futuresSDK.futuresBuyTest(
{
symbol: 'ETHUSDTM',
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
// Buy Stop Order
futuresSDK.futuresBuyTest(
{
symbol: 'ETHUSDTM',
price: 10000,
leverage: 5,
size: 1,
// clientOid: uuidV4(),
optional: {
stop: 'up',
stopPriceType: 'TP',
stopPrice: '10000'
// ...
}
},
console.log
);
// Sell Order
// futuresSDK.futuresBuyTest -> futuresSDK.futuresSellTest
futuresSDK.futuresSellTest(
{
symbol: 'ETHUSDTM',
price: 20000,
leverage: 5,
size: 1
// clientOid: uuidV4(),
},
console.log
);
//request
[
{
"clientOid":"5c52e11203aa677f33e491",
"side":"buy",
"symbol":"ETHUSDTM",
"type":"limit",
"price":"2150",
"size":"2"
},
{
"clientOid":"5c52e11203aa677f33e492",
"side":"buy",
"symbol":"XBTUSDTM",
"type":"limit",
"price":"32150",
"size":"2"
}
]
//Response
[
{
"orderId":"80465574458560512",
"clientOid":"5c52e11203aa677f33e491",
"symbol":"ETHUSDTM",
"code":"200000",
"msg":"success"
},
{
"orderId":"80465575289094144",
"clientOid":"5c52e11203aa677f33e492",
"symbol":"ETHUSDTM",
"code":"200000",
"msg":"success"
}
]
futuresSDK.futuresOrderMulti([...], console.log);
// Get Fills
futuresSDK.futuresFills({ pageSize: 100 }, console.log);
// Recent Fills
futuresSDK.futuresRecentFills('ETHUSDTM', console.log);
// Or Search All
futuresSDK.futuresRecentFills('', console.log);
// Active Order Value Calculation
futuresSDK.futuresMarginOpenOrders('ETHUSDTM', console.log);
// Get Position Details
futuresSDK.futuresPositionDetail('ETHUSDTM', console.log);
// Get Position List
futuresSDK.futuresPositions('USDT', console.log);
// Or Search All
futuresSDK.futuresPositions('', console.log);
// Enable of Auto-Deposit Margin
futuresSDK.futuresPositionAutoDeposit(
{ symbol: 'ETHUSDTM', status: true },
console.log
);
// Disable of Auto-Deposit Margin
futuresSDK.futuresPositionAutoDeposit(
{ symbol: 'ETHUSDTM', status: false },
console.log
);
// Add Margin Manually
// bizNo default uuidV4()
futuresSDK.futuresPositionMargin(
{
symbol: 'ETHUSDTM',
margin: 0.01
// bizNo: uuidV4(),
},
console.log
);
// Obtain Futures Risk Limit Level
futuresSDK.futuresRiskLimit('ETHUSDTM', console.log);
// Adjust Risk Limit Level
futuresSDK.futuresChangeRiskLimit(
{ symbol: 'ETHUSDTM', level: 2 },
console.log
);
// Get Current Funding Rate
futuresSDK.futuresFundingRate('XBTUSDM', console.log);
// Get Public Funding History
futuresSDK.futuresFundingRates({
symbol: 'XBTUSDTM',
from: '1700310700000',
to: '1702310700000',
}, console.log);
// Get Private Funding History
futuresSDK.futuresFundingHistory({ symbol: 'ETHUSDTM' }, console.log);
futuresSDK.futuresContractsActive(console.log);
futuresSDK.futuresContractDetail('XBTUSDTM', console.log);
futuresSDK.futuresTicker('XBTUSDTM', console.log);
futuresSDK.futuresLevel2('XBTUSDTM', console.log);
// Get Level2 depth20
futuresSDK.futuresLevel2Depth20('XBTUSDTM', console.log);
// Get Level2 depth100
futuresSDK.futuresLevel2Depth100('XBTUSDTM', console.log);
futuresSDK.futuresTradeHistory('XBTUSDTM', console.log);
// Get Interest Rate List
futuresSDK.futuresInterests({ symbol: '.XBTINT' }, console.log);
// Get Index List
futuresSDK.futuresIndexList({ symbol: '.KXBT' }, console.log);
// Get Current Mark Price
futuresSDK.futuresMarkPrice('XBTUSDM', console.log);
// Get Premium Index
futuresSDK.futuresPremiums({ symbol: '.XBTUSDMPI' }, console.log);
futuresSDK.futuresTimestamp(console.log);
futuresSDK.futuresStatus(console.log);
futuresSDK.futuresKline(
{
symbol: 'XBTUSDTM',
granularity: 480,
from: new Date().getTime() - 24 * 60 * 60 * 1000,
to: new Date().getTime()
},
console.log
);
// need auth
futuresSDK.futuresTradeStatistics(console.log);
- Socket implements 59s heartbeat, disconnection retry mechanism
- When calling the provided websocket.x method, the system will create a corresponding socket connection channel based on public or private, and only one connection will be created for each type
- Parameters pass symbols, support passing arrays, and push symbol messages in the arrays
- When the parameter is an array, the length of the array will be automatically cut according to the length of 90
All methods that pass symbols support array format The first parameter is symbol and the second parameter is callback. When the parameter does not exist, the first parameter is callback
//
// Get Real-Time Symbol Ticker v2
futuresSDK.websocket.tickerV2(['ETHUSDTM', 'XBTUSDTM'], console.log);
// Or
futuresSDK.websocket.tickerV2('ETHUSDTM', console.log);
// Get Real-Time Symbol Ticker
futuresSDK.websocket.ticker(['ETHUSDTM', 'XBTUSDTM']);
// Level 2 Market Data
futuresSDK.websocket.level2(['ETHUSDTM', 'XBTUSDTM']);
// Execution data
futuresSDK.websocket.execution(['ETHUSDTM', 'XBTUSDTM']);
// Message channel for the 5 best ask/bid full data of Level 2
futuresSDK.websocket.level2Depth5(['ETHUSDTM', 'XBTUSDTM']);
// Message channel for the 50 best ask/bid full data of Level 2
futuresSDK.websocket.level2Depth50(['ETHUSDTM', 'XBTUSDTM']);
// Contract Market Data
// subject --> "mark.index.price" return Mark Price & Index Price
// subject --> "funding.rate" return Funding Rate
futuresSDK.websocket.instrument(['ETHUSDTM', 'XBTUSDTM']);
// Funding Fee Settlement
// subject --> "funding.begin" return Start Funding Fee Settlement
// subject --> "funding.end" return End Funding Fee Settlement
futuresSDK.websocket.announcement(console.log);
// Transaction Statistics Timer Event
futuresSDK.websocket.snapshot(['ETHUSDTM', 'XBTUSDTM']);
// Trade Orders - According To The Market
futuresSDK.websocket.tradeOrders(['ETHUSDTM', 'XBTUSDTM'], console.log);
// Or
futuresSDK.websocket.tradeOrders(console.log);
// Stop Order Lifecycle Event
futuresSDK.websocket.advancedOrders(console.log);
// Account Balance Events
// subject --> "orderMargin.change" return Order Margin Event
// subject --> "availableBalance.change" return Available Balance Event
// subject --> "withdrawHold.change" return Withdrawal Amount & Transfer-Out Amount Event
futuresSDK.websocket.wallet(console.log);
// Position Change Events
// subject --> "position.change" return Position Changes Caused Operations
// Position Changes Caused Operations
// -- “marginChange”: margin change;
// -- “positionChange”: position change;
// -- “liquidation”: liquidation;
// -- “autoAppendMarginStatusChange”: auto-deposit-status change;
// -- “adl”: adl;
// Position Changes Caused by Mark Price
// subject --> "position.settlement" return Funding Settlement
futuresSDK.websocket.position(['ETHUSDTM', 'XBTUSDTM']);