From 6f9981db15394ef9c97838721adc98c71e68a678 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 10 Feb 2023 18:26:55 +0000 Subject: [PATCH 1/2] v1.0.4: feat(#6) add futures trailing stop endpoint, add missing types for new order endpoint --- package.json | 2 +- src/futures-client.ts | 8 ++++++++ src/types/request/futures.ts | 20 +++++++++++++++++--- test/futures/private.write.test.ts | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 67faa63..53dfe5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitget-api", - "version": "1.0.3", + "version": "1.0.4", "description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/futures-client.ts b/src/futures-client.ts index 0560a4a..92444d0 100644 --- a/src/futures-client.ts +++ b/src/futures-client.ts @@ -19,6 +19,7 @@ import { FuturesSymbolRule, FuturesMarginMode, FuturesPosition, + NewFuturesPlanTrailingStopOrder, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -417,6 +418,13 @@ export class FuturesClient extends BaseRestClient { return this.postPrivate('/api/mix/v1/plan/placeTPSL', params); } + /** Place Trailing Stop order */ + submitTrailingStopOrder( + params: NewFuturesPlanTrailingStopOrder + ): Promise> { + return this.postPrivate('/api/mix/v1/plan/placeTrailStop', params); + } + /** Place Position TPSL */ submitPositionTPSL( params: NewFuturesPlanPositionTPSL diff --git a/src/types/request/futures.ts b/src/types/request/futures.ts index 053dcb7..67dfc32 100644 --- a/src/types/request/futures.ts +++ b/src/types/request/futures.ts @@ -38,7 +38,9 @@ export type FuturesOrderSide = | 'open_long' | 'open_short' | 'close_long' - | 'close_short'; + | 'close_short' + | 'buy_single' + | 'sell_single'; export interface NewFuturesOrder { symbol: string; @@ -100,15 +102,27 @@ export interface ModifyFuturesPlanOrderTPSL { presetStopLossPrice?: string; } -export type FuturesPlanType = 'profit_plan' | 'loss_plan'; +export type FuturesPlanType = 'profit_plan' | 'loss_plan' | 'moving_plan'; export interface NewFuturesPlanStopOrder { symbol: string; marginCoin: string; planType: FuturesPlanType; triggerPrice: string; - holdSide?: FuturesHoldSide; + triggerType?: 'fill_price' | 'market_price'; + holdSide: FuturesHoldSide; size?: string; + rangeRate?: string; +} + +export interface NewFuturesPlanTrailingStopOrder { + symbol: string; + marginCoin: string; + triggerPrice: string; + triggerType?: 'fill_price' | 'market_price'; + size?: string; + side: FuturesOrderSide; + rangeRate?: string; } export interface NewFuturesPlanPositionTPSL { diff --git a/test/futures/private.write.test.ts b/test/futures/private.write.test.ts index 781c360..8301894 100644 --- a/test/futures/private.write.test.ts +++ b/test/futures/private.write.test.ts @@ -227,6 +227,7 @@ describe('Private Futures REST API POST Endpoints', () => { marginCoin, symbol, planType: 'profit_plan', + holdSide: 'long', triggerPrice: '100', }) ).toMatchObject({ From b98ef12c6997137704ce687ae1b63493619efe99 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 10 Feb 2023 18:31:42 +0000 Subject: [PATCH 2/2] fix test exception codes --- src/constants/enum.ts | 1 + test/futures/private.write.test.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/constants/enum.ts b/src/constants/enum.ts index 5a6185f..7de0b93 100644 --- a/src/constants/enum.ts +++ b/src/constants/enum.ts @@ -9,6 +9,7 @@ export const API_ERROR_CODE = { INSUFFICIENT_BALANCE: '40754', QTY_GREATER_THAN_MAX_OPEN: '40762', FUTURES_ORDER_CANCEL_NOT_FOUND: '40768', + FUTURES_INSUFFICIENT_POSITION_NO_TPSL: '40891', QTY_LESS_THAN_MINIMUM: '43006', /** Parameter verification exception margin mode == FIXED */ PARAMETER_EXCEPTION: '40808', diff --git a/test/futures/private.write.test.ts b/test/futures/private.write.test.ts index 8301894..d4464f4 100644 --- a/test/futures/private.write.test.ts +++ b/test/futures/private.write.test.ts @@ -82,7 +82,7 @@ describe('Private Futures REST API POST Endpoints', () => { data: {}, }); } catch (e) { - console.log(`submitOrder() exception: `, e.body); + // console.log(`submitOrder() exception: `, e.body); expect(e.body).toMatchObject({ // seems to be the new "insufficient balance" error, informed bitget on 7th feb code: API_ERROR_CODE.QTY_GREATER_THAN_MAX_OPEN, @@ -235,8 +235,9 @@ describe('Private Futures REST API POST Endpoints', () => { data: {}, }); } catch (e) { + // console.log(e.body); expect(e.body).toMatchObject({ - code: API_ERROR_CODE.FUTURES_POSITION_DIRECTION_EMPTY, + code: API_ERROR_CODE.FUTURES_INSUFFICIENT_POSITION_NO_TPSL, }); } });