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

[BugFix] Make User Preferences -> Defaults Work With Any Parameter #6687

Merged
merged 16 commits into from
Oct 3, 2024

Conversation

deeleeramone
Copy link
Contributor

@deeleeramone deeleeramone commented Sep 23, 2024

  1. Why?:

    • The "defaults" section of the user_settings.json was not able to cope with anything other than "provider".
    • The app fails to import if the defaults configuration is incorrect.
  2. What?:

  3. Impact:

    • Improved configurability.
    • The API only partially supports this behavior because all mandatory fields need to be supplied to the URL.
  4. Testing Done:

    • Ran integration tests and have not found unexpected behavior.

User Settings:

{
  "defaults": {
    "commands": {
      "/equity/price/historical": {
        "provider": "yfinance",
        "chart": true,
        "chart_params": {
          "heikin_ashi": true,
          "indicators": {
            "sma": {
              "length": [21, 50]
            },
            "ema": {
              "length": 150
            }
          }
        }
      }
    }
  }
}

Before:

from openbb import obb
ValidationError: 2 validation errors for UserSettings
defaults.commands.`equity.price.historical`.chart
  Input should be a valid list [type=list_type, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.9/v/list_type
defaults.commands.`equity.price.historical`.chart_params
  Input should be a valid list [type=list_type, input_value={'heikin_ashi': True, 'in...'ema': {'length': 150}}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.9/v/list_type

After:

from openbb import obb

res = obb.equity.price.historical(symbol="AAPL")
res.show()

image

@deeleeramone deeleeramone added bug Fix bug platform OpenBB Platform labels Sep 23, 2024
@github-actions github-actions bot added v4 PRs for v4 labels Sep 23, 2024
Copy link
Contributor

@hjoaquim hjoaquim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm; the chart args are such a cool example on how this works well.
Also, extrapolates perfectly to the cli!

image

I don't have any suggesitons code-wise.

Only thing (you're probably aware of) are the warning this is raising:

image

@@ -37,7 +57,7 @@ def _check_credentials(self, provider: str) -> Optional[bool]:
return all(getattr(credentials, r, None) for r in required)

def _get_provider(
self, choice: Optional[str], command: str, default_priority: Tuple[str, ...]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the idea that this (not using typing's type hints) would break on 3.9 envs, but it didn't, probably a 3.8 thing 😀

Copy link
Contributor

@IgorWounds IgorWounds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the warnings @hjoaquim mentioned, this looks good!

@deeleeramone
Copy link
Contributor Author

Aside from the warnings @hjoaquim mentioned, this looks good!

Warnings are coming from the pandas_ta library, so there is not much we can do directly.

@deeleeramone deeleeramone added this pull request to the merge queue Oct 3, 2024
Merged via the queue into develop with commit fe16bc3 Oct 3, 2024
10 checks passed
@IgorWounds IgorWounds deleted the bugfix/defaults-preferences branch October 8, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fix bug platform OpenBB Platform v4 PRs for v4
Projects
None yet
4 participants