node-yahoo-finance2 icon indicating copy to clipboard operation
node-yahoo-finance2 copied to clipboard

[docs] How to override fetch

Open gadicc opened this issue 5 months ago • 0 comments

Document how to ovverride fetch and when this might be useful (e.g. give a fetch-mock-cache example).

See commit https://github.com/gadicc/node-yahoo-finance2/commit/ea002e14ede0fbc61ceaed44c061f56e5ef79ef8.

Related: #923

Need to decide where to and how to best document all this but basically, as of now:

  1. Without any overrides, we'll use globalThis.fetch at request time. Note: this differs from earlier behaviour where we'd save a ref during module load (v2) / instantiation time (<v3.6).

  2. Specify a custom fetch at instantiation time.

    const yahooFinance = new YahooFinance({ fetch: customFetch })
    
  3. Custom fetch after instantiation time (unstable API, don't rely on this)

    yahooFinance._env.fetch = customFetch; // Probably won't stay around
    
  4. Custom fetch per request

    yahooFinance.quote(symbol, quoteOpts, { fetch: customFetch })
    

gadicc avatar Aug 11 '25 14:08 gadicc