From df047a0cdbd48a1f62e6fbf1ae269e1d48ea172f Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Fri, 28 Feb 2025 11:23:57 +0000 Subject: [PATCH] fix(v3.11.0): ensure private GET requests use serialised/encoded params appended to URL. Update slippage tolerance type to optional. --- package-lock.json | 4 ++-- package.json | 2 +- src/types/request/v5-trade.ts | 4 ++-- src/util/BaseRestClient.ts | 5 ++++- test/v5/private.read.test.ts | 30 +++++++++++++++++++++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e18733..a0091a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.10.34", + "version": "3.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.10.34", + "version": "3.11.0", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 786d88a..507cc0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.10.34", + "version": "3.11.0", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/types/request/v5-trade.ts b/src/types/request/v5-trade.ts index b8d42bc..22bd732 100644 --- a/src/types/request/v5-trade.ts +++ b/src/types/request/v5-trade.ts @@ -18,8 +18,8 @@ export interface OrderParamsV5 { orderType: OrderTypeV5; qty: string; marketUnit?: 'baseCoin' | 'quoteCoin'; - slippageToleranceType: string; - slippageTolerance: string; + slippageToleranceType?: string; + slippageTolerance?: string; price?: string; triggerDirection?: 1 | 2; orderFilter?: OrderFilterV5; diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index eb46c7f..18728a5 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -67,6 +67,7 @@ interface SignedRequest { interface UnsignedRequest { originalParams: T; paramsWithSign: T; + serializedParams: string; sign?: string; timestamp?: number; recvWindow?: number; @@ -285,7 +286,9 @@ export default abstract class BaseRestClient { return { ...options, headers, - params: signResult.originalParams, + url: signResult.serializedParams + ? options.url + '?' + signResult.serializedParams + : options.url, }; } diff --git a/test/v5/private.read.test.ts b/test/v5/private.read.test.ts index b84d47d..abb8625 100644 --- a/test/v5/private.read.test.ts +++ b/test/v5/private.read.test.ts @@ -188,7 +188,35 @@ describe('Private READ V5 REST API Endpoints', () => { accountType: accountType, coin: settleCoin, }), - ).toMatchObject({ ...successResponseObjectV3() }); + ).toMatchObject({ + ...successResponseObjectV3(), + // retMsg: '', + }); + }); + + it('getAllCoinsBalance() unified with one symbol', async () => { + const result = await api.getAllCoinsBalance({ + accountType: 'UNIFIED', + coin: 'USDT', + }); + + if (result.retCode !== 0) { + console.error(expect.getState().currentTestName, 'exception: ', result); + } + + expect(result).toMatchObject({ ...successResponseObjectV3() }); + }); + + it('getAllCoinsBalance() unified with multiple symbols', async () => { + const result = await api.getAllCoinsBalance({ + accountType: 'UNIFIED', + coin: 'USDT,ETH', + }); + + if (result.retCode !== 0) { + console.error(expect.getState().currentTestName, 'exception: ', result); + } + expect(result).toMatchObject({ ...successResponseObjectV3() }); }); it('getTransferableCoinList()', async () => {