Skip to content

Commit

Permalink
Merge pull request #23 from Apexrsq/feature/supply-interface
Browse files Browse the repository at this point in the history
feat: add reset interface
  • Loading branch information
GannicusZhou authored Jan 12, 2024
2 parents 578deec + 653f8b0 commit 9796650
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 46 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# KuCoin Futures Node SDK

[![KuCoin Futures Node SDK](https://docs.kucoin.com/futures/images/logo_en.svg)](https://docs.kucoin.com/futures/#introduction)
[KuCoin Futures Node SDK](https://docs.kucoin.com/futures/#introduction)
[![Latest Version](https://img.shields.io/github/release/Kucoin/kucoin-futures-node-sdk.svg?style=flat-square)](https://github.com/Kucoin/kucoin-futures-node-sdk/releases)

- [KuCoin Futures Node SDK](#kucoin-futures-node-sdk)
Expand Down Expand Up @@ -35,6 +35,7 @@
- [Server Time](#server-time)
- [Server Status](#server-status)
- [Get K Line Data of Contract](#get-k-line-data-of-contract)
- [Get 24hour futures transaction volume](#get-24hour-futures-transaction-volume)
- [WebSocket](#websocket)
- [Public Channels](#public-channels)
- [Private Channels](#private-channels)
Expand Down Expand Up @@ -256,6 +257,12 @@ 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);

Expand Down Expand Up @@ -338,6 +345,17 @@ futuresSDK.futuresChangeRiskLimit(
#### Funding Fees

```js
// 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);
```

Expand Down Expand Up @@ -399,9 +417,6 @@ futuresSDK.futuresMarkPrice('XBTUSDM', console.log);

// Get Premium Index
futuresSDK.futuresPremiums({ symbol: '.XBTUSDMPI' }, console.log);

// Get Current Funding Rate
futuresSDK.futuresFundingRate('XBTUSDM', console.log);
```

#### Server Time
Expand Down Expand Up @@ -430,6 +445,13 @@ futuresSDK.futuresKline(
);
```

#### Get 24hour futures transaction volume

```js
// need auth
futuresSDK.futuresTradeStatistics(console.log);
```

---

## WebSocket
Expand Down
38 changes: 27 additions & 11 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ futuresSDK.futuresStatus(console.log);

// futuresSDK.futuresAccount('USDT', console.log);

futuresSDK.futuresAccountOverview('USDT', console.log);
// futuresSDK.futuresAccountOverview('USDT', console.log);

// futuresSDK.futuresBuy(
// {
Expand All @@ -32,17 +32,17 @@ futuresSDK.futuresAccountOverview('USDT', console.log);
// futuresSDK.futuresSell(
// {
// symbol: 'ETHUSDTM',
// price: 20000,
// leverage: 5,
// price: 3000,
// leverage: 15,
// size: 1,
// // clientOid: uuidV4(),
// optional: {
// remark: 'test',
// stop: 'up',
// stopPriceType: 'TP',
// stopPrice: '20000',
// // ...
// }
// // optional: {
// // remark: 'test',
// // stop: 'up',
// // stopPriceType: 'TP',
// // stopPrice: '20000',
// // // ...
// // }
// },
// console.log
// );
Expand All @@ -55,7 +55,15 @@ futuresSDK.futuresAccountOverview('USDT', console.log);

// futuresSDK.futuresCancelAll('ETHUSDTM', console.log);

// futuresSDK.futuresOpenOrders({ status: 'done' }, console.log);
// futuresSDK.futuresCancelOrderByClientOid(
// 'ETHUSDTM',
// 'clientId',
// console.log
// );

// futuresSDK.futuresOpenOrders({ status: 'active' }, (data) =>
// console.log(JSON.stringify(data))
// );

// futuresSDK.futuresStopOrders({ type: 'market' }, console.log);

Expand Down Expand Up @@ -179,6 +187,14 @@ futuresSDK.futuresAccountOverview('USDT', console.log);
// console.log
// );

// futuresSDK.futuresFundingRates({
// symbol: 'XBTUSDTM',
// from: '1700310700000',
// to: '1702310700000',
// }, console.log);

// futuresSDK.futuresTradeStatistics(console.log);

// === websocket === //

// futuresSDK.websocket.ticker(['ETHUSDTM', 'XBTUSDTM']);
Expand Down
5 changes: 5 additions & 0 deletions lib/dataType/other.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export interface FundingHistoryParams extends PageOffsetParams {
symbol: string;
reverse?: boolean | true;
}
export interface FundingRatesParams {
symbol: string;
startAt: string;
endAt: string;
}
14 changes: 12 additions & 2 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback } from './dataType';
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams } from './dataType';
import { WebSocketClient } from './websocket';
export default class KuCoinFutures {
private request;
Expand Down Expand Up @@ -79,6 +79,7 @@ export default class KuCoinFutures {
futuresCancelAllOpenOrders: (symbol?: string, callback?: Function) => Promise<any>;
futuresCancelAllStopOrders: (symbol?: string, callback?: Function) => Promise<any>;
futuresCancelAll: (symbol?: string, callback?: Function) => Promise<[any, any]>;
futuresCancelOrderByClientOid: (symbol: string, clientOid: string, callback?: Function) => Promise<any>;
/**
* search to open orders list
* @param params.status --'active'|'done' default 'active'
Expand Down Expand Up @@ -154,6 +155,15 @@ export default class KuCoinFutures {
* @param callback -- callback function
*/
futuresFundingHistory: (params?: FundingHistoryParams, callback?: Function) => Promise<any>;
/**
* search to stop orders list
* @param params.symbol -- string symbol
* @param params.startAt -- timestamp
* @param params.endAt -- timestamp
* @param callback -- callback function
*/
futuresFundingRates: (params?: FundingRatesParams, callback?: Function) => Promise<any>;
futuresFundingRate: (symbol: string, callback?: Function) => Promise<any>;
futuresContractsActive: (callback?: Function) => Promise<any>;
futuresContractDetail: (symbol: string, callback?: Function) => Promise<any>;
futuresTicker: (symbol: string, callback?: Function) => Promise<any>;
Expand All @@ -171,6 +181,7 @@ export default class KuCoinFutures {
* @param params.to -- boolean
*/
futuresKline: (params: klineParams, callback?: Function) => Promise<any>;
futuresTradeStatistics: (callback?: Function) => Promise<any>;
/**
* search to interest list
* @param params.symbol -- string symbol
Expand Down Expand Up @@ -208,7 +219,6 @@ export default class KuCoinFutures {
* @param callback -- callback function
*/
futuresPremiums: (params?: IndexListParams, callback?: Function) => Promise<any>;
futuresFundingRate: (symbol: string, callback?: Function) => Promise<any>;
futuresGetSocketInstance: (isPrivate: boolean) => Promise<WebSocketClient>;
futuresGetCacheSocketInstance: (isPrivate: boolean) => Promise<WebSocketClient>;
futuresSocketSubscribe: (topic: string, callback?: Callback, isPrivate?: boolean, strict?: boolean) => Promise<false | undefined>;
Expand Down
57 changes: 47 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ var KuCoinFutures = /** @class */ (function () {
return [2 /*return*/, Promise.all([cancelAllOpenOrders, cancelAllStopOrders])];
});
}); };
this.futuresCancelOrderByClientOid = function (symbol, clientOid, callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
body: '',
method: constants_1.DELETE,
endpoint: "".concat(resetAPI_1.FUTURES_ORDER_CLIENT_ORDER_EP, "/").concat(clientOid, "?symbol=").concat(symbol),
callback: callback
})];
});
}); };
/**
* search to open orders list
* @param params.status --'active'|'done' default 'active'
Expand Down Expand Up @@ -477,6 +487,34 @@ var KuCoinFutures = /** @class */ (function () {
})];
});
}); };
/**
* search to stop orders list
* @param params.symbol -- string symbol
* @param params.startAt -- timestamp
* @param params.endAt -- timestamp
* @param callback -- callback function
*/
this.futuresFundingRates = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
body: params,
method: constants_1.GET,
endpoint: resetAPI_1.FUTURES_FUNDING_RATES_EP,
callback: callback,
isPrivate: false
})];
});
}); };
this.futuresFundingRate = function (symbol, callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
method: constants_1.GET,
endpoint: "".concat(resetAPI_1.FUTURES_FUNDING_RATE_EP, "/").concat(symbol, "/current"),
callback: callback,
isPrivate: false
})];
});
}); };
this.futuresContractsActive = function (callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
Expand Down Expand Up @@ -594,6 +632,15 @@ var KuCoinFutures = /** @class */ (function () {
})];
});
}); };
this.futuresTradeStatistics = function (callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
method: constants_1.GET,
endpoint: resetAPI_1.FUTURES_TRADE_STATISTICS_EP,
callback: callback
})];
});
}); };
/**
* search to interest list
* @param params.symbol -- string symbol
Expand Down Expand Up @@ -670,16 +717,6 @@ var KuCoinFutures = /** @class */ (function () {
})];
});
}); };
this.futuresFundingRate = function (symbol, callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.makeRequest({
method: constants_1.GET,
endpoint: "".concat(resetAPI_1.FUTURES_FUNDING_RATE_EP, "/").concat(symbol, "/current"),
callback: callback,
isPrivate: false
})];
});
}); };
this.futuresGetSocketInstance = function (isPrivate) { return __awaiter(_this_1, void 0, void 0, function () {
var _a, instanceServers, token, wssUri, websocket, socketInstance;
return __generator(this, function (_b) {
Expand Down
5 changes: 4 additions & 1 deletion lib/resetAPI/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export declare const FUTURES_TRANSFER_LIST_EP = "/api/v1/transfer-list";
export declare const FUTURES_ORDER_EP = "/api/v1/orders";
export declare const FUTURES_STOP_ORDER_EP = "/api/v1/stopOrders";
export declare const FUTURES_RECENT_DONE_ORDERS_EP = "/api/v1/recentDoneOrders";
export declare const FUTURES_ORDER_CLIENT_ORDER_EP = "/api/v1/orders/client-order";
export declare const FUTURES_FILLS_EP = "/api/v1/fills";
export declare const FUTURES_RECENT_FILLS_EP = "/api/v1/recentFills";
export declare const FUTURES_TOTAL_OPEN_ORDERS_MARGIN_EP = "/api/v1/openOrderStatistics";
Expand All @@ -18,7 +19,9 @@ export declare const FUTURES_POSITION_AUTO_DEPOSIT_STATUS_EP = "/api/v1/position
export declare const FUTURES_POSITION_MARGIN_EP = "/api/v1/position/margin/deposit-margin";
export declare const FUTURES_RISK_LIMIT_EP = "/api/v1/contracts/risk-limit";
export declare const FUTURES_CHANGE_RISK_LIMIT_EP = "/api/v1/position/risk-limit-level/change";
export declare const FUTURES_FUNDING_RATE_EP = "/api/v1/funding-rate";
export declare const FUTURES_FUNDING_HISTORY_EP = "/api/v1/funding-history";
export declare const FUTURES_FUNDING_RATES_EP = "/api/v1/contract/funding-rates";
export declare const FUTURES_CONTRACTS_ACTIVE_EP = "/api/v1/contracts/active";
export declare const FUTURES_CONTRACTS_DETAIL_EP = "api/v1/contracts";
export declare const FUTURES_TICKER_EP = "/api/v1/ticker";
Expand All @@ -30,7 +33,7 @@ export declare const FUTURES_INTEREST_EP = "/api/v1/interest/query";
export declare const FUTURES_INDEX_EP = "/api/v1/index/query";
export declare const FUTURES_MARK_PRICE_EP = "/api/v1/mark-price";
export declare const FUTURES_PREMIUM_EP = "/api/v1/premium/query";
export declare const FUTURES_FUNDING_RATE_EP = "/api/v1/funding-rate";
export declare const FUTURES_TIMESTAMP_EP = "/api/v1/timestamp";
export declare const FUTURES_SERVICE_STATUS_EP = "/api/v1/status";
export declare const FUTURES_KLINE_EP = "/api/v1/kline/query";
export declare const FUTURES_TRADE_STATISTICS_EP = "/api/v1/trade-statistics";
10 changes: 7 additions & 3 deletions lib/resetAPI/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FUTURES_KLINE_EP = exports.FUTURES_SERVICE_STATUS_EP = exports.FUTURES_TIMESTAMP_EP = exports.FUTURES_FUNDING_RATE_EP = exports.FUTURES_PREMIUM_EP = exports.FUTURES_MARK_PRICE_EP = exports.FUTURES_INDEX_EP = exports.FUTURES_INTEREST_EP = exports.FUTURES_TRADE_HISTORY_EP = exports.FUTURES_LEVEL2_100_EP = exports.FUTURES_LEVEL2_20_EP = exports.FUTURES_LEVEL2_EP = exports.FUTURES_TICKER_EP = exports.FUTURES_CONTRACTS_DETAIL_EP = exports.FUTURES_CONTRACTS_ACTIVE_EP = exports.FUTURES_FUNDING_HISTORY_EP = exports.FUTURES_CHANGE_RISK_LIMIT_EP = exports.FUTURES_RISK_LIMIT_EP = exports.FUTURES_POSITION_MARGIN_EP = exports.FUTURES_POSITION_AUTO_DEPOSIT_STATUS_EP = exports.FUTURES_POSITIONS_EP = exports.FUTURES_POSITION_EP = exports.FUTURES_TOTAL_OPEN_ORDERS_MARGIN_EP = exports.FUTURES_RECENT_FILLS_EP = exports.FUTURES_FILLS_EP = exports.FUTURES_RECENT_DONE_ORDERS_EP = exports.FUTURES_STOP_ORDER_EP = exports.FUTURES_ORDER_EP = exports.FUTURES_TRANSFER_LIST_EP = exports.FUTURES_TRANSFER_IN_EP = exports.FUTURES_TRANSFER_OUT_EP = exports.FUTURES_UPDATE_SUB_API_EP = exports.FUTURES_SUB_API_EP = exports.FUTURES_TRANSACTION_HISTORY_EP = exports.FUTURES_ACCOUNT_OVERVIEW_ALL_EP = exports.FUTURES_ACCOUNT_OVERVIEW_EP = void 0;
exports.FUTURES_TRADE_STATISTICS_EP = exports.FUTURES_KLINE_EP = exports.FUTURES_SERVICE_STATUS_EP = exports.FUTURES_TIMESTAMP_EP = exports.FUTURES_PREMIUM_EP = exports.FUTURES_MARK_PRICE_EP = exports.FUTURES_INDEX_EP = exports.FUTURES_INTEREST_EP = exports.FUTURES_TRADE_HISTORY_EP = exports.FUTURES_LEVEL2_100_EP = exports.FUTURES_LEVEL2_20_EP = exports.FUTURES_LEVEL2_EP = exports.FUTURES_TICKER_EP = exports.FUTURES_CONTRACTS_DETAIL_EP = exports.FUTURES_CONTRACTS_ACTIVE_EP = exports.FUTURES_FUNDING_RATES_EP = exports.FUTURES_FUNDING_HISTORY_EP = exports.FUTURES_FUNDING_RATE_EP = exports.FUTURES_CHANGE_RISK_LIMIT_EP = exports.FUTURES_RISK_LIMIT_EP = exports.FUTURES_POSITION_MARGIN_EP = exports.FUTURES_POSITION_AUTO_DEPOSIT_STATUS_EP = exports.FUTURES_POSITIONS_EP = exports.FUTURES_POSITION_EP = exports.FUTURES_TOTAL_OPEN_ORDERS_MARGIN_EP = exports.FUTURES_RECENT_FILLS_EP = exports.FUTURES_FILLS_EP = exports.FUTURES_ORDER_CLIENT_ORDER_EP = exports.FUTURES_RECENT_DONE_ORDERS_EP = exports.FUTURES_STOP_ORDER_EP = exports.FUTURES_ORDER_EP = exports.FUTURES_TRANSFER_LIST_EP = exports.FUTURES_TRANSFER_IN_EP = exports.FUTURES_TRANSFER_OUT_EP = exports.FUTURES_UPDATE_SUB_API_EP = exports.FUTURES_SUB_API_EP = exports.FUTURES_TRANSACTION_HISTORY_EP = exports.FUTURES_ACCOUNT_OVERVIEW_ALL_EP = exports.FUTURES_ACCOUNT_OVERVIEW_EP = void 0;
// account endpoint
exports.FUTURES_ACCOUNT_OVERVIEW_EP = '/api/v1/account-overview';
exports.FUTURES_ACCOUNT_OVERVIEW_ALL_EP = '/api/v1/account-overview-all';
Expand All @@ -15,6 +15,7 @@ exports.FUTURES_TRANSFER_LIST_EP = '/api/v1/transfer-list';
exports.FUTURES_ORDER_EP = '/api/v1/orders';
exports.FUTURES_STOP_ORDER_EP = '/api/v1/stopOrders';
exports.FUTURES_RECENT_DONE_ORDERS_EP = '/api/v1/recentDoneOrders';
exports.FUTURES_ORDER_CLIENT_ORDER_EP = '/api/v1/orders/client-order';
// fills endpoint
exports.FUTURES_FILLS_EP = '/api/v1/fills';
exports.FUTURES_RECENT_FILLS_EP = '/api/v1/recentFills';
Expand All @@ -24,10 +25,13 @@ exports.FUTURES_POSITION_EP = '/api/v1/position';
exports.FUTURES_POSITIONS_EP = '/api/v1/positions';
exports.FUTURES_POSITION_AUTO_DEPOSIT_STATUS_EP = '/api/v1/position/margin/auto-deposit-status';
exports.FUTURES_POSITION_MARGIN_EP = '/api/v1/position/margin/deposit-margin';
// other endpoint
// risk limit endpoint
exports.FUTURES_RISK_LIMIT_EP = '/api/v1/contracts/risk-limit';
exports.FUTURES_CHANGE_RISK_LIMIT_EP = '/api/v1/position/risk-limit-level/change';
// funding fees endpoint
exports.FUTURES_FUNDING_RATE_EP = '/api/v1/funding-rate';
exports.FUTURES_FUNDING_HISTORY_EP = '/api/v1/funding-history';
exports.FUTURES_FUNDING_RATES_EP = '/api/v1/contract/funding-rates';
// market endpoint
exports.FUTURES_CONTRACTS_ACTIVE_EP = '/api/v1/contracts/active';
exports.FUTURES_CONTRACTS_DETAIL_EP = 'api/v1/contracts';
Expand All @@ -40,7 +44,7 @@ exports.FUTURES_INTEREST_EP = '/api/v1/interest/query';
exports.FUTURES_INDEX_EP = '/api/v1/index/query';
exports.FUTURES_MARK_PRICE_EP = '/api/v1/mark-price';
exports.FUTURES_PREMIUM_EP = '/api/v1/premium/query';
exports.FUTURES_FUNDING_RATE_EP = '/api/v1/funding-rate';
exports.FUTURES_TIMESTAMP_EP = '/api/v1/timestamp';
exports.FUTURES_SERVICE_STATUS_EP = '/api/v1/status';
exports.FUTURES_KLINE_EP = '/api/v1/kline/query';
exports.FUTURES_TRADE_STATISTICS_EP = '/api/v1/trade-statistics';
6 changes: 6 additions & 0 deletions src/dataType/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ export interface FundingHistoryParams extends PageOffsetParams {
symbol: string;
reverse?: boolean | true; // This parameter functions to judge whether the lookup is forward or not. True means “yes” and False means “no”. This parameter is set as true by default
}

export interface FundingRatesParams {
symbol: string;
startAt: string;
endAt: string;
}
Loading

0 comments on commit 9796650

Please sign in to comment.