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

Set global defaults

Open gadicc opened this issue 3 years ago • 3 comments

Feature Request

Wanted Feature

A recommended method to set global defaults.

Use Cases

Currently we can override defaults per request. But's a bit weird for things like the queue, which affects all past and future requests too.

Potential Example Usage

// with run-time validation
yahooFinance.setConfig({ ... });

// perhaps to be clearer about what's a default for future requests
yahooFinance.setDefault({});

Timeline

  • [X] API (#133) - thanks @PythonCreator27
  • [ ] Update docs that mention _opts
  • [ ] Docs to explain difference between global options and global defaults? (e.g. queue opts are global opts, but maybe we have some fetch opts that are defaults used for each request and can be overriden)
  • [ ] Change behaviour in yf.* funcs that any overrides should be just for that call, and should throw an error if trying to override a global option (like the queue, this isn't really make sense, as there is only one queue for all requests). NB: this WOULD be a breaking change but since the queue code is still only in devel and has not been released, we're all good!

gadicc avatar Apr 12 '21 10:04 gadicc

@gadicc I absolutely agree. It would just involve setting properties on _opts, right? If so, I can send a PR soon.

advaiyalad avatar Apr 12 '21 12:04 advaiyalad

I think that setConfig makes more sense, as it is more clear about what is being set. Maybe setGlobalConfig would be better?

advaiyalad avatar Apr 12 '21 19:04 advaiyalad

Would it make more sense to override the default config, or just merge them? I would go with merging, as it is usually a more predictable behavior. What do you think, @gadicc?

advaiyalad avatar Apr 12 '21 19:04 advaiyalad