From 60e56bbeb23c4f169ec6d30df6e9c0ab220e198d Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Thu, 7 Dec 2023 10:49:03 +0000 Subject: [PATCH 1/3] feat(): add new many-symbol param for spot and better method signatures --- examples/rest-spot-public.ts | 22 ++++++++++++++++++++-- package.json | 2 +- src/main-client.ts | 33 ++++++++++++++++++++++++++------- src/types/shared.ts | 4 ++++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/examples/rest-spot-public.ts b/examples/rest-spot-public.ts index 8eaf9e39..d52c4b01 100644 --- a/examples/rest-spot-public.ts +++ b/examples/rest-spot-public.ts @@ -10,8 +10,26 @@ const client = new MainClient({ (async () => { try { - console.log('getAvgPrice: ', await client.getAvgPrice({ symbol: 'BTCUSDT' })); - console.log('getExchangeInfo: ', JSON.stringify(await client.getExchangeInfo(), null, 2)); + // console.log( + // 'getAvgPrice: ', + // await client.getAvgPrice({ symbol: 'BTCUSDT' }), + // ); + // console.log( + // 'getExchangeInfo: ', + // JSON.stringify(await client.getExchangeInfo(), null, 2), + // ); + + const oneTicker = await client.get24hrChangeStatististics({ + symbol: 'BTCUSDT', + }); + console.log('getTickers', oneTicker); + + const manyTickers = await client.get24hrChangeStatististics({ + symbols: ['BTCUSDT', 'ETHUSDT'], + }); + console.log('getTickers many', manyTickers); + const allTickers = await client.get24hrChangeStatististics(); + console.log('getTickers all'); } catch (e) { console.error('request failed: ', e); } diff --git a/package.json b/package.json index d8f95242..5c9abbca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance", - "version": "2.8.13", + "version": "2.8.14", "description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/main-client.ts b/src/main-client.ts index 1f1681dc..7f56b27a 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -20,6 +20,7 @@ import { SymbolPrice, RowsWithTotal, CoinStartEndLimit, + SymbolArrayParam, } from './types/shared'; import { @@ -753,15 +754,33 @@ export class MainClient extends BaseRestClient { } get24hrChangeStatististics( - params?: Partial, + params: BasicSymbolParam, + ): Promise; + + get24hrChangeStatististics( + params?: SymbolArrayParam, + ): Promise; + + get24hrChangeStatististics( + params?: Partial | Partial, ): Promise { - if (!params?.symbol) { - return this.get('api/v3/ticker/24hr') as Promise; + if (params && typeof params['symbol'] === 'string') { + return this.get( + 'api/v3/ticker/24hr', + params, + ) as Promise; } - return this.get( - 'api/v3/ticker/24hr', - params, - ) as Promise; + + if (params && params['symbols'] && Array.isArray(params['symbols'])) { + const symbols = (params as SymbolArrayParam).symbols; + const symbolsQueryParam = JSON.stringify(symbols); + + return this.get( + 'api/v3/ticker/24hr?symbols=' + symbolsQueryParam, + ) as Promise; + } + + return this.get('api/v3/ticker/24hr') as Promise; } getSymbolPriceTicker( diff --git a/src/types/shared.ts b/src/types/shared.ts index 3322843a..438198cf 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -84,6 +84,10 @@ export interface BasicSymbolParam { isIsolated?: StringBoolean; } +export interface SymbolArrayParam { + symbols: string[]; +} + export interface BasicAssetPaginatedParams { asset?: string; startTime?: number; From 11a13479b5e32089f10e34f4d03737914d2c2655 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Thu, 7 Dec 2023 10:50:17 +0000 Subject: [PATCH 2/3] chore(): minor fixes --- examples/rest-spot-public.ts | 2 +- src/main-client.ts | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/rest-spot-public.ts b/examples/rest-spot-public.ts index d52c4b01..a8f1a556 100644 --- a/examples/rest-spot-public.ts +++ b/examples/rest-spot-public.ts @@ -29,7 +29,7 @@ const client = new MainClient({ }); console.log('getTickers many', manyTickers); const allTickers = await client.get24hrChangeStatististics(); - console.log('getTickers all'); + console.log('getTickers all', allTickers); } catch (e) { console.error('request failed: ', e); } diff --git a/src/main-client.ts b/src/main-client.ts index 7f56b27a..06d2ee8b 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -765,22 +765,17 @@ export class MainClient extends BaseRestClient { params?: Partial | Partial, ): Promise { if (params && typeof params['symbol'] === 'string') { - return this.get( - 'api/v3/ticker/24hr', - params, - ) as Promise; + return this.get('api/v3/ticker/24hr', params); } if (params && params['symbols'] && Array.isArray(params['symbols'])) { const symbols = (params as SymbolArrayParam).symbols; const symbolsQueryParam = JSON.stringify(symbols); - return this.get( - 'api/v3/ticker/24hr?symbols=' + symbolsQueryParam, - ) as Promise; + return this.get('api/v3/ticker/24hr?symbols=' + symbolsQueryParam); } - return this.get('api/v3/ticker/24hr') as Promise; + return this.get('api/v3/ticker/24hr'); } getSymbolPriceTicker( From e88973b9e0271d2738d5ad0c882f92e5a7b6bd64 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Thu, 7 Dec 2023 11:11:43 +0000 Subject: [PATCH 3/3] chore(): bigger resource class --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d30bc689..3a7eb65f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,8 @@ jobs: docker: - image: cimg/node:15.1 # resource_class: tiagosiebler/localcirunner + # The resource_class feature allows configuring CPU and RAM resources for each job. Different resource classes are available for different executors. https://circleci.com/docs/2.0/configuration-reference/#resourceclass + resource_class: large steps: - checkout - restore_cache: