diff --git a/index.d.ts b/index.d.ts index e14f9ca1..5570aa0c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,6 +9,7 @@ declare module 'binance-api-node' { wsBase?: string wsFutures?: string proxy?: string + fetchClient?: unknown }): Binance export type ErrorCodes_LT = diff --git a/src/http-client.js b/src/http-client.js index 7156d6a1..08c09d6e 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,9 @@ export default opts => { delivery: (opts && opts.httpDelivery) || COIN_FUTURES, } + // 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 } }) const privCall = privateCall({ ...opts, endpoints, pubCall })