Skip to content

Commit

Permalink
hotfix/ stocks/options/chains - Single Window/to_display columns (#…
Browse files Browse the repository at this point in the history
…4670)

* init

* Update options_controller.py

* Update options_controller.py
  • Loading branch information
tehcoderer authored Apr 4, 2023
1 parent 7f9a312 commit 0447b96
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
11 changes: 10 additions & 1 deletion openbb_terminal/stocks/options/options_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,17 @@ def call_chains(self, other_args: List[str]):
f"Expiration not an option. Expiration set to {self.selected_date}"
)
if self.selected_date:
df_chain = self.chain.copy()
needed = ["symbol", "code", "optionType", "expiration", "strike"]
needed = [col for col in needed if col in df_chain.columns]

if ns_parser.to_display:
to_display = ns_parser.to_display.split(",")
display = [col for col in to_display if col not in needed]
df_chain = df_chain[needed + display]

display_chains(
chain=self.chain,
chain=df_chain,
expire=self.selected_date,
calls_only=ns_parser.calls,
puts_only=ns_parser.puts,
Expand Down
47 changes: 32 additions & 15 deletions openbb_terminal/stocks/options/options_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd

from openbb_terminal import OpenBBFigure
from openbb_terminal.core.plots.backend import plots_backend

# IMPORTATION INTERNAL
from openbb_terminal.core.session.current_user import get_current_user
Expand Down Expand Up @@ -49,25 +50,41 @@ def print_raw(
puts_only: bool = False,
export: str = "",
):
if not puts_only:
calls = calls.copy().drop(columns=["optionType"])
print_rich_table(
calls,
headers=list(calls.columns),
show_index=False,
title=f"{title} - Calls",
export=bool(export),
)
if not calls_only:
puts = puts.copy().drop(columns=["optionType"])
print_rich_table(
puts,
headers=list(puts.columns),
current_user = get_current_user()
enable_interactive = (
current_user.preferences.USE_INTERACTIVE_DF and plots_backend().isatty
)

if enable_interactive:
table_title = f"{title} - Calls & Puts"
data = pd.concat([calls, puts])

if calls_only or puts_only:
options_type = "call" if calls_only else "put"
data = data[data["optionType"] == options_type].drop(columns=["optionType"])
table_title = f"{title} - {options_type.title()}s"

return print_rich_table(
data,
headers=list(data.columns),
show_index=False,
title=f"{title} - Puts",
title=table_title,
export=bool(export),
)

for opt_type, only in zip(["call", "put"], [puts_only, calls_only]):
if not only:
data = (calls if opt_type == "call" else puts).drop(columns=["optionType"])
print_rich_table(
data,
headers=list(data.columns),
show_index=False,
title=f"{title} - {opt_type.title()}s",
export=bool(export),
)

return None


@log_start_end(log=logger)
def plot_vol(
Expand Down

0 comments on commit 0447b96

Please sign in to comment.