Files
OpenBB/website/content/platform/usage/basic_response.md
Danglewood 657fd1fbcc [Docs] Break Out Usage Section In Docs Pages (#6258)
* break out the Usage section in docs pages

* codespell
2024-03-27 13:12:54 +00:00

3.8 KiB
Vendored

title, sidebar_position, description, keywords
title sidebar_position description keywords
Basic Response & Command Coverage 4 This page details the basic response and output that can be expected to be received from the the OpenBB Platform, as well as instructions for determining the command coverage provided by the installed extensions.
standardized output
OBBject
basic response
provider
results
warnings
chart
extra
command coverage

import HeadTitle from '@site/src/components/General/HeadTitle.tsx';

The output of every command is an object which contains the results of the request, along with additional information. It is a custom class, OBBject, and always returns with the fields listed below:

id: ...                 # UUID Tag
results: ...            # Serializable results.
provider: ...           # Provider name.
warnings: ...           # List of warnings.
chart: ...              # Chart object.
extra: ...              # Extra info.
from openbb import obb

data = obb.equity.price.historical("SPY", provider="polygon")

data
OBBject

id: 06520558-d54a-7e53-8000-7aafc8a42694
results: [{'date': datetime.datetime(2022, 10, 5, 0, 0), 'open': 375.62, 'high': 37...
provider: polygon
warnings: None
chart: None
extra: {'metadata': {'arguments': {'provider_choices': {'provider': 'polygon'}, 'st...

Additional class methods are helpers for converting the results to a variety of formats.

  • to_dict(): converts to a dictionary, accepting all standard "orientation" parameters, i.e., "records"
  • to_df() / to_dataframe(): converts to a Pandas DataFrame.
  • to_numpy(): converts to a Numpy array.
  • to_polars(): converts to a Polars table.

The output from the Fast API is a serialized version of this object, and these methods are lost on conversion. OBBject can be reconstructed to recover the helpers by importing the model and validating the data.

import requests
from openbb_core.app.model.obbject import OBBject

data = []
symbol="SPY"
url = f"http://127.0.0.1:8000/api/v1/equity/price/historical?provider=polygon&symbol={symbol}"
headers = {"accept": "application/json"}

response = requests.get(url, headers=headers, timeout=3)

if response.status_code == 200:
  data = OBBject.model_validate(response.json())

data.to_df()

:::info The preferred output type can be set with a user preference.

obb.user.preferences.output_type="dataframe"

:::

Dynamic Command Execution

Dynamic execution provides an alternate entry point to functions. This method requires formatting the query as demonstrated below.

from openbb_core.app.command_runner import CommandRunner
runner = CommandRunner()
output = await runner.run(
    "/equity/fundamental/ratios",
    provider_choices={
        "provider": "fmp",
    },
    standard_params={
        "symbol" : "TSLA",
        "period" : "quarter",
    },
    extra_params={}
)
>>> output
OBBject

id: 065241b7-bd9d-7313-8000-9406d8afab75
results: [{'symbol': 'TSLA', 'date': '2023-06-30', 'period': 'Q2', 'current_ratio':...
provider: fmp
warnings: None
chart: None
extra: {'metadata': {'arguments': {'provider_choices': {'provider': 'fmp'}, 'standa...

Commands and Provider Coverage

The installed commands and data providers are found under, obb.coverage.

obb.coverage
/coverage

    providers
    commands
    command_model
    command_schemas

obb.coverage.providers is a dictionary of the installed provider extensions, each with its own list of available commands.

obb.coverage.commands is a dictionary of commands, each with its own list of available providers for the data.

obb.coverage.command_model is a dictionary where the keys are the command paths and the values is a nested dictionary of QueryParams and Data models associated with that function.