From a951a7bdabc2f6ea10d79b676e5bed1102073f2f Mon Sep 17 00:00:00 2001 From: Cameron Beebe <39677739+CameronBeebe@users.noreply.github.com> Date: Sun, 5 Dec 2021 12:51:09 -0700 Subject: [PATCH] Feature/price (#961) * Begin implementing price option for quote in stocks * Still sane tests. Note: Why can't we interface with the ticker (pandas df) itself from within the GST? E.g. GME.price * Basic function of price option for quote achieved (e.g. "quote -t GME -p" returns "Price of GME 210.0"). Not sure if this is compatible with non-YF data backends. Still need to update documentation. * Removed personalized comments in prep for pull request. Simple feature works, but IMO brings up questions about ideal function of load and quote functions. * Changed one comment, also tried testing pre-commit, no output is good? * Added option [-p] to usage and description * cleaned extra lines * Cleaned extra lines * Test print df in load, fixed formatting for print in quote (hope it passes linter) * Deleted whitespace for linter... * Reformatted for linter * Removed tests for load * Rewrote but black linter still seems to fail on ``` --- gamestonk_terminal/stocks/stocks_helper.py | 17 ++++++++++++++++- website/content/stocks/quote/_index.md | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/stocks/stocks_helper.py b/gamestonk_terminal/stocks/stocks_helper.py index 26ac09f5be3..c97587a18e3 100644 --- a/gamestonk_terminal/stocks/stocks_helper.py +++ b/gamestonk_terminal/stocks/stocks_helper.py @@ -284,7 +284,6 @@ def load( df_stock_candidate = yf.download( ns_parser.s_ticker, start=ns_parser.s_start_date, - end=ns_parser.s_end_date, progress=False, ) @@ -699,6 +698,16 @@ def quote(other_args: List[str], s_ticker: str): help="Stock ticker", ) + # Price only option. + parser.add_argument( + "-p", + "--price", + action="store_true", + dest="price_only", + default=False, + help="Price only", + ) + try: # For the case where a user uses: 'quote BB' if other_args and "-" not in other_args[0]: @@ -713,6 +722,11 @@ def quote(other_args: List[str], s_ticker: str): ticker = yf.Ticker(ns_parser.s_ticker) + # If price only option, return immediate market price for ticker. + if ns_parser.price_only: + print(f"Price of {ns_parser.s_ticker} {ticker.info['regularMarketPrice']}") + return + try: quote_df = pd.DataFrame( [ @@ -761,6 +775,7 @@ def quote(other_args: List[str], s_ticker: str): stralign="right", ) ) + except KeyError: print(f"Invalid stock ticker: {ns_parser.s_ticker}") diff --git a/website/content/stocks/quote/_index.md b/website/content/stocks/quote/_index.md index 1a9314dfd64..d1f13029c59 100755 --- a/website/content/stocks/quote/_index.md +++ b/website/content/stocks/quote/_index.md @@ -1,5 +1,5 @@ ``` -usage: quote [-t S_TICKER] [-h] +usage: quote [-t S_TICKER] [-p] [-h] ``` Retrieves a current quote from the currently [loaded ticker](https://gamestonkterminal.github.io/GamestonkTerminal/stocks/load/). To view a quote from a different symbol than what is currently loaded, add the '-t' argument to the command string. @@ -8,6 +8,7 @@ Retrieves a current quote from the currently [loaded ticker](https://gamestonkte optional arguments: -t S_TICKER, --ticker S_TICKER Stock ticker (default: AAPL) + -p, --price Return only the current price (default: False) -h, --help show this help message (default: False) ```