summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorteh_coderer <me@tehcoderer.com>2023-05-05 09:09:28 -0400
committerGitHub <noreply@github.com>2023-05-05 09:09:28 -0400
commit00e1bbd6490056ce617175d7cd650365484b057f (patch)
tree773ad623c066ae7dd61e7f8e3404cf1056c813df
parent24fb86f4e8d5f92dbae095d728f5a057e667a80a (diff)
parent5ed7830af77bda409808a477c96e6b32b4e957a4 (diff)
Merge branch 'develop' into feature/plotly-react
-rw-r--r--openbb_terminal/stocks/stocks_controller.py19
-rw-r--r--openbb_terminal/stocks/stocks_helper.py15
-rw-r--r--tests/openbb_terminal/stocks/test_stocks_helper.py1
3 files changed, 18 insertions, 17 deletions
diff --git a/openbb_terminal/stocks/stocks_controller.py b/openbb_terminal/stocks/stocks_controller.py
index 953b4f3eb54..a40211e04b4 100644
--- a/openbb_terminal/stocks/stocks_controller.py
+++ b/openbb_terminal/stocks/stocks_controller.py
@@ -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)
diff --git a/openbb_terminal/stocks/stocks_helper.py b/openbb_terminal/stocks/stocks_helper.py
index 047ccadfd98..f0a98f850e2 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 44a738b8cd0..8c35dd4e575 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,