Package: openbb-charting
OpenBB Charting extensionThis extension provides a charting library for OpenBB Platform.The library includes:a charting infrastructure based on Plotlya set of charting componentsprebuilt charts for a set of commands that are built-in OpenBB extensions[!NOTE]
The charting library is anOBBjectextensionwhich means you'll have the functionality it exposes on every command result.InstallationTo install the extension, run the following command in this folder:pipinstallopenbb-chartingPyWry dependency on LinuxThe 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-devArch Linux / Manjaro:sudo pacman -S webkit2gtkFedora:sudo dnf install gtk3-devel webkit2gtk3-develUsageTo use the extension, run any of the OpenBB Platform endpoints with thechartargument set toTrue.Here's an example of how it would look like in a python interface:fromopenbbimportobbequity_data=obb.equity.price.historical(symbol="TSLA",chart=True)This results in aOBBjectobject containing achartattribute, which contains Plotly JSON data.In order to display the chart, you need to call theshow()method:equity_data.show()Note: Theshow()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 theopenbb-chartingis anOBBjectextension and use its available methods.fromopenbbimportobbres=obb.equity.price.historical("AAPL")res.charting.show()The above code will produce the same effect as the previous example.Discovering available chartsNot all the endpoints are currently supported by the charting extension. To discover which endpoints are supported, you can run the following command:fromopenbb_chartingimportChartingCharting.functions()Using theto_chartmethodTheto_chartfunction should be taken as an advanced feature, as it requires the user to have a good understanding of the charting extension and theOpenBBFigureclass.The user can use any number of**kwargsthat will be passed to thePlotlyTAclass 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 indicatorsfromopenbbimportobbres=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 alreadyres.charting.indicators# or if you want to know in standalone fashionfromopenbb_chartingimportChartingCharting.indicators()Add a visualization to an existing Platform commandOne should first ensure that the already implemented endpoint is available in thecharting 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_emaWhen 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:OpenBBFigurePlotlyTANote that the return of each charting function should respect the already defined return types:Tuple[OpenBBFigure, Dict[str, Any]].The returned tuple contains aOpenBBFigurethat is an interactive plotly figure which can be used in a Python interpreter, and aDict[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 availablechartargument toTrue.
Or accessing thechartingattribute of theOBBjectobject:my_obbject.charting.show().