From e39b7fedf2368bf9dc06f293bbc86d4c9f290186 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Wed, 6 Sep 2023 13:05:56 +0100 Subject: [PATCH] small adjustments --- .../charting/openbb_charting/core/to_chart.py | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/openbb_sdk/extensions/charting/openbb_charting/core/to_chart.py b/openbb_sdk/extensions/charting/openbb_charting/core/to_chart.py index f707a6aaab2..0bb1a81af6d 100644 --- a/openbb_sdk/extensions/charting/openbb_charting/core/to_chart.py +++ b/openbb_sdk/extensions/charting/openbb_charting/core/to_chart.py @@ -44,20 +44,25 @@ def to_chart( Returns ------- - str - Plotly json representation of the chart. + Tuple[OpenBBFigure, Dict[str, Any]] + Tuple containing the OpenBBFigure and the plotly json representation of the chart. """ - ta = PlotlyTA(charting_settings=charting_settings) - fig = ta.plot( - df_stock=data, - indicators=indicators, - symbol=symbol, - candles=candles, - volume=volume, - prepost=prepost, - volume_ticks_x=volume_ticks_x, - ) - content = fig.show(external=True).to_plotly_json() + try: + ta = PlotlyTA(charting_settings=charting_settings) + fig = ta.plot( + df_stock=data, + indicators=indicators, + symbol=symbol, + candles=candles, + volume=volume, + prepost=prepost, + volume_ticks_x=volume_ticks_x, + ) + content = fig.show(external=True).to_plotly_json() - return fig, content + return fig, content + except Exception as e: + raise Exception( + f"Failed to convert results to chart. Ensure the provided data is a valid time series. {e}" + ) from e