mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
Fixed search command issues (#4845)
* Added `exchange` filter in `stocks\search` * Fixed arguments * Fixed issues with `stocks\search` command * Fixed linting * Fixed args and updated test * get rid of second dash --------- Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -197,8 +197,7 @@ class StocksController(StockBaseController):
|
||||
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 @@ class StocksController(StockBaseController):
|
||||
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 @@ class StocksController(StockBaseController):
|
||||
)
|
||||
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 @@ class StocksController(StockBaseController):
|
||||
"--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 @@ class StocksController(StockBaseController):
|
||||
|
||||
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)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -63,6 +63,7 @@ def test_search(mocker, use_tab):
|
||||
sector="",
|
||||
industry="",
|
||||
industry_group="",
|
||||
exchange="",
|
||||
exchange_country="",
|
||||
all_exchanges=False,
|
||||
limit=5,
|
||||
|
||||
Reference in New Issue
Block a user