Skip to content

Commit

Permalink
Merge pull request #25 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 May 29, 2024
2 parents 36a63fc + a0dc9f2 commit 58deca8
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 24 deletions.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- [Get Transfer-Out Request Records](#get-transfer-out-request-records)
- [Trade](#trade)
- [Orders](#orders)
- [Place Order Test](#place-order-test)
- [Place Multiple Orders](#place-multiple-orders)
- [Fills](#fills)
- [Positions](#positions)
- [Risk Limit Level](#risk-limit-level)
Expand Down Expand Up @@ -280,6 +282,113 @@ futuresSDK.futuresOrderDetail({ clientOid: 'clientOid' }, console.log);
futuresSDK.futuresOrderDetail('orderId', console.log);
```

##### Place Order Test
> Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
```js
// 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
);
```

##### Place Multiple Orders
```js
//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);
```



#### Fills

```js
Expand Down
58 changes: 58 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const KuCoinFutures = require('../lib/index').default;
// const { v4: uuidV4 } = require('uuid');

const futuresSDK = new KuCoinFutures({
key: '[Your key]',
Expand Down Expand Up @@ -29,6 +30,21 @@ futuresSDK.futuresStatus(console.log);
// console.log
// );

// futuresSDK.futuresBuyTest(
// {
// symbol: 'ETHUSDTM',
// price: 10000,
// leverage: 5,
// size: 1,
// optional: {
// stop: 'up',
// stopPriceType: 'TP',
// stopPrice: '10000'
// }
// },
// console.log
// );

// futuresSDK.futuresSell(
// {
// symbol: 'ETHUSDTM',
Expand All @@ -47,6 +63,24 @@ futuresSDK.futuresStatus(console.log);
// console.log
// );

// futuresSDK.futuresSellTest(
// {
// symbol: 'ETHUSDTM',
// price: 3000,
// leverage: 15,
// size: 1,
// // clientOid: uuidV4(),
// optional: {
// remark: 'test',
// stop: 'up',
// stopPriceType: 'TP',
// stopPrice: '20000',
// // ...
// }
// },
// console.log
// );

// futuresSDK.futuresCancel('orderId', console.log);

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

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

// futuresSDK.futuresOrderMulti(
// [
// {
// clientOid: uuidV4(),
// side: 'buy',
// symbol: 'ETHUSDTM',
// type: 'limit',
// price: '10',
// size: '1',
// leverage: 5
// },
// {
// clientOid: uuidV4(),
// side: 'buy',
// symbol: 'XBTUSDTM',
// type: 'limit',
// price: '10',
// size: '2',
// leverage: 10
// }
// ],
// console.log
// );

// futuresSDK.futuresTransactionHistory(
// {
// startTime: new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
Expand Down
21 changes: 21 additions & 0 deletions lib/dataType/order.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ export interface OrderBody extends BaseOrderBody {
side: string;
price?: number | string;
}
export interface MultiOrderBody {
clientOid: string;
side: string;
symbol: string;
leverage: string;
price?: number | string;
size?: number;
type?: string;
remark?: string;
stop?: string;
stopPriceType?: string;
stopPrice?: string;
reduceOnly?: string;
closeOrder?: string;
forceHold?: string;
timeInForce?: string;
postOnly?: string;
hidden?: string;
iceberg?: string;
visibleSize?: string;
}
export type OpenOrderStatusType = 'active' | 'done';
export interface OpenOrderListParams extends PageSizeParams {
status?: OpenOrderStatusType;
Expand Down
20 changes: 19 additions & 1 deletion 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, FundingRatesParams } from './dataType';
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams, MultiOrderBody } from './dataType';
import { WebSocketClient } from './websocket';
export default class KuCoinFutures {
private request;
Expand Down Expand Up @@ -58,6 +58,7 @@ export default class KuCoinFutures {
*/
futureTransfers: (params?: TransferListParams, callback?: Function) => Promise<any>;
private order;
private orderTest;
private stopOrder;
futuresBuy: (params: {
symbol: string;
Expand All @@ -75,6 +76,23 @@ export default class KuCoinFutures {
clientOid?: string | undefined;
optional?: object | undefined;
}, callback?: Function) => Promise<any>;
futuresBuyTest: (params: {
symbol: string;
size: string | number;
price: string | number;
leverage?: number | undefined;
clientOid?: string | undefined;
optional?: object | undefined;
}, callback?: Function) => Promise<any>;
futuresSellTest: (params: {
symbol: string;
size: string | number;
price: string | number;
leverage?: number | undefined;
clientOid?: string | undefined;
optional?: object | undefined;
}, callback?: Function) => Promise<any>;
futuresOrderMulti: (params: Array<MultiOrderBody>, callback?: Function) => Promise<any>;
futuresCancel: (orderId: string, callback?: Function) => Promise<any>;
futuresCancelAllOpenOrders: (symbol?: string, callback?: Function) => Promise<any>;
futuresCancelAllStopOrders: (symbol?: string, callback?: Function) => Promise<any>;
Expand Down
42 changes: 42 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ var KuCoinFutures = /** @class */ (function () {
});
});
};
this.orderTest = function (params, method, callback) {
if (method === void 0) { method = constants_1.GET; }
return __awaiter(_this_1, void 0, void 0, function () {
var _a, body, endpoint;
return __generator(this, function (_b) {
_a = (0, resetAPI_1.returnBodyAndEndpoint)(params, method, true), body = _a.body, endpoint = _a.endpoint;
return [2 /*return*/, this.makeRequest({ body: body, method: method, endpoint: endpoint, callback: callback })];
});
});
};
this.stopOrder = function (params, method, callback) {
if (method === void 0) { method = constants_1.GET; }
return __awaiter(_this_1, void 0, void 0, function () {
Expand Down Expand Up @@ -271,6 +281,38 @@ var KuCoinFutures = /** @class */ (function () {
return [2 /*return*/, this.order({ side: 'sell', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
});
}); };
// Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
this.futuresBuyTest = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
var price, symbol, size, _a, leverage, _b, clientOid, optional;
return __generator(this, function (_c) {
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;
if (!symbol) {
throw new TypeError('Order buy symbol must be set!');
}
return [2 /*return*/, this.orderTest({ side: 'buy', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
});
}); };
// Place Order Test, After placing an order, the order will not enter the matching system, and the order cannot be queried.
this.futuresSellTest = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
var price, symbol, size, _a, leverage, _b, clientOid, optional;
return __generator(this, function (_c) {
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;
if (!symbol) {
throw new TypeError('Order sell symbol must be set!');
}
return [2 /*return*/, this.orderTest({ side: 'sell', price: price, symbol: symbol, size: size, leverage: leverage, clientOid: clientOid, optional: optional }, constants_1.POST, callback)];
});
}); };
this.futuresOrderMulti = 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.POST,
endpoint: resetAPI_1.FUTURES_ORDER_MULTI_EP,
callback: callback
})];
});
}); };
this.futuresCancel = function (orderId, callback) { return __awaiter(_this_1, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.order(orderId, constants_1.DELETE, callback)];
Expand Down
2 changes: 2 additions & 0 deletions lib/resetAPI/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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_ORDER_TEST_EP = "/api/v1/orders/test";
export declare const FUTURES_ORDER_MULTI_EP = "/api/v1/orders/multi";
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 Down
4 changes: 3 additions & 1 deletion 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_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;
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;
// account endpoint
exports.FUTURES_ACCOUNT_OVERVIEW_EP = '/api/v1/account-overview';
exports.FUTURES_ACCOUNT_OVERVIEW_ALL_EP = '/api/v1/account-overview-all';
Expand All @@ -16,6 +16,8 @@ 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';
exports.FUTURES_ORDER_TEST_EP = '/api/v1/orders/test';
exports.FUTURES_ORDER_MULTI_EP = '/api/v1/orders/multi';
// fills endpoint
exports.FUTURES_FILLS_EP = '/api/v1/fills';
exports.FUTURES_RECENT_FILLS_EP = '/api/v1/recentFills';
Expand Down
3 changes: 2 additions & 1 deletion lib/resetAPI/futuresOrder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export declare const makeFuturesOrderBody: ({ side, symbol, size, price, leverag
* return futures order make body and endpoint
* @param {any} params。
* @param {string} method - DEFAULT 'GET'。
* @param {boolean} isTest - DEFAULT false
* @returns {Object} return { body, endpoint }。
*/
declare const returnBodyAndEndpoint: (params: any, method?: string) => {
declare const returnBodyAndEndpoint: (params: any, method?: string, isTest?: boolean) => {
body: any;
endpoint: string;
};
Expand Down
6 changes: 4 additions & 2 deletions lib/resetAPI/futuresOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ exports.makeFuturesOrderBody = makeFuturesOrderBody;
* return futures order make body and endpoint
* @param {any} params。
* @param {string} method - DEFAULT 'GET'。
* @param {boolean} isTest - DEFAULT false
* @returns {Object} return { body, endpoint }。
*/
var returnBodyAndEndpoint = function (params, method) {
var returnBodyAndEndpoint = function (params, method, isTest) {
if (method === void 0) { method = 'GET'; }
var endpoint = constants_1.FUTURES_ORDER_EP;
if (isTest === void 0) { isTest = false; }
var endpoint = isTest ? constants_1.FUTURES_ORDER_TEST_EP : constants_1.FUTURES_ORDER_EP;
var body = params;
switch (method) {
case 'POST': {
Expand Down
1 change: 0 additions & 1 deletion lib/tools/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export declare const TIME_OUT = 10000;
export declare const GET = "GET";
export declare const POST = "POST";
export declare const DELETE = "DELETE";
export declare const SANDBOX_ADDR_EP = "https://api-sandbox-futures.kucoin.com";
export declare const PROD_ADDR_EP = "https://api-futures.kucoin.com";
3 changes: 1 addition & 2 deletions lib/tools/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PROD_ADDR_EP = exports.SANDBOX_ADDR_EP = exports.DELETE = exports.POST = exports.GET = exports.TIME_OUT = void 0;
exports.PROD_ADDR_EP = exports.DELETE = exports.POST = exports.GET = exports.TIME_OUT = void 0;
exports.TIME_OUT = 10000;
exports.GET = 'GET';
exports.POST = 'POST';
exports.DELETE = 'DELETE';
exports.SANDBOX_ADDR_EP = 'https://api-sandbox-futures.kucoin.com';
exports.PROD_ADDR_EP = 'https://api-futures.kucoin.com';
Loading

0 comments on commit 58deca8

Please sign in to comment.