Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 58deca8

Browse files
authored
Merge pull request #25 from Apexrsq/feature/supply-interface
feat: add reset interface
2 parents 36a63fc + a0dc9f2 commit 58deca8

File tree

21 files changed

+380
-24
lines changed

21 files changed

+380
-24
lines changed

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- [Get Transfer-Out Request Records](#get-transfer-out-request-records)
2121
- [Trade](#trade)
2222
- [Orders](#orders)
23+
- [Place Order Test](#place-order-test)
24+
- [Place Multiple Orders](#place-multiple-orders)
2325
- [Fills](#fills)
2426
- [Positions](#positions)
2527
- [Risk Limit Level](#risk-limit-level)
@@ -280,6 +282,113 @@ futuresSDK.futuresOrderDetail({ clientOid: 'clientOid' }, console.log);
280282
futuresSDK.futuresOrderDetail('orderId', console.log);
281283
```
282284

285+
##### Place Order Test
286+
> Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
287+
288+
```js
289+
// Place Order Test
290+
// symbol, price, size, leverage = 1, clientOid = uuidV4(), optional
291+
292+
// Buy Limit Order
293+
futuresSDK.futuresBuyTest(
294+
{
295+
symbol: 'ETHUSDTM',
296+
price: 10000,
297+
leverage: 5,
298+
size: 1
299+
// clientOid: uuidV4(),
300+
},
301+
console.log
302+
);
303+
304+
// Buy Market Order
305+
futuresSDK.futuresBuyTest(
306+
{
307+
symbol: 'ETHUSDTM',
308+
leverage: 5,
309+
size: 1
310+
// clientOid: uuidV4(),
311+
},
312+
console.log
313+
);
314+
315+
// Buy Stop Order
316+
futuresSDK.futuresBuyTest(
317+
{
318+
symbol: 'ETHUSDTM',
319+
price: 10000,
320+
leverage: 5,
321+
size: 1,
322+
// clientOid: uuidV4(),
323+
optional: {
324+
stop: 'up',
325+
stopPriceType: 'TP',
326+
stopPrice: '10000'
327+
// ...
328+
}
329+
},
330+
console.log
331+
);
332+
333+
// Sell Order
334+
// futuresSDK.futuresBuyTest -> futuresSDK.futuresSellTest
335+
futuresSDK.futuresSellTest(
336+
{
337+
symbol: 'ETHUSDTM',
338+
price: 20000,
339+
leverage: 5,
340+
size: 1
341+
// clientOid: uuidV4(),
342+
},
343+
console.log
344+
);
345+
```
346+
347+
##### Place Multiple Orders
348+
```js
349+
//request
350+
[
351+
{
352+
"clientOid":"5c52e11203aa677f33e491",
353+
"side":"buy",
354+
"symbol":"ETHUSDTM",
355+
"type":"limit",
356+
"price":"2150",
357+
"size":"2"
358+
},
359+
{
360+
"clientOid":"5c52e11203aa677f33e492",
361+
"side":"buy",
362+
"symbol":"XBTUSDTM",
363+
"type":"limit",
364+
"price":"32150",
365+
"size":"2"
366+
}
367+
]
368+
369+
//Response
370+
[
371+
{
372+
"orderId":"80465574458560512",
373+
"clientOid":"5c52e11203aa677f33e491",
374+
"symbol":"ETHUSDTM",
375+
"code":"200000",
376+
"msg":"success"
377+
},
378+
{
379+
"orderId":"80465575289094144",
380+
"clientOid":"5c52e11203aa677f33e492",
381+
"symbol":"ETHUSDTM",
382+
"code":"200000",
383+
"msg":"success"
384+
}
385+
]
386+
387+
futuresSDK.futuresOrderMulti([...], console.log);
388+
```
389+
390+
391+
283392
#### Fills
284393

285394
```js

example/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const KuCoinFutures = require('../lib/index').default;
2+
// const { v4: uuidV4 } = require('uuid');
23

34
const futuresSDK = new KuCoinFutures({
45
key: '[Your key]',
@@ -29,6 +30,21 @@ futuresSDK.futuresStatus(console.log);
2930
// console.log
3031
// );
3132

33+
// futuresSDK.futuresBuyTest(
34+
// {
35+
// symbol: 'ETHUSDTM',
36+
// price: 10000,
37+
// leverage: 5,
38+
// size: 1,
39+
// optional: {
40+
// stop: 'up',
41+
// stopPriceType: 'TP',
42+
// stopPrice: '10000'
43+
// }
44+
// },
45+
// console.log
46+
// );
47+
3248
// futuresSDK.futuresSell(
3349
// {
3450
// symbol: 'ETHUSDTM',
@@ -47,6 +63,24 @@ futuresSDK.futuresStatus(console.log);
4763
// console.log
4864
// );
4965

66+
// futuresSDK.futuresSellTest(
67+
// {
68+
// symbol: 'ETHUSDTM',
69+
// price: 3000,
70+
// leverage: 15,
71+
// size: 1,
72+
// // clientOid: uuidV4(),
73+
// optional: {
74+
// remark: 'test',
75+
// stop: 'up',
76+
// stopPriceType: 'TP',
77+
// stopPrice: '20000',
78+
// // ...
79+
// }
80+
// },
81+
// console.log
82+
// );
83+
5084
// futuresSDK.futuresCancel('orderId', console.log);
5185

5286
// futuresSDK.futuresCancelAllOpenOrders('ETHUSDTM', console.log);
@@ -73,6 +107,30 @@ futuresSDK.futuresStatus(console.log);
73107

74108
// futuresSDK.futuresOrderDetail('orderId', console.log);
75109

110+
// futuresSDK.futuresOrderMulti(
111+
// [
112+
// {
113+
// clientOid: uuidV4(),
114+
// side: 'buy',
115+
// symbol: 'ETHUSDTM',
116+
// type: 'limit',
117+
// price: '10',
118+
// size: '1',
119+
// leverage: 5
120+
// },
121+
// {
122+
// clientOid: uuidV4(),
123+
// side: 'buy',
124+
// symbol: 'XBTUSDTM',
125+
// type: 'limit',
126+
// price: '10',
127+
// size: '2',
128+
// leverage: 10
129+
// }
130+
// ],
131+
// console.log
132+
// );
133+
76134
// futuresSDK.futuresTransactionHistory(
77135
// {
78136
// startTime: new Date().getTime() - 7 * 24 * 60 * 60 * 1000,

lib/dataType/order.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ export interface OrderBody extends BaseOrderBody {
1616
side: string;
1717
price?: number | string;
1818
}
19+
export interface MultiOrderBody {
20+
clientOid: string;
21+
side: string;
22+
symbol: string;
23+
leverage: string;
24+
price?: number | string;
25+
size?: number;
26+
type?: string;
27+
remark?: string;
28+
stop?: string;
29+
stopPriceType?: string;
30+
stopPrice?: string;
31+
reduceOnly?: string;
32+
closeOrder?: string;
33+
forceHold?: string;
34+
timeInForce?: string;
35+
postOnly?: string;
36+
hidden?: string;
37+
iceberg?: string;
38+
visibleSize?: string;
39+
}
1940
export type OpenOrderStatusType = 'active' | 'done';
2041
export interface OpenOrderListParams extends PageSizeParams {
2142
status?: OpenOrderStatusType;

lib/index.d.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams } from './dataType';
1+
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams, MultiOrderBody } from './dataType';
22
import { WebSocketClient } from './websocket';
33
export default class KuCoinFutures {
44
private request;
@@ -58,6 +58,7 @@ export default class KuCoinFutures {
5858
*/
5959
futureTransfers: (params?: TransferListParams, callback?: Function) => Promise<any>;
6060
private order;
61+
private orderTest;
6162
private stopOrder;
6263
futuresBuy: (params: {
6364
symbol: string;
@@ -75,6 +76,23 @@ export default class KuCoinFutures {
7576
clientOid?: string | undefined;
7677
optional?: object | undefined;
7778
}, callback?: Function) => Promise<any>;
79+
futuresBuyTest: (params: {
80+
symbol: string;
81+
size: string | number;
82+
price: string | number;
83+
leverage?: number | undefined;
84+
clientOid?: string | undefined;
85+
optional?: object | undefined;
86+
}, callback?: Function) => Promise<any>;
87+
futuresSellTest: (params: {
88+
symbol: string;
89+
size: string | number;
90+
price: string | number;
91+
leverage?: number | undefined;
92+
clientOid?: string | undefined;
93+
optional?: object | undefined;
94+
}, callback?: Function) => Promise<any>;
95+
futuresOrderMulti: (params: Array<MultiOrderBody>, callback?: Function) => Promise<any>;
7896
futuresCancel: (orderId: string, callback?: Function) => Promise<any>;
7997
futuresCancelAllOpenOrders: (symbol?: string, callback?: Function) => Promise<any>;
8098
futuresCancelAllStopOrders: (symbol?: string, callback?: Function) => Promise<any>;

lib/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ var KuCoinFutures = /** @class */ (function () {
238238
});
239239
});
240240
};
241+
this.orderTest = function (params, method, callback) {
242+
if (method === void 0) { method = constants_1.GET; }
243+
return __awaiter(_this_1, void 0, void 0, function () {
244+
var _a, body, endpoint;
245+
return __generator(this, function (_b) {
246+
_a = (0, resetAPI_1.returnBodyAndEndpoint)(params, method, true), body = _a.body, endpoint = _a.endpoint;
247+
return [2 /*return*/, this.makeRequest({ body: body, method: method, endpoint: endpoint, callback: callback })];
248+
});
249+
});
250+
};
241251
this.stopOrder = function (params, method, callback) {
242252
if (method === void 0) { method = constants_1.GET; }
243253
return __awaiter(_this_1, void 0, void 0, function () {
@@ -271,6 +281,38 @@ var KuCoinFutures = /** @class */ (function () {
271281
return [2 /*return*/, this.order({ side: 'sell', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
272282
});
273283
}); };
284+
// Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
285+
this.futuresBuyTest = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
286+
var price, symbol, size, _a, leverage, _b, clientOid, optional;
287+
return __generator(this, function (_c) {
288+
price = params.price, symbol = params.symbol, size = params.size, _a = params.leverage, leverage = _a === void 0 ? 1 : _a, _b = params.clientOid, clientOid = _b === void 0 ? (0, uuid_1.v4)() : _b, optional = params.optional;
289+
if (!symbol) {
290+
throw new TypeError('Order buy symbol must be set!');
291+
}
292+
return [2 /*return*/, this.orderTest({ side: 'buy', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
293+
});
294+
}); };
295+
// Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
296+
this.futuresSellTest = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
297+
var price, symbol, size, _a, leverage, _b, clientOid, optional;
298+
return __generator(this, function (_c) {
299+
price = params.price, symbol = params.symbol, size = params.size, _a = params.leverage, leverage = _a === void 0 ? 1 : _a, _b = params.clientOid, clientOid = _b === void 0 ? (0, uuid_1.v4)() : _b, optional = params.optional;
300+
if (!symbol) {
301+
throw new TypeError('Order sell symbol must be set!');
302+
}
303+
return [2 /*return*/, this.orderTest({ side: 'sell', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
304+
});
305+
}); };
306+
this.futuresOrderMulti = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
307+
return __generator(this, function (_a) {
308+
return [2 /*return*/, this.makeRequest({
309+
body: params,
310+
method: constants_1.POST,
311+
endpoint: resetAPI_1.FUTURES_ORDER_MULTI_EP,
312+
callback: callback
313+
})];
314+
});
315+
}); };
274316
this.futuresCancel = function (orderId, callback) { return __awaiter(_this_1, void 0, void 0, function () {
275317
return __generator(this, function (_a) {
276318
return [2 /*return*/, this.order(orderId, constants_1.DELETE, callback)];

lib/resetAPI/constants.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export declare const FUTURES_ORDER_EP = "/api/v1/orders";
1010
export declare const FUTURES_STOP_ORDER_EP = "/api/v1/stopOrders";
1111
export declare const FUTURES_RECENT_DONE_ORDERS_EP = "/api/v1/recentDoneOrders";
1212
export declare const FUTURES_ORDER_CLIENT_ORDER_EP = "/api/v1/orders/client-order";
13+
export declare const FUTURES_ORDER_TEST_EP = "/api/v1/orders/test";
14+
export declare const FUTURES_ORDER_MULTI_EP = "/api/v1/orders/multi";
1315
export declare const FUTURES_FILLS_EP = "/api/v1/fills";
1416
export declare const FUTURES_RECENT_FILLS_EP = "/api/v1/recentFills";
1517
export declare const FUTURES_TOTAL_OPEN_ORDERS_MARGIN_EP = "/api/v1/openOrderStatistics";

lib/resetAPI/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
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;
3+
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_MULTI_EP = exports.FUTURES_ORDER_TEST_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;
44
// account endpoint
55
exports.FUTURES_ACCOUNT_OVERVIEW_EP = '/api/v1/account-overview';
66
exports.FUTURES_ACCOUNT_OVERVIEW_ALL_EP = '/api/v1/account-overview-all';
@@ -16,6 +16,8 @@ exports.FUTURES_ORDER_EP = '/api/v1/orders';
1616
exports.FUTURES_STOP_ORDER_EP = '/api/v1/stopOrders';
1717
exports.FUTURES_RECENT_DONE_ORDERS_EP = '/api/v1/recentDoneOrders';
1818
exports.FUTURES_ORDER_CLIENT_ORDER_EP = '/api/v1/orders/client-order';
19+
exports.FUTURES_ORDER_TEST_EP = '/api/v1/orders/test';
20+
exports.FUTURES_ORDER_MULTI_EP = '/api/v1/orders/multi';
1921
// fills endpoint
2022
exports.FUTURES_FILLS_EP = '/api/v1/fills';
2123
exports.FUTURES_RECENT_FILLS_EP = '/api/v1/recentFills';

lib/resetAPI/futuresOrder.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export declare const makeFuturesOrderBody: ({ side, symbol, size, price, leverag
1717
* return futures order make body and endpoint
1818
* @param {any} params。
1919
* @param {string} method - DEFAULT 'GET'。
20+
* @param {boolean} isTest - DEFAULT false
2021
* @returns {Object} return { body, endpoint }。
2122
*/
22-
declare const returnBodyAndEndpoint: (params: any, method?: string) => {
23+
declare const returnBodyAndEndpoint: (params: any, method?: string, isTest?: boolean) => {
2324
body: any;
2425
endpoint: string;
2526
};

lib/resetAPI/futuresOrder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ exports.makeFuturesOrderBody = makeFuturesOrderBody;
9898
* return futures order make body and endpoint
9999
* @param {any} params。
100100
* @param {string} method - DEFAULT 'GET'。
101+
* @param {boolean} isTest - DEFAULT false
101102
* @returns {Object} return { body, endpoint }。
102103
*/
103-
var returnBodyAndEndpoint = function (params, method) {
104+
var returnBodyAndEndpoint = function (params, method, isTest) {
104105
if (method === void 0) { method = 'GET'; }
105-
var endpoint = constants_1.FUTURES_ORDER_EP;
106+
if (isTest === void 0) { isTest = false; }
107+
var endpoint = isTest ? constants_1.FUTURES_ORDER_TEST_EP : constants_1.FUTURES_ORDER_EP;
106108
var body = params;
107109
switch (method) {
108110
case 'POST': {

lib/tools/constants.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export declare const TIME_OUT = 10000;
22
export declare const GET = "GET";
33
export declare const POST = "POST";
44
export declare const DELETE = "DELETE";
5-
export declare const SANDBOX_ADDR_EP = "https://api-sandbox-futures.kucoin.com";
65
export declare const PROD_ADDR_EP = "https://api-futures.kucoin.com";

0 commit comments

Comments
 (0)