From 508066d2515798d4593dec35b9ec41bc06fce3d8 Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:44:34 -0700 Subject: [PATCH 1/3] fix options hist to display date column when raw is True --- .../stocks/options/chartexchange_model.py | 3 +- .../stocks/options/chartexchange_view.py | 40 +++++++++++-------- .../stocks/options/intrinio_view.py | 2 + .../stocks/options/options_controller.py | 1 + .../stocks/options/tradier_view.py | 2 + .../stocks/options/test_chartexchange_view.py | 12 ++---- .../test_display_raw[False].txt | 12 ------ 7 files changed, 34 insertions(+), 38 deletions(-) diff --git a/openbb_terminal/stocks/options/chartexchange_model.py b/openbb_terminal/stocks/options/chartexchange_model.py index b6cb847d7637..f1e4234ec187 100644 --- a/openbb_terminal/stocks/options/chartexchange_model.py +++ b/openbb_terminal/stocks/options/chartexchange_model.py @@ -35,7 +35,8 @@ def get_option_history( price : Union[str, Union[int, float]] Strike price for a specific option chain_id: str - OCC option symbol. Overwrites other inputs + Option symbol. Overwrites other inputs. ChartExchange uses the format: + `{TICKER}{YYYYMMDD}{C/P}{PRICE}`, where the price has no leading and trailing zeros. Returns ------- diff --git a/openbb_terminal/stocks/options/chartexchange_view.py b/openbb_terminal/stocks/options/chartexchange_view.py index 2667091d837e..cabc6d937ace 100644 --- a/openbb_terminal/stocks/options/chartexchange_view.py +++ b/openbb_terminal/stocks/options/chartexchange_view.py @@ -72,6 +72,7 @@ def display_raw( price: float = 90, limit: int = 10, chain_id: Optional[str] = None, + raw: bool = False, export: str = "", sheet_name: Optional[str] = None, external_axes: bool = False, @@ -109,22 +110,27 @@ def display_raw( option_type = "call" if call else "put" fig = plot_chart(df, option_type, symbol, price) - export_data( - export, - os.path.dirname(os.path.abspath(__file__)), - "hist", - df, - sheet_name, - fig, - ) - print_rich_table( - df, - headers=list(df.columns), - show_index=True, - index_name="Date", - title=f"{symbol.upper()} raw data", - export=bool(export), - limit=limit, - ) + if export != "": + export_data( + export, + os.path.dirname(os.path.abspath(__file__)), + "hist", + df, + sheet_name, + fig, + ) + return None + + if raw is True: + print_rich_table( + df, + headers=list(df.columns), + show_index=True, + index_name="Date", + title=f"{symbol.upper()} raw data", + export=bool(export), + limit=limit, + ) + return None return fig.show(external=external_axes) diff --git a/openbb_terminal/stocks/options/intrinio_view.py b/openbb_terminal/stocks/options/intrinio_view.py index 1198ac852919..d7becd0ae050 100644 --- a/openbb_terminal/stocks/options/intrinio_view.py +++ b/openbb_terminal/stocks/options/intrinio_view.py @@ -71,6 +71,8 @@ def display_historical( headers=[x.title() for x in df_hist.columns], title="Historical Option Prices", export=bool(export), + show_index=True, + index_name="Date", ) df_hist.columns = [x.title() for x in df_hist.columns] diff --git a/openbb_terminal/stocks/options/options_controller.py b/openbb_terminal/stocks/options/options_controller.py index 677e0ae6be6a..325399b62022 100644 --- a/openbb_terminal/stocks/options/options_controller.py +++ b/openbb_terminal/stocks/options/options_controller.py @@ -800,6 +800,7 @@ def call_hist(self, other_args: List[str]): call=not ns_parser.put, price=ns_parser.strike, limit=ns_parser.limit, + raw=ns_parser.raw, export=ns_parser.export, chain_id=ns_parser.chain_id, sheet_name=" ".join(ns_parser.sheet_name) diff --git a/openbb_terminal/stocks/options/tradier_view.py b/openbb_terminal/stocks/options/tradier_view.py index dc76bb1225c1..d4e5faac49d1 100644 --- a/openbb_terminal/stocks/options/tradier_view.py +++ b/openbb_terminal/stocks/options/tradier_view.py @@ -72,6 +72,8 @@ def display_historical( headers=[x.title() for x in df_hist.columns], title="Historical Option Prices", export=bool(export), + show_index=True, + index_name="Date", ) op_type = ["call", "put"][put] diff --git a/tests/openbb_terminal/stocks/options/test_chartexchange_view.py b/tests/openbb_terminal/stocks/options/test_chartexchange_view.py index 4ae4fceaeeb1..322a665f1295 100644 --- a/tests/openbb_terminal/stocks/options/test_chartexchange_view.py +++ b/tests/openbb_terminal/stocks/options/test_chartexchange_view.py @@ -23,12 +23,12 @@ def vcr_config(): @pytest.mark.vcr @pytest.mark.record_stdout @pytest.mark.parametrize( - "tab", + "raw", [True, False], ) -def test_display_raw(mocker, tab): +def test_display_raw(mocker, raw): # MOCK CHARTS - preferences = PreferencesModel(USE_TABULATE_DF=tab) + preferences = PreferencesModel(USE_TABULATE_DF=raw) mock_current_user = copy_user(preferences=preferences) mocker.patch( target="openbb_terminal.core.session.current_user.__current_user", @@ -39,9 +39,5 @@ def test_display_raw(mocker, tab): mocker.patch(target="openbb_terminal.stocks.options.chartexchange_view.plot_chart") chartexchange_view.display_raw( - export="", - symbol="GME", - expiry="2021-02-05", - call=True, - price=90, + export="", symbol="GME", expiry="2021-02-05", call=True, price=90, raw=raw ) diff --git a/tests/openbb_terminal/stocks/options/txt/test_chartexchange_view/test_display_raw[False].txt b/tests/openbb_terminal/stocks/options/txt/test_chartexchange_view/test_display_raw[False].txt index e094a6c806e1..e69de29bb2d1 100644 --- a/tests/openbb_terminal/stocks/options/txt/test_chartexchange_view/test_display_raw[False].txt +++ b/tests/openbb_terminal/stocks/options/txt/test_chartexchange_view/test_display_raw[False].txt @@ -1,12 +0,0 @@ - Open High Low Close Change Volume Open Interest Change Since -Date -2021-01-25 20.70 85.70 13.90 20.00 0.00000 1834.0 552.0 -0.99850 -2021-01-26 27.50 75.79 21.00 70.17 2.50850 1763.0 572.0 -0.99957 -2021-01-27 210.20 285.50 70.80 255.90 2.64686 309.0 461.0 -0.99988 -2021-01-28 225.40 385.55 62.75 130.65 -0.48945 49.0 450.0 -0.99977 -2021-01-29 232.15 296.20 183.10 183.10 0.40145 37.0 445.0 -0.99984 -2021-02-01 232.60 232.60 133.09 133.09 -0.27313 107.0 441.0 -0.99977 -2021-02-02 64.61 76.20 18.50 23.70 -0.82193 1991.0 555.0 -0.99873 -2021-02-03 40.45 40.45 13.50 14.26 -0.39831 2124.0 1074.0 -0.99790 -2021-02-04 13.70 14.00 0.75 0.75 -0.94741 5945.0 2386.0 -0.96000 -2021-02-05 0.57 14.79 0.01 0.03 -0.96000 6580.0 2017.0 0.00000 From f063ed194084dd4d2a2eacacfc07eb708a00eb3d Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:54:13 -0700 Subject: [PATCH 2/3] make raw table title same as other sources --- openbb_terminal/stocks/options/chartexchange_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/stocks/options/chartexchange_view.py b/openbb_terminal/stocks/options/chartexchange_view.py index cabc6d937ace..155e1ce067d9 100644 --- a/openbb_terminal/stocks/options/chartexchange_view.py +++ b/openbb_terminal/stocks/options/chartexchange_view.py @@ -127,7 +127,7 @@ def display_raw( headers=list(df.columns), show_index=True, index_name="Date", - title=f"{symbol.upper()} raw data", + title="Historical Option Prices", export=bool(export), limit=limit, ) From 429e3d6d785d07092d281e35f5da3f08dd440a0b Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:13:54 -0700 Subject: [PATCH 3/3] if export --- openbb_terminal/stocks/options/chartexchange_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbb_terminal/stocks/options/chartexchange_view.py b/openbb_terminal/stocks/options/chartexchange_view.py index 155e1ce067d9..fbf818ad2baf 100644 --- a/openbb_terminal/stocks/options/chartexchange_view.py +++ b/openbb_terminal/stocks/options/chartexchange_view.py @@ -110,7 +110,7 @@ def display_raw( option_type = "call" if call else "put" fig = plot_chart(df, option_type, symbol, price) - if export != "": + if export: export_data( export, os.path.dirname(os.path.abspath(__file__)), @@ -121,7 +121,7 @@ def display_raw( ) return None - if raw is True: + if raw: print_rich_table( df, headers=list(df.columns),