Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferred data source for a given command and help docs for any command #1928

Merged

Conversation

stkerr
Copy link
Contributor

@stkerr stkerr commented Jun 10, 2022

Description

  • Summary of the change / bug fix.
  • Link # issue, if applicable.
  • Screenshot of the feature or the bug before/after fix, if applicable.
  • Relevant motivation and context.
  • List any dependencies that are required for this change.

This PR adds a new feature settings under /settings called preferred_data_source_file. It is defaulted to sources.json. This PR updates the /stocks/load command to use the preferred data source if one is not specified explicitly.

This PR also introduces a new helper function called get_preferred_source which can be used to retrieve the preferred value for a given command. If a specific value is not present, the function wlll return the most specific preference as possible, eventually resulting in the default value. In practice, this means a call like get_preferred_source("stocks.subcommand.subsubcommand") will return first the value for stocks.subcommand.subsubcommand, then stocks.subcommand["default"], then stocks["default"], then eventually the root-level ["default"] value.

This is intended to allow different parts of Terminal to know what data source the user wants to use and then they can take action based on that. The individual commands implemented will be responsible for examining and respecting this value.

In the future, this can be used to change the logic inside of various functions depending on which data source the user prefers, rather than hardcoding to Yahoo finance as is currently done in several parts of the Terminal. As various other data sources, such as new brokers, are added, users can select those as their preferred data source instead of Yahoo.

How has this been tested?

Existing pytests were run successfully.

Several manual runs to change the values in the source file and then run the load command were done.

Checklist:

Others

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My code passes all the checks pylint, flake8, black, ... To speed up development you should run pre-commit install.
  • New and existing unit tests pass locally with my changes. You can test this locally using pytest tests/....

@stkerr stkerr force-pushed the stkerr-preferred-data-provider-setting branch from be03fe8 to 26c6414 Compare June 10, 2022 19:59
@jmaslek jmaslek added the feat S Small T-Shirt size Feature label Jun 10, 2022
@stkerr stkerr changed the title Add a feature flag loaded from . env for preferred data source Add a feature setting for preferred data source Jun 10, 2022
@DidierRLopes
Copy link
Collaborator

Hey @stkerr ,

I am currently away until next week, but this is something I wanted for us to tackle in a more generic way.

I was thinking about doing something along the lines of having a file with:

{
    'stocks/load': 'yf',
    'crypto/load`: 'cg',
    ....
}

And adding a command to access this file and change it in settings. Something where we could do:
source --cmd stocks/load --value av to change 1 value
source to display the dictionary in a nice way

Thoughts?

@stkerr stkerr changed the title Add a feature setting for preferred data source Add routines to retrieve preferred data source for a given command Jun 11, 2022
@stkerr stkerr force-pushed the stkerr-preferred-data-provider-setting branch from 1cf700a to ce29e6e Compare June 11, 2022 20:52
@stkerr stkerr marked this pull request as ready for review June 12, 2022 16:07
@stkerr stkerr force-pushed the stkerr-preferred-data-provider-setting branch from 2600a1b to f677e31 Compare June 13, 2022 15:14
@DidierRLopes DidierRLopes changed the title Add routines to retrieve preferred data source for a given command Preferred data source for a given command and help docs for any command Jun 14, 2022
@Chavithra Chavithra merged commit 497324d into OpenBB-finance:main Jun 14, 2022
@stkerr stkerr deleted the stkerr-preferred-data-provider-setting branch June 14, 2022 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat L Large T-Shirt size Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants