From f09e79edbdb69efe4bc57076eeb2f2dc940f8d19 Mon Sep 17 00:00:00 2001 From: Thanh Tung Date: Sat, 8 Feb 2025 09:56:52 +0700 Subject: [PATCH 1/2] feat: add useDemoTrading flag to BaseRestClient for demo mode support --- package.json | 2 +- src/rest-client-v2.ts | 2 +- src/util/BaseRestClient.ts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 003ea4c..cd6e5da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitget-api", - "version": "2.3.0", + "version": "2.3.1", "description": "Node.js & JavaScript SDK for Bitget REST APIs & WebSockets, with TypeScript & end-to-end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/rest-client-v2.ts b/src/rest-client-v2.ts index ce3a7ea..f5f5788 100644 --- a/src/rest-client-v2.ts +++ b/src/rest-client-v2.ts @@ -1262,7 +1262,7 @@ export class RestClientV2 extends BaseRestClient { } getFuturesContractConfig(params: { - symbol: string; + symbol?: string; productType: FuturesProductTypeV2; }): Promise> { return this.get('/api/v2/mix/market/contracts', params); diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index dcf4057..9f407aa 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -92,6 +92,7 @@ export default abstract class BaseRestClient { constructor( restOptions: RestClientOptions = {}, networkOptions: AxiosRequestConfig = {}, + useDemoTrading: boolean = false, ) { this.options = { recvWindow: 5000, @@ -110,6 +111,7 @@ export default abstract class BaseRestClient { 'X-CHANNEL-API-CODE': 'hbnni', 'Content-Type': 'application/json', locale: 'en-US', + ...(useDemoTrading ? { paptrading: '1' } : {}), }, }; From 2c074b2cc6ee294268c0e2ddf791e8a62377b36d Mon Sep 17 00:00:00 2001 From: Thanh Tung Date: Sat, 8 Feb 2025 18:34:40 +0700 Subject: [PATCH 2/2] refactor: replace useDemoTrading with demoTrading in RestClientOptions for consistency --- src/util/BaseRestClient.ts | 3 +-- src/util/requestUtils.ts | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 9f407aa..e02be75 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -92,7 +92,6 @@ export default abstract class BaseRestClient { constructor( restOptions: RestClientOptions = {}, networkOptions: AxiosRequestConfig = {}, - useDemoTrading: boolean = false, ) { this.options = { recvWindow: 5000, @@ -111,7 +110,7 @@ export default abstract class BaseRestClient { 'X-CHANNEL-API-CODE': 'hbnni', 'Content-Type': 'application/json', locale: 'en-US', - ...(useDemoTrading ? { paptrading: '1' } : {}), + ...(restOptions.demoTrading ? { paptrading: '1' } : {}), }, }; diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 90ea006..e4ed446 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -11,6 +11,13 @@ export interface RestClientOptions { /** Set to `true` to connect to testnet. Uses the live environment by default. */ // testnet?: boolean; + /** + * Set to `true` to use Bitget's demo trading: https://www.bitget.com/api-doc/common/demotrading/restapi. + * + * Disabled by default. + */ + demoTrading?: boolean; + /** Override the max size of the request window (in ms) */ recvWindow?: number;