From 4bba5c2bbd8d18817802e87a12466b3afaa3e7fe Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 24 Nov 2022 09:37:42 +0000 Subject: [PATCH] improve crypto.candle --- .../cryptocurrency/cryptocurrency_helpers.py | 36 +++++++++++++++---- .../miscellaneous/library/trail_map.csv | 2 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py index 8c86ab45ed9..3ab2a46cb62 100644 --- a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py +++ b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py @@ -785,7 +785,8 @@ def plot_chart( prices_df["Volume"] = prices_df["Volume"] / 1_000_000 plot_candles( - candles_df=prices_df, + symbol=to_symbol, + data=prices_df, title=title, volume=True, ylabel="Volume [1M]" if volume_mean > 1_000_000 else "Volume", @@ -797,7 +798,14 @@ def plot_chart( def plot_candles( - candles_df: pd.DataFrame, + symbol: str, + data: pd.DataFrame = pd.DataFrame(), + start_date: Union[datetime, Union[str, None]] = None, + end_date: Union[datetime, Union[str, None]] = None, + interval: Union[str, int] = "1440", + exchange: str = "binance", + vs_currency: str = "usdt", + source: str = "CCXT", volume: bool = True, ylabel: str = "", title: str = "", @@ -808,7 +816,9 @@ def plot_candles( Parameters ---------- - candles_df: pd.DataFrame + symbol: str + Ticker name + data: pd.DataFrame Dataframe containing time and OHLCV volume: bool If volume data shall be plotted, by default True @@ -821,6 +831,18 @@ def plot_candles( yscale : str Scaling for y axis. Either linear or log """ + + if data.empty: + data = load( + symbol=symbol, + start_date=start_date, + end_date=end_date, + interval=interval, + exchange=exchange, + vs_currency=vs_currency, + source=source, + ) + candle_chart_kwargs = { "type": "candle", "style": theme.mpf_style, @@ -844,16 +866,16 @@ def plot_candles( candle_chart_kwargs["figratio"] = (10, 7) candle_chart_kwargs["figscale"] = 1.10 candle_chart_kwargs["figsize"] = plot_autoscale() - fig, ax = mpf.plot(candles_df, **candle_chart_kwargs) + fig, ax = mpf.plot(data, **candle_chart_kwargs) fig.suptitle( - f"\n{title}", + f"\n{symbol if title == '' else title}", horizontalalignment="left", verticalalignment="top", x=0.05, y=1, ) - lambda_long_number_format_y_axis(candles_df, "Volume", ax) + lambda_long_number_format_y_axis(data, "Volume", ax) if yscale == "log": ax[0].yaxis.set_major_formatter(ScalarFormatter()) ax[0].yaxis.set_major_locator( @@ -874,7 +896,7 @@ def plot_candles( candle_chart_kwargs["ax"] = ax - mpf.plot(candles_df, **candle_chart_kwargs) + mpf.plot(data, **candle_chart_kwargs) def plot_order_book( diff --git a/openbb_terminal/miscellaneous/library/trail_map.csv b/openbb_terminal/miscellaneous/library/trail_map.csv index 4cbe28b3fc2..b37a142f115 100644 --- a/openbb_terminal/miscellaneous/library/trail_map.csv +++ b/openbb_terminal/miscellaneous/library/trail_map.csv @@ -507,7 +507,7 @@ crypto.load,openbb_terminal.cryptocurrency.cryptocurrency_helpers.load, crypto.price,openbb_terminal.cryptocurrency.pyth_model.get_price, crypto.find,openbb_terminal.cryptocurrency.crypto_models.find, crypto.chart,openbb_terminal.cryptocurrency.cryptocurrency_helpers.plot_chart, -crypto.candles,openbb_terminal.cryptocurrency.cryptocurrency_helpers.plot_candles, +crypto.candle,openbb_terminal.cryptocurrency.cryptocurrency_helpers.plot_candles, etf.candle,openbb_terminal.stocks.stocks_helper.display_candle, forex.candle,openbb_terminal.forex.forex_helper.display_candle, forex.load,openbb_terminal.forex.forex_helper.load,