From c71acfeb83eeb2a1dc4bd0ae28b136f50bbec040 Mon Sep 17 00:00:00 2001 From: Mehrdad Mirsamie Date: Thu, 2 Mar 2023 11:49:27 +0330 Subject: [PATCH 1/2] feature/add-fetch-client-to-options --- index.d.ts | 1 + src/http-client.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index e14f9ca1..95776049 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,6 +9,7 @@ declare module 'binance-api-node' { wsBase?: string wsFutures?: string proxy?: string + fetch?: unknown }): Binance export type ErrorCodes_LT = diff --git a/src/http-client.js b/src/http-client.js index 7156d6a1..fa44882c 100644 --- a/src/http-client.js +++ b/src/http-client.js @@ -5,6 +5,7 @@ import JSONbig from 'json-bigint' import 'isomorphic-fetch' +let fetchClient = fetch; const BASE = 'https://api.binance.com' const FUTURES = 'https://fapi.binance.com' const COIN_FUTURES = 'https://dapi.binance.com' @@ -121,7 +122,7 @@ const checkParams = (name, payload, requires = []) => { */ const publicCall = ({ proxy, endpoints }) => (path, data, method = 'GET', headers = {}) => { return sendResult( - fetch( + fetchClient( `${ path.includes('/fapi') || path.includes('/futures') ? endpoints.futures @@ -194,7 +195,7 @@ const privateCall = ({ const newData = noExtra ? data : { ...data, timestamp, signature } return sendResult( - fetch( + fetchClient( `${ path.includes('/fapi') || path.includes('/futures') ? endpoints.futures @@ -333,6 +334,8 @@ export default opts => { delivery: (opts && opts.httpDelivery) || COIN_FUTURES, } + fetchClient = fetch || opts.fetch; + const pubCall = publicCall({ ...opts, endpoints }) const deliveryPubCall = publicCall({ ...opts, endpoints: { futures: endpoints.delivery } }) const privCall = privateCall({ ...opts, endpoints, pubCall }) From 5f695dd2e9640e39ac1bae5f88209b87337c7875 Mon Sep 17 00:00:00 2001 From: Mehrdad Mirsamie Date: Thu, 2 Mar 2023 12:33:17 +0330 Subject: [PATCH 2/2] override fetch client --- index.d.ts | 2 +- src/http-client.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 95776049..5570aa0c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,7 +9,7 @@ declare module 'binance-api-node' { wsBase?: string wsFutures?: string proxy?: string - fetch?: unknown + fetchClient?: unknown }): Binance export type ErrorCodes_LT = diff --git a/src/http-client.js b/src/http-client.js index fa44882c..08c09d6e 100644 --- a/src/http-client.js +++ b/src/http-client.js @@ -334,7 +334,8 @@ export default opts => { delivery: (opts && opts.httpDelivery) || COIN_FUTURES, } - fetchClient = fetch || opts.fetch; + // overriding the fetch client if available in options + fetchClient = opts.fetchClient || fetch; const pubCall = publicCall({ ...opts, endpoints }) const deliveryPubCall = publicCall({ ...opts, endpoints: { futures: endpoints.delivery } })