diff --git a/openbb_terminal/stocks/options/options_controller.py b/openbb_terminal/stocks/options/options_controller.py index ed420073e87..c68c183542a 100644 --- a/openbb_terminal/stocks/options/options_controller.py +++ b/openbb_terminal/stocks/options/options_controller.py @@ -129,7 +129,7 @@ class OptionsController(BaseController): self.ticker = ticker self.prices = pd.DataFrame(columns=["Price", "Chance"]) - self.selected_date = expiration if expiration else "" + self.selected_date = expiration or "" self.chain: pd.DataFrame = pd.DataFrame() self.full_chain: pd.DataFrame = pd.DataFrame() @@ -173,10 +173,7 @@ class OptionsController(BaseController): custom_filters = [sort_filter] - commands = parse_and_split_input( - an_input=an_input, custom_filters=custom_filters - ) - return commands + return parse_and_split_input(an_input=an_input, custom_filters=custom_filters) def set_option_chain(self): df = pd.DataFrame() @@ -202,13 +199,13 @@ class OptionsController(BaseController): self.full_chain = df.copy(deep=True) self.chain = self.full_chain.copy(deep=True) - console.print("Loaded option chain from", self.source) + console.print(f"Loaded option chain from {self.source}\n") def set_current_price(self): if not self.chain.empty: if self.source == "Tradier": last_price = tradier_model.get_last_price(self.ticker) - self.current_price = last_price if last_price else 0.0 + self.current_price = last_price or 0.0 elif self.source == "Nasdaq": self.current_price = nasdaq_model.get_last_price(self.ticker) elif self.source == "Intrinio": @@ -359,8 +356,7 @@ class OptionsController(BaseController): default=-1, required="-m" in other_args, ) - ns_parser = self.parse_known_args_and_warn(parser, other_args) - if ns_parser: + if ns_parser := self.parse_known_args_and_warn(parser, other_args): pars = ( {"x_min": ns_parser.min, "x_max": ns_parser.max} if ns_parser.min > 0 and ns_parser.max > 0 @@ -431,10 +427,9 @@ class OptionsController(BaseController): ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-l") - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED - ) - if ns_parser: + ): if ns_parser.calls_only and ns_parser.puts_only: console.print( "Cannot return puts only and calls only. Either use one or neither." @@ -478,10 +473,9 @@ class OptionsController(BaseController): ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-l") - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES - ) - if ns_parser: + ): if self.ticker: alphaquery_view.display_put_call_ratio( symbol=self.ticker, @@ -504,10 +498,9 @@ class OptionsController(BaseController): prog="info", description="Display option data [Source: Barchart.com]", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED - ) - if ns_parser: + ): if self.ticker: barchart_view.print_options_data( symbol=self.ticker, @@ -579,10 +572,9 @@ class OptionsController(BaseController): ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-s") - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES - ) - if ns_parser: + ): if self.ticker or "--chain" in other_args: if self.selected_date or "--chain" in other_args: if ( @@ -652,16 +644,15 @@ class OptionsController(BaseController): "--ticker", action="store", dest="ticker", - required="-h" not in other_args, + required="-h" not in other_args and "--help" not in other_args, help="Stock ticker", ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-t") - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, - ) - if ns_parser: + ): self.ticker = ns_parser.ticker.upper() self.source = ns_parser.source @@ -716,8 +707,7 @@ class OptionsController(BaseController): else: other_args.insert(0, "-i") - ns_parser = self.parse_known_args_and_warn(parser, other_args) - if ns_parser: + if ns_parser := self.parse_known_args_and_warn(parser, other_args): if self.ticker: # Print possible expiry dates if ns_parser.index == -1 and not ns_parser.date: @@ -782,14 +772,13 @@ class OptionsController(BaseController): ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-s") - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True, limit=10, - ) - if ns_parser: + ): if not self.ticker and ns_parser.chain_id is None: console.print("No ticker loaded. First use `load `") return @@ -903,7 +892,7 @@ class OptionsController(BaseController): "-d", "--display", dest="to_display", - default=",".join(list(self.chain)) if not self.chain.empty else [], + default=[] if self.chain.empty else ",".join(list(self.chain)), type=str, help="Columns to display", ) @@ -916,10 +905,9 @@ class OptionsController(BaseController): help="Select expiration date (YYYY-MM-DD)", default="", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED - ) - if ns_parser: + ): if self.ticker: if ns_parser.exp: if ns_parser.exp in self.expiry_dates: @@ -1014,13 +1002,12 @@ class OptionsController(BaseController): help="Select expiration date (YYYY-MM-DD)", default="", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True, - ) - if ns_parser: + ): if self.ticker: if ns_parser.exp: if ns_parser.exp in self.expiry_dates: @@ -1100,10 +1087,9 @@ class OptionsController(BaseController): help="Select expiration date (YYYY-MM-DD)", default="", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True - ) - if ns_parser: + ): if self.ticker: if ns_parser.exp: if ns_parser.exp in self.expiry_dates: @@ -1190,13 +1176,12 @@ class OptionsController(BaseController): help="Select expiration date (YYYY-MM-DD)", default="", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, raw=True, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, - ) - if ns_parser: + ): if self.ticker: if ns_parser.exp: if ns_parser.exp in self.expiry_dates: @@ -1285,10 +1270,9 @@ class OptionsController(BaseController): help="Choose from already created graphs", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, EXPORT_ONLY_FIGURES_ALLOWED - ) - if ns_parser: + ): if self.ticker: if self.selected_date: if ( @@ -1331,10 +1315,9 @@ class OptionsController(BaseController): help="The data for the Z axis", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, export_allowed=EXPORT_ONLY_FIGURES_ALLOWED - ) - if ns_parser: + ): yfinance_view.display_vol_surface( self.ticker, export=ns_parser.export, @@ -1399,10 +1382,9 @@ class OptionsController(BaseController): help="Whether to show all greeks.", ) - ns_parser = self.parse_known_args_and_warn( + if ns_parser := self.parse_known_args_and_warn( parser, other_args, export_allowed=EXPORT_ONLY_FIGURES_ALLOWED - ) - if ns_parser: + ): if not self.ticker: console.print("No ticker loaded. First use `load `") elif not self.selected_date: @@ -1456,13 +1438,11 @@ class OptionsController(BaseController): "--date", type=valid_date, dest="date", - help="Date to get option chain for. Format YYYY-MM-DD", - required="-h" not in other_args, + help="Date to get option chain for. Format YYYY-MM-DD", + required="-h" not in other_args and "--help" not in other_args, ) - ns_parser = self.parse_known_args_and_warn(parser, other_args) - - if ns_parser: + if ns_parser := self.parse_known_args_and_warn(parser, other_args): if not self.ticker: console.print("No ticker loaded. First use `load `") return