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

Commit c8bf9af

Browse files
authored
Merge pull request #38 from Apexrsq/feature/supply-interface
feat: add rest interface(/api/v1/st-orders)
2 parents cff2c54 + f1ad8e7 commit c8bf9af

File tree

10 files changed

+147
-20
lines changed

10 files changed

+147
-20
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [Orders](#orders)
2323
- [Place Order Test](#place-order-test)
2424
- [Place Multiple Orders](#place-multiple-orders)
25+
- [Place take profit and stop loss order](#place-take-profit-and-stop-loss-order)
2526
- [Fills](#fills)
2627
- [Positions](#positions)
2728
- [Risk Limit Level](#risk-limit-level)
@@ -390,6 +391,43 @@ futuresSDK.futuresOrderMulti([...], console.log);
390391
```
391392

392393

394+
##### Place take profit and stop loss order
395+
```js
396+
//request
397+
{
398+
"clientOid": "5c52e11203aa677f33e493fb",
399+
"reduceOnly": false,
400+
"closeOrder": false,
401+
"forceHold": false,
402+
"hidden": false,
403+
"iceberg": false,
404+
"leverage": 20,
405+
"postOnly": false,
406+
"price": 8000,
407+
"remark": "remark",
408+
"side": "buy",
409+
"size": 20,"stopPriceType": "",
410+
"symbol": "XBTUSDM",
411+
"timeInForce": "",
412+
"type": "limit",
413+
"visibleSize": 0,
414+
"marginMode": "ISOLATED"
415+
"triggerStopUpPrice": 9000, //take profit price
416+
"triggerStopDownPrice": 7000 //stop loss price
417+
}
418+
419+
//Response
420+
{
421+
"code": "200000",
422+
"data": {
423+
"orderId": "5bd6e9286d99522a52e458de",
424+
"clientOid": "5c52e11203aa677f33e493fb"
425+
}
426+
}
427+
428+
futuresSDK.futuresOrderStp(params, console.log);
429+
```
430+
393431

394432
#### Fills
395433

@@ -478,7 +516,7 @@ futuresSDK.futuresChangeRiskLimit(
478516

479517
```js
480518
// Get Current Funding Rate
481-
futuresSDK.futuresFundingRate('XBTUSDM', console.log);
519+
futuresSDK.futuresFundingRate('XBTUSDTM', console.log);
482520

483521
// Get Public Funding History
484522
futuresSDK.futuresFundingRates({
@@ -558,10 +596,10 @@ futuresSDK.futuresInterests({ symbol: '.XBTINT' }, console.log);
558596
futuresSDK.futuresIndexList({ symbol: '.KXBT' }, console.log);
559597

560598
// Get Current Mark Price
561-
futuresSDK.futuresMarkPrice('XBTUSDM', console.log);
599+
futuresSDK.futuresMarkPrice('XBTUSDTM', console.log);
562600

563601
// Get Premium Index
564-
futuresSDK.futuresPremiums({ symbol: '.XBTUSDMPI' }, console.log);
602+
futuresSDK.futuresPremiums({ symbol: '.XBTUSDTMPI' }, console.log);
565603
```
566604

567605
#### Server Time

example/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ futuresSDK.futuresStatus(console.log);
239239

240240
// futuresSDK.futuresIndexList({ symbol: '.KXBT' }, console.log);
241241

242-
// futuresSDK.futuresMarkPrice('XBTUSDM', console.log);
242+
// futuresSDK.futuresMarkPrice('XBTUSDTM', console.log);
243243

244-
// futuresSDK.futuresPremiums({ symbol: '.XBTUSDMPI' }, console.log);
244+
// futuresSDK.futuresPremiums({ symbol: '.XBTUSDTMPI' }, console.log);
245245

246-
// futuresSDK.futuresFundingRate('XBTUSDM', console.log);
246+
// futuresSDK.futuresFundingRate('XBTUSDTM', console.log);
247247

248248
// futuresSDK.futuresTradeFees('XBTUSDTM', console.log);
249249

lib/dataType/order.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { PageSizeParams } from './common';
22
export type BaseOrderType = 'limit' | 'market';
33
export type OrderType = 'limit' | 'market' | 'limit_stop' | 'market_stop';
4+
export type TriggerType = 'TP' | 'IP' | 'MP';
5+
export type STPType = 'CN' | 'CO' | 'CB';
6+
export type TimeInForceType = 'GTC' | 'IOC';
47
export type OrderOptionalParamsType = 'type' | 'remark' | 'stop' | 'stopPriceType' | 'stopPrice' | 'reduceOnly' | 'closeOrder' | 'forceHold' | 'timeInForce' | 'postOnly' | 'hidden' | 'iceberg' | 'visibleSize';
58
export type OptionalParamsObject<T extends keyof any> = {
69
[P in T]?: any;
@@ -55,3 +58,25 @@ export interface FillsParams extends PageSizeParams {
5558
side?: string;
5659
type?: OrderType;
5760
}
61+
export interface StpOrderParams {
62+
clientOid: string;
63+
side: string;
64+
symbol: string;
65+
leverage: string;
66+
type?: string;
67+
remark?: string;
68+
triggerStopUpPrice?: string;
69+
stopPriceType?: TriggerType;
70+
triggerStopDownPrice?: string;
71+
reduceOnly?: boolean;
72+
closeOrder?: boolean;
73+
forceHold?: boolean;
74+
stp?: STPType;
75+
price?: number | string;
76+
size?: number;
77+
timeInForce?: TimeInForceType;
78+
postOnly?: boolean;
79+
hidden?: boolean;
80+
iceberg?: boolean;
81+
visibleSize?: number | string;
82+
}

lib/index.d.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { WebSocketClient } from './websocket';
2-
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams, MultiOrderBody, HistoryPositionsParams } from './dataType';
2+
import { CreateSubApiParams, FillsParams, FundingHistoryParams, OpenOrderListParams, StopOrderListParams, TransactionHistoryParams, TransferListParams, UpdateSubApiParams, IndexListParams, klineParams, Callback, FundingRatesParams, MultiOrderBody, HistoryPositionsParams, StpOrderParams } from './dataType';
33
export default class KuCoinFutures {
44
private request;
55
private socketInstanceCache;
@@ -93,6 +93,7 @@ export default class KuCoinFutures {
9393
optional?: object | undefined;
9494
}, callback?: Function) => Promise<any>;
9595
futuresOrderMulti: (params: Array<MultiOrderBody>, callback?: Function) => Promise<any>;
96+
futuresOrderStp: (params: StpOrderParams, callback?: Function) => Promise<any>;
9697
futuresCancel: (orderId: string, callback?: Function) => Promise<any>;
9798
futuresCancelAllOpenOrders: (symbol?: string, callback?: Function) => Promise<any>;
9899
futuresCancelAllStopOrders: (symbol?: string, callback?: Function) => Promise<any>;
@@ -255,19 +256,29 @@ export default class KuCoinFutures {
255256
futuresSocketSubscribe: (topic: string, callback?: Callback, isPrivate?: boolean, strict?: boolean) => Promise<false | undefined>;
256257
get websocket(): {
257258
klineCandle: (symbol: string, callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
258-
tickerV2: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
259-
ticker: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
260-
level2: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
261-
execution: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
262-
level2Depth5: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
263-
level2Depth50: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
264-
instrument: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
259+
tickerV2: (symbols: string | [
260+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
261+
ticker: (symbols: string | [
262+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
263+
level2: (symbols: string | [
264+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
265+
execution: (symbols: string | [
266+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
267+
level2Depth5: (symbols: string | [
268+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
269+
level2Depth50: (symbols: string | [
270+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
271+
instrument: (symbols: string | [
272+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
265273
announcement: (callback?: (d: any) => void) => Promise<false | undefined>;
266-
snapshot: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
267-
tradeOrders: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
274+
snapshot: (symbols: string | [
275+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
276+
tradeOrders: (symbols: string | [
277+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
268278
advancedOrders: (callback?: (d: any) => void) => Promise<false | undefined>;
269279
wallet: (callback?: (d: any) => void) => Promise<false | undefined>;
270-
position: (symbols: string | [], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
280+
position: (symbols: string | [
281+
], callback?: (d: any) => void) => Promise<false | (false | undefined)[] | undefined>;
271282
positionAll: (callback?: (d: any) => void) => Promise<false | undefined>;
272283
};
273284
}

lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,16 @@ var KuCoinFutures = /** @class */ (function () {
312312
})];
313313
});
314314
}); };
315+
this.futuresOrderStp = function (params, callback) { return __awaiter(_this_1, void 0, void 0, function () {
316+
return __generator(this, function (_a) {
317+
return [2 /*return*/, this.makeRequest({
318+
body: params,
319+
method: constants_1.POST,
320+
endpoint: resetAPI_1.FUTURES_ORDER_STP_EP,
321+
callback: callback
322+
})];
323+
});
324+
}); };
315325
this.futuresCancel = function (orderId, callback) { return __awaiter(_this_1, void 0, void 0, function () {
316326
return __generator(this, function (_a) {
317327
return [2 /*return*/, this.order(orderId, constants_1.DELETE, callback)];

lib/resetAPI/constants.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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";
1313
export declare const FUTURES_ORDER_TEST_EP = "/api/v1/orders/test";
1414
export declare const FUTURES_ORDER_MULTI_EP = "/api/v1/orders/multi";
15+
export declare const FUTURES_ORDER_STP_EP = "/api/v1/st-orders";
1516
export declare const FUTURES_FILLS_EP = "/api/v1/fills";
1617
export declare const FUTURES_RECENT_FILLS_EP = "/api/v1/recentFills";
1718
export declare const FUTURES_TOTAL_OPEN_ORDERS_MARGIN_EP = "/api/v1/openOrderStatistics";

lib/resetAPI/constants.js

Lines changed: 2 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_ALL_TICKER_TP = 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_TRADE_FEE_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_MAX_OPEN_POSITIONS_EP = exports.FUTURES_HISTORY_POSITIONS_EP = exports.FUTURES_WITHDRAW_MARGIN_EP = exports.FUTURES_MAX_WITHDRAW_MARGIN_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;
3+
exports.FUTURES_ALL_TICKER_TP = 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_TRADE_FEE_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_MAX_OPEN_POSITIONS_EP = exports.FUTURES_HISTORY_POSITIONS_EP = exports.FUTURES_WITHDRAW_MARGIN_EP = exports.FUTURES_MAX_WITHDRAW_MARGIN_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_STP_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';
@@ -18,6 +18,7 @@ exports.FUTURES_RECENT_DONE_ORDERS_EP = '/api/v1/recentDoneOrders';
1818
exports.FUTURES_ORDER_CLIENT_ORDER_EP = '/api/v1/orders/client-order';
1919
exports.FUTURES_ORDER_TEST_EP = '/api/v1/orders/test';
2020
exports.FUTURES_ORDER_MULTI_EP = '/api/v1/orders/multi';
21+
exports.FUTURES_ORDER_STP_EP = '/api/v1/st-orders';
2122
// fills endpoint
2223
exports.FUTURES_FILLS_EP = '/api/v1/fills';
2324
exports.FUTURES_RECENT_FILLS_EP = '/api/v1/recentFills';

src/dataType/order.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { PageSizeParams } from './common';
22

33
export type BaseOrderType = 'limit' | 'market';
44
export type OrderType = 'limit' | 'market' | 'limit_stop' | 'market_stop';
5+
export type TriggerType = 'TP' | 'IP' | 'MP';
6+
export type STPType = 'CN' | 'CO' | 'CB';
7+
export type TimeInForceType = 'GTC' | 'IOC';
58

69
export type OrderOptionalParamsType =
710
| 'type'
@@ -77,3 +80,26 @@ export interface FillsParams extends PageSizeParams {
7780
side?: string;
7881
type?: OrderType;
7982
}
83+
84+
export interface StpOrderParams {
85+
clientOid: string;
86+
side: string;
87+
symbol: string;
88+
leverage: string;
89+
type?: string;
90+
remark?: string;
91+
triggerStopUpPrice?: string;
92+
stopPriceType?: TriggerType;
93+
triggerStopDownPrice?: string;
94+
reduceOnly?: boolean;
95+
closeOrder?: boolean;
96+
forceHold?: boolean;
97+
stp?: STPType;
98+
price?: number | string;
99+
size?: number;
100+
timeInForce?: TimeInForceType;
101+
postOnly?: boolean;
102+
hidden?: boolean;
103+
iceberg?: boolean;
104+
visibleSize?: number | string;
105+
}

src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import {
5151
FUTURES_TRADE_FEE_EP,
5252
FUTURES_HISTORY_POSITIONS_EP,
5353
FUTURES_MAX_OPEN_POSITIONS_EP,
54-
FUTURES_ALL_TICKER_TP
54+
FUTURES_ALL_TICKER_TP,
55+
FUTURES_ORDER_STP_EP
5556
} from './resetAPI';
5657
import {
5758
WebSocketClient,
@@ -92,7 +93,8 @@ import {
9293
Callback,
9394
FundingRatesParams,
9495
MultiOrderBody,
95-
HistoryPositionsParams
96+
HistoryPositionsParams,
97+
StpOrderParams
9698
} from './dataType';
9799

98100
export default class KuCoinFutures {
@@ -447,6 +449,18 @@ export default class KuCoinFutures {
447449
});
448450
};
449451

452+
futuresOrderStp = async (
453+
params: StpOrderParams,
454+
callback?: Function
455+
) => {
456+
return this.makeRequest({
457+
body: params,
458+
method: POST,
459+
endpoint: FUTURES_ORDER_STP_EP,
460+
callback
461+
});
462+
};
463+
450464
futuresCancel = async (orderId: string, callback?: Function) => {
451465
return this.order(orderId, DELETE, callback);
452466
};

src/resetAPI/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const FUTURES_RECENT_DONE_ORDERS_EP = '/api/v1/recentDoneOrders';
1818
export const FUTURES_ORDER_CLIENT_ORDER_EP = '/api/v1/orders/client-order';
1919
export const FUTURES_ORDER_TEST_EP = '/api/v1/orders/test';
2020
export const FUTURES_ORDER_MULTI_EP = '/api/v1/orders/multi';
21+
export const FUTURES_ORDER_STP_EP = '/api/v1/st-orders';
2122

2223
// fills endpoint
2324
export const FUTURES_FILLS_EP = '/api/v1/fills';

0 commit comments

Comments
 (0)