* fix circular import issues on the obbject extension framework * settings available on the obbject * extension init * charting assets and code * introduce to_chart functionality * removes the to_chart method from obbject in detriment of the one from the obbject extension * Update openbb_platform/obbject_extensions/charting/charting/__init__.py Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * fix on the show method * adding the example to the to_chart docstring * copying the exsting README from charting extension - needs to be revamped * moving to openbb_charting instead * update the pyproject.toml file * pydocstyle * versions * better docstrings * making accessors public * removing unnecessary credentials variable cc @montezdesousa * removing access to extra/metadata and use designated private attrs instead * Fixes linting for the logging service (#5992) * lints * typing.Type instead * deprecating ChartingService to use the new extension instead - adding function discovery capabilities using it * tests for the obbject charting extension * removing charting service from command runner * filter functions not implemented in the module * remove charting service tests * removing charting service on the tests for int tests * charting integration tests * removing charting service file * removing old charting extension code * revamp builder * fix obbject tests * fix command_runner tests * removing openbb_figure_table * better website docs * reviewed readme * unsetting api key for posthog (pywry) windows * added debug_mode to the system settings * removing api key * update nightly script * fix tests * black * black * Revert "black" This reverts commit21d76ad689. * Revert "black" This reverts commit0904653fd7. * black for henrique * returning a list instead * better docstrings * removing unnecessary indicators docstring * typo * black * intentional access to protected member * changes to publish script * filtering deleted files * black * adding render argument * fixing the df_to_basemodel function: it should include the index in the columns either if flagged or if the index is named * adding the hability to add you own data to to_chart method * tests * black * disable protected access * accept kwargs to eg. save image * adjustment cc Igor * add if statement for protection * remove unused return typing * fix technical charting views * better error message cc @IgorWounds * better structure and fix test * Revert "better structure and fix test" This reverts commit612ea6117c. * Revert "better error message cc @IgorWounds" This reverts commit3d7ee53878. --------- Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
5.0 KiB
Vendored
OpenBB Charting extension
This extension provides a charting library for OpenBB Platform.
The library includes:
- a charting infrastructure based on Plotly
- a set of charting components
- prebuilt charts for a set of commands that are built-in OpenBB extensions
Note
The charting library is an
OBBjectextension which means you'll have the functionality it exposes on every command result.
Installation
To install the extension, run the following command in this folder:
pip install openbb-charting
PyWry dependency on Linux
The PyWry dependency handles the display of interactive charts and tables in a separate window. It is installed automatically with the OpenBB Charting extension.
When using Linux distributions, the PyWry dependency requires certain dependencies to be installed first.
-
Debian-based / Ubuntu / Mint:
sudo apt install libwebkit2gtk-4.0-dev -
Arch Linux / Manjaro:
sudo pacman -S webkit2gtk -
Fedora:
sudo dnf install gtk3-devel webkit2gtk3-devel
Usage
To use the extension, run any of the OpenBB Platform endpoints with the chart argument set to True.
Here's an example of how it would look like in a python interface:
from openbb import obb
equity_data = obb.equity.price.historical(symbol="TSLA", chart=True)
This results in a OBBject object containing a chart attribute, which contains Plotly JSON data.
In order to display the chart, you need to call the show() method:
equity_data.show()
Note: The
show()method currently works either in a Jupyter Notebook or in a standalone python script with a PyWry based backend properly initialized.
Alternatively, you can use the fact that the openbb-charting is an OBBject extension and use its available methods.
from openbb import obb
res = obb.equity.price.historical("AAPL")
res.charting.show()
The above code will produce the same effect as the previous example.
Discovering available charts
Not all the endpoints are currently supported by the charting extension. To discover which endpoints are supported, you can run the following command:
from openbb_charting import Charting
Charting.functions()
Using the to_chart method
The to_chart function should be taken as an advanced feature, as it requires the user to have a good understanding of the charting extension and the OpenBBFigure class.
The user can use any number of **kwargs that will be passed to the PlotlyTA class in order to build custom visualizations with custom indicators and similar.
Note that, this method will only work to some limited extent with data that is not standardized. Also, it is currently designed only to handle time series (OHLCV) data.
Example usage:
-
Plotting a time series with TA indicators
from openbb import obb res = obb.equity.price.historical("AAPL") indicators = dict( sma=dict(length=[20,30,50]), adx=dict(length=14), rsi=dict(length=14), macd=dict(fast=12, slow=26, signal=9), bbands=dict(length=20, std=2), stoch=dict(length=14), ema=dict(length=[20,30,50]), ) res.charting.to_chart(**{"indicators": indicators}) -
Get all the available indicators
# if you have a command result already res.charting.indicators # or if you want to know in standalone fashion from openbb_charting import Charting Charting.indicators()
Add a visualization to an existing Platform command
One should first ensure that the already implemented endpoint is available in the charting router.
To do so, you can run:
python openbb_platform/obbject_extensions/charting/openbb_charting/builder.py - which will read all the available endpoints and add them to the charting router.
Afterwards, you'll need to add the visualization to the [charting router]. The convention to match the endpoint with the respective charting function is the following:
/equity/price/historical->equity_price_historical/technical/ema->technical_ema
When you spot the charting function on the charting router file, you can add the visualization to it.
The implementation should leverage the already existing classes and methods to do so, namely:
OpenBBFigurePlotlyTA
Note that the return of each charting function should respect the already defined return types: Tuple[OpenBBFigure, Dict[str, Any]].
The returned tuple contains a OpenBBFigure that is an interactive plotly figure which can be used in a Python interpreter, and a Dict[str, Any] that contains the raw data leveraged by the API.
After you're done implementing the charting function, you can use either the Python interface or the API to get the chart. To do so, you'll only need to set the already available chart argument to True.
Or accessing the charting attribute of the OBBject object: my_obbject.charting.show().