Files
OpenBB/website/content/platform/development/developer-guidelines/obbject.md
Danglewood c047cfeddd docs/new-working-docs: New working docs branch (#5768)
* move old example notebooks to v3 folder, update loadHistoricalPriceData and add findSymbols

* Create README.md

* Update README.md

* Update README.md

* Update README.md

* Vertical diagram instead

* important classes

* core dependencies

* folder structure

* devtools

* swap order

* fix github pages deploy issue

* development index

* delete expectations for developers

* devtools

* obbject stuff

* add

* installation

* hub sync

* idk if i committed already

* add usage page for financial statements

* add link to reference page

* syntax

* numbers

* nearly --> more than

* easier to read code blocks

* codespell

* removing mention to provider

* add 'orientation' for to_dict

* info card for output user preference

* put it in a code block

* correct user_settings.json example

* syntax corrections

* fix sentence

* get rid of floating point mathc

* get rid of other floating point math

* add companion example notebook for financial statements, and new section

* historical prices usage page

* codespell

* add commitment of traders section to usage

* add a note

* codespell

* get rid of equals sign

* Cleanup docs. with @the-praxs

* install

* obbject extend

* spell

* HeadTitle thingies

* Update obbject_extensions.md

* Update obbject_extensions.md

* typo

* Update architectural_considerations.md

* point to the TET pattern

* optional vs required

* reviewing the  patterns. removed the --pre flag under the assumption this will be the final docs for the release cc @deeleeramone

* add a walkthrough

* spelling

* Add more in the introduction

* validator examples

* update Copper-to-Gold notebook example for V4

* Update README.md

* QA Caveats w @the-praxs

* info on class outputs

* merge add data sources and add data points

* disclaimer on cookiecutter

* add missing import to example

* slight syntax change

* missing code block

* missing import

* update intrinio example syntax

* intrinio syntax update

* urls

* core and provider merged

* example syntax

* grammar

* Update API banner link

* quick-fix-docs cc @minhhoang1023

* Update pip install command for v3

* remove --pre note block

* update landing image

---------

Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: Luqman <luqazino@gmail.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
2023-12-01 01:09:25 +00:00

4.5 KiB
Vendored

title, sidebar_position, description, keywords
title sidebar_position description keywords
OpenBB OBBject 7 This page provides information about the OBBject class in the OpenBB Platform. This class provides the interface to interact with commands
OBBject
Python
Development
OpenBB Platform
Results
Commands
Pandas
DataFrame
Polars
Numpy

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

The OBBject (OpenBB Object) is at the heart of developing around the OpenBB Platform. Every command will return this class as the command output. This class contains the following attributes:

  • results
    • This contains serializable data that was obtained by running the command.
  • provider
    • The name of the provider that was used to obtain the data.
  • Warnings
    • Any warnings that were generated by the command.
  • Extra
    • Additional metadata about the command run, including any arguments, the route, the timestamp, etc.

Example

In the python interface, the OBBject class is returned by every command. The following example shows how to access the results of a command:

from openbb import obb

obbject = obb.equity.price.historical("AAPL", provider="fmp")

display(obbject)
OBBject

id: 0655d06a-8797-7310-8000-4daaa1d47936
results: [{'date': datetime.datetime(2023, 11, 21, 0, 0), 'open': 191.41, 'high': 1...
provider: fmp
warnings: None
chart: None
extra: {'metadata': {'arguments': {'provider_choices': {'provider': 'fmp'}, 'standa...

The output type is <class 'openbb_core.app.model.obbject.OBBject'>.

If we look at the results attribute, we see that we are returned a list of the Data models used, i.e

obbject.results[0]
FMPEquityHistoricalData(date=2023-11-21 00:00:00, open=191.41, high=191.5, low=189.74, close=190.375, volume=24029603, vwap=190.54, label=November 21, 23, adj_close=190.375, unadjusted_volume=24029603.0, change=-1.03, change_percent=-0.5407241, change_over_time=-0.005407241)

In general, this will not be how you want to ingest or modify your data, so to help with this we have provided some methods.

OBBject Methods

We understand that there is no one size fits all solution for data ingestion and manipulation, so we have provided a few methods to help with this and handle the conversion from Obbject to your preferred data type. These methods are accessed by running obbject.<method>.

to_dataframe()

One of the most popular libraries for python data manipulation, this method will return a pandas dataframe with the results. We have designed this function to work with various data structures we have encountered. Given the time series nature of the data, we set the index to be date if that column appears in the models.

This also has the shorter alias to_df().

type(obb.equity.price.historical("AAPL", provider="fmp").to_dataframe())
<class 'pandas.core.frame.DataFrame'>

to_dict(orient)

A very common data structure is to return the data in a dictionary. This model provides an interface to do so, with options to return the dictionary in different orientations, just as in the pandas to_dict() method. The default method will return a dictionary that allows you to index to obtain data:

to_dict = obb.equity.price.historical("AAPL", provider="fmp").to_dict()["open"][:10]
[150.16, 148.13, 149.45, 148.31, 145.14, 144.29, 141.4, 148.21, 145.96, 147.77]

Orienting as records will give you a list of dictionaries, commonly used in JSON data structures:

obb.equity.price.historical("AAPL", provider="fmp").to_dict("records")[0]
{'open': 144.29,
'high': 144.81,
'low': 140.35,
'close': 141.17,
'volume': 83763800,
'vwap': 142.11,
'label': 'November 29, 22',
'adj_close': 140.39,
'unadjusted_volume': 83763800.0,
'change': -3.12,
'change_percent': -2.16,
'change_over_time': -0.0216}

Others

In addition to these two highly used methods, we have also provided the following methods:

to_numpy()

Returns numpy arrays of the results. Note that this loses the column names, so you will need to index the array to obtain the data.

to_polars()

Growing in popularity, polars is a blazingly fast dataframe library. This method will return a polars dataframe. Note that we do not include polars in the core dependency tree, so it needs to be installed separately.


More information can be found on the OpenBB Core Readme