diff --git a/openbb_terminal/stocks/stock_statics.py b/openbb_terminal/stocks/stock_statics.py index ce73a088034..36b5af791c0 100644 --- a/openbb_terminal/stocks/stock_statics.py +++ b/openbb_terminal/stocks/stock_statics.py @@ -12,55 +12,55 @@ CANDLE_SORT = [ ] market_coverage_suffix = { - "USA": ["CBT", "CME", "NYB", "CMX", "NYM", "US", ""], - "Argentina": ["BA"], - "Austria": ["VI"], - "Australia": ["AX"], - "Belgium": ["BR"], - "Brazil": ["SA"], - "Canada": ["CN", "NE", "TO", "V"], - "Chile": ["SN"], - "China": ["SS", "SZ"], - "Czech-Republic": ["PR"], - "Denmark": ["CO"], - "Egypt": ["CA"], - "Estonia": ["TL"], - "Europe": ["NX"], - "Finland": ["HE"], - "France": ["PA"], - "Germany": ["BE", "BM", "DU", "F", "HM", "HA", "MU", "SG", "DE"], - "Greece": ["AT"], - "Hong-Kong": ["HK"], - "Hungary": ["BD"], - "Iceland": ["IC"], - "India": ["BO", "NS"], - "Indonesia": ["JK"], - "Ireland": ["IR"], - "Israel": ["TA"], - "Italy": ["MI"], - "Japan": ["T", "S"], - "Latvia": ["RG"], - "Lithuania": ["VS"], - "Malaysia": ["KL"], - "Mexico": ["MX"], - "Netherlands": ["AS"], - "New-Zealand": ["NZ"], - "Norway": ["OL"], - "Portugal": ["LS"], - "Qatar": ["QA"], - "Russia": ["ME"], - "Singapore": ["SI"], - "South-Africa": ["JO"], - "South-Korea": ["KS", "KQ"], - "Spain": ["MC"], - "Saudi-Arabia": ["SAU"], - "Sweden": ["ST"], - "Switzerland": ["SW"], - "Taiwan": ["TWO", "TW"], - "Thailand": ["BK"], - "Turkey": ["IS"], - "United-Kingdom": ["L", "IL"], - "Venezuela": ["CR"], + "united_states": ["CBT", "CME", "NYB", "CMX", "NYM", "US", ""], + "argentina": ["BA"], + "austria": ["VI"], + "australia": ["AX"], + "belgium": ["BR"], + "brazil": ["SA"], + "canada": ["CN", "NE", "TO", "V"], + "chile": ["SN"], + "china": ["SS", "SZ"], + "czech_republic": ["PR"], + "denmark": ["CO"], + "egypt": ["CA"], + "estonia": ["TL"], + "europe": ["NX"], + "finland": ["HE"], + "france": ["PA"], + "germany": ["BE", "BM", "DU", "F", "HM", "HA", "MU", "SG", "DE"], + "greece": ["AT"], + "hong_kong": ["HK"], + "hungary": ["BD"], + "iceland": ["IC"], + "india": ["BO", "NS"], + "indonesia": ["JK"], + "ireland": ["IR"], + "israel": ["TA"], + "italy": ["MI"], + "japan": ["T", "S"], + "latvia": ["RG"], + "lithuania": ["VS"], + "malaysia": ["KL"], + "mexico": ["MX"], + "netherlands": ["AS"], + "new_zealand": ["NZ"], + "norway": ["OL"], + "portugal": ["LS"], + "qatar": ["QA"], + "russia": ["ME"], + "singapore": ["SI"], + "south_africa": ["JO"], + "south_korea": ["KS", "KQ"], + "spain": ["MC"], + "saudi_arabia": ["SAU"], + "sweden": ["ST"], + "switzerland": ["SW"], + "taiwan": ["TWO", "TW"], + "thailand": ["BK"], + "turkey": ["IS"], + "united_kingdom": ["L", "IL"], + "venezuela": ["CR"], } INCOME_PLOT = { diff --git a/openbb_terminal/stocks/stocks_controller.py b/openbb_terminal/stocks/stocks_controller.py index d419879a91f..bad20060980 100644 --- a/openbb_terminal/stocks/stocks_controller.py +++ b/openbb_terminal/stocks/stocks_controller.py @@ -123,13 +123,15 @@ class StocksController(StockBaseController): choices["search"] = { "--query": None, "-q": "--query", - "--country": {c: {} for c in self.country}, + "--country": {c.lower().replace(" ", "_"): {} for c in self.country}, "-c": "--country", "--sector": {c: {} for c in self.sector}, "-s": "--sector", "--industry": {c: {} for c in self.industry}, "-i": "--industry", - "--exchange": {c: {} for c in stocks_helper.market_coverage_suffix}, + "--exchange": { + c.lower(): {} for c in stocks_helper.market_coverage_suffix + }, "-e": "--exchange", "--limit": one_to_hundred, "-l": "--limit", @@ -246,7 +248,8 @@ class StocksController(StockBaseController): default="", choices=clean_countries, dest="country", - type=str, + metavar="country_name", + type=str.lower, help="Search by country to find stocks matching the criteria", ) parser.add_argument( @@ -267,11 +270,14 @@ class StocksController(StockBaseController): dest="industry", help="Search by industry to find stocks matching the criteria", ) + country_opts = [x.lower() for x in stocks_helper.market_coverage_suffix] parser.add_argument( "-e", "--exchange", default="", - choices=list(stocks_helper.market_coverage_suffix.keys()), + choices=country_opts, + type=str.lower, + metavar="country_name", dest="exchange_country", help="Search by a specific exchange country to find stocks matching the criteria", ) diff --git a/openbb_terminal/stocks/stocks_helper.py b/openbb_terminal/stocks/stocks_helper.py index b8d9c79cdae..acefda9d2a1 100644 --- a/openbb_terminal/stocks/stocks_helper.py +++ b/openbb_terminal/stocks/stocks_helper.py @@ -107,6 +107,11 @@ def search( " please check if you can access this website without a VPN.[/red]\n" ) data = {} + except ValueError: + console.print( + "[red]No companies were found that match the given criteria.[/red]\n" + ) + return if not data: console.print("No companies found.\n") return @@ -150,9 +155,9 @@ def search( if query: title += f" on term {query}" if exchange_country: - title += f" {exchange_country} exchange" + title += f" on an exchange in {exchange_country.replace('_', ' ').title()}" if country: - title += f" in {country}" + title += f" in {country.replace('_', ' ').title()}" if sector: title += f" within {sector}" if industry: @@ -160,6 +165,13 @@ def search( if not sector and industry: title += f" within {industry}" + df["exchange"] = df["exchange"].apply( + lambda x: x.replace("_", " ").title() if x else None + ) + df["exchange"] = df["exchange"].apply( + lambda x: "United States" if x == "Usa" else None + ) + print_rich_table( df.iloc[:limit] if limit else df, show_index=True, diff --git a/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[False].txt b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[False].txt index 6d5deff349c..ff00b526604 100644 --- a/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[False].txt +++ b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[False].txt @@ -1,6 +1,6 @@ - long_name country sector industry exchange -S4LB.F Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production Germany -SNC.LS Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services Portugal -SON.LS Sonae, SGPS, S.A. Portugal Consumer Cyclical Department Stores Portugal -SONI.LS Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production Portugal -XOA1.SG Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services Germany + long_name country sector industry exchange +S4LB.F Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production None +SNC.LS Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services None +SON.LS Sonae, SGPS, S.A. Portugal Consumer Cyclical Department Stores None +SONI.LS Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production None +XOA1.SG Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services None diff --git a/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[True].txt b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[True].txt index 6d5deff349c..ff00b526604 100644 --- a/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[True].txt +++ b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_search[True].txt @@ -1,6 +1,6 @@ - long_name country sector industry exchange -S4LB.F Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production Germany -SNC.LS Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services Portugal -SON.LS Sonae, SGPS, S.A. Portugal Consumer Cyclical Department Stores Portugal -SONI.LS Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production Portugal -XOA1.SG Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services Germany + long_name country sector industry exchange +S4LB.F Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production None +SNC.LS Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services None +SON.LS Sonae, SGPS, S.A. Portugal Consumer Cyclical Department Stores None +SONI.LS Sonae Indústria, S.G.P.S., S.A. Portugal Basic Materials Lumber & Wood Production None +XOA1.SG Sonaecom, S.G.P.S., S.A. Portugal Technology Information Technology Services None