Skip to content

Commit

Permalink
hotfix/options-hist: Fixes options/hist to display date column when…
Browse files Browse the repository at this point in the history
… raw is True (#5304)

* fix options hist to display date column when raw is True

* make raw table title same as other sources

* if export
  • Loading branch information
deeleeramone authored Aug 9, 2023
1 parent d3f4752 commit 581fd94
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 38 deletions.
3 changes: 2 additions & 1 deletion openbb_terminal/stocks/options/chartexchange_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
40 changes: 23 additions & 17 deletions openbb_terminal/stocks/options/chartexchange_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
print_rich_table(
df,
headers=list(df.columns),
show_index=True,
index_name="Date",
title="Historical Option Prices",
export=bool(export),
limit=limit,
)
return None

return fig.show(external=external_axes)
2 changes: 2 additions & 0 deletions openbb_terminal/stocks/options/intrinio_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions openbb_terminal/stocks/options/options_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions openbb_terminal/stocks/options/tradier_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 4 additions & 8 deletions tests/openbb_terminal/stocks/options/test_chartexchange_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
)
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 581fd94

Please sign in to comment.