node-yahoo-finance2
node-yahoo-finance2 copied to clipboard
[docs] How to override fetch
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:
-
Without any overrides, we'll use
globalThis.fetchat request time. Note: this differs from earlier behaviour where we'd save a ref during module load (v2) / instantiation time (<v3.6). -
Specify a custom fetch at instantiation time.
const yahooFinance = new YahooFinance({ fetch: customFetch }) -
Custom fetch after instantiation time (unstable API, don't rely on this)
yahooFinance._env.fetch = customFetch; // Probably won't stay around -
Custom fetch per request
yahooFinance.quote(symbol, quoteOpts, { fetch: customFetch })