diff --git a/openbb_terminal/stocks/stocks_controller.py b/openbb_terminal/stocks/stocks_controller.py index 953b4f3eb542..a40211e04b46 100644 --- a/openbb_terminal/stocks/stocks_controller.py +++ b/openbb_terminal/stocks/stocks_controller.py @@ -197,8 +197,7 @@ def call_search(self, other_args: List[str]): help="Search by sector to find stocks matching the criteria", ) parser.add_argument( - "-g", - "--industry-group", + "--industrygroup", default="", choices=stocks_helper.format_parse_choices(self.industry_group), type=str.lower, @@ -227,8 +226,7 @@ def call_search(self, other_args: List[str]): help="Search by a specific exchange to find stocks matching the criteria", ) parser.add_argument( - "-m", - "--exchange-country", + "--exchangecountry", default="", choices=stocks_helper.format_parse_choices( list(stocks_helper.market_coverage_suffix.keys()) @@ -248,13 +246,12 @@ def call_search(self, other_args: List[str]): ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-q") - 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, limit=10, - ) - if ns_parser: + ): # Mapping sector = stocks_helper.map_parse_choices(self.sector)[ns_parser.sector] industry = stocks_helper.map_parse_choices(self.industry)[ @@ -296,7 +293,7 @@ def call_tob(self, other_args: List[str]): "--ticker", action="store", dest="s_ticker", - required=not any(x in other_args for x in ["-h", "--help"]) + required=all(x not in other_args for x in ["-h", "--help"]) and not self.ticker, help="Ticker to get data for", ) @@ -311,10 +308,8 @@ def call_tob(self, other_args: List[str]): if not self.ticker and other_args and "-" not in other_args[0][0]: other_args.insert(0, "-t") - ns_parser = self.parse_known_args_and_warn(parser, other_args) - - if ns_parser: - ticker = ns_parser.s_ticker if ns_parser.s_ticker else self.ticker + if ns_parser := self.parse_known_args_and_warn(parser, other_args): + ticker = ns_parser.s_ticker or self.ticker cboe_view.display_top_of_book(ticker, ns_parser.exchange) @log_start_end(log=logger) diff --git a/openbb_terminal/stocks/stocks_helper.py b/openbb_terminal/stocks/stocks_helper.py index 047ccadfd986..f0a98f850e24 100644 --- a/openbb_terminal/stocks/stocks_helper.py +++ b/openbb_terminal/stocks/stocks_helper.py @@ -138,11 +138,11 @@ def search( exchange: str Search by exchange to find stock matching the criteria exchange_country: str - Search by exchange country to find stock matching + Search by exchange country to find stock matching the criteria all_exchanges: bool Whether to search all exchanges, without this option only the United States market is searched limit : int - The limit of companies shown. + The limit of results shown, where 0 means all the results Returns ------- @@ -166,7 +166,9 @@ def search( kwargs["industry_group"] = industry_group if exchange: kwargs["exchange"] = exchange - kwargs["exclude_exchanges"] = False if exchange_country else not all_exchanges + kwargs["exclude_exchanges"] = ( + False if (exchange_country or exchange) else not all_exchanges + ) try: equities_database = fd.Equities() @@ -187,7 +189,7 @@ def search( " capabilities. This tends to be due to access restrictions for GitHub.com," " please check if you can access this website without a VPN.[/red]\n" ) - data = {} + data = pd.DataFrame() except ValueError: console.print( "[red]No companies were found that match the given criteria.[/red]\n" @@ -223,6 +225,8 @@ def search( exchange_suffix[x] = k df = df[["name", "country", "sector", "industry_group", "industry", "exchange"]] + # To automate renaming columns + headers = [col.replace("_", " ") for col in df.columns.tolist()] title = "Companies found" if query: @@ -252,7 +256,8 @@ def search( print_rich_table( df, show_index=True, - headers=["Name", "Country", "Sector", "Industry Group", "Industry", "Exchange"], + headers=headers, + index_name="Symbol", title=title, limit=limit, ) diff --git a/tests/openbb_terminal/stocks/test_stocks_helper.py b/tests/openbb_terminal/stocks/test_stocks_helper.py index 44a738b8cd00..8c35dd4e5756 100644 --- a/tests/openbb_terminal/stocks/test_stocks_helper.py +++ b/tests/openbb_terminal/stocks/test_stocks_helper.py @@ -63,6 +63,7 @@ def test_search(mocker, use_tab): sector="", industry="", industry_group="", + exchange="", exchange_country="", all_exchanges=False, limit=5,