def _get_args(self): parser = ArgumentParser(prog="stonky", epilog=EPILOG, formatter_class=RawTextHelpFormatter) parser.add_argument("--config", metavar="PATH", help="sets path to config file") parser.add_argument( "--currency", metavar="CODE", choices=CurrencyType.arg_choices(), type=str.upper, help="converts all amounts using current forex rates", ) parser.add_argument( "--refresh", metavar="SECONDS", type=int, help="refreshes output on set interval", ) parser.add_argument( "--sort", metavar="FIELD", type=str.lower, choices=SortType.arg_choices(), help="orders stocks by field", ) self._args = parser.parse_args() if self._args.config: self.config_path = Path(self._args.config)
async def get_quote(self, ticket: str) -> Stock: url = f"https://query1.finance.yahoo.com/v11/finance/quoteSummary/{ticket}" params = {"modules": "summaryDetail,price"} response = await self._query(url, params) if "error" in response: raise StonkyException( f"Could not get stock information for {ticket}") try: summary_data = response["quoteSummary"]["result"][0][ "summaryDetail"] price_data = response["quoteSummary"]["result"][0]["price"] stock = Stock( ticket=ticket, currency=CurrencyType(price_data["currency"]), amount_bid=summary_data["bid"].get("raw", 0.0), amount_ask=summary_data["ask"].get("raw", 0.0), amount_low=summary_data["dayLow"].get("raw", 0.0), amount_high=summary_data["dayHigh"].get("raw", 0.0), amount_prev_close=summary_data["previousClose"].get( "raw", 0.0), delta_amount=price_data["regularMarketChange"].get("raw", 0.0), delta_percent=price_data["regularMarketChangePercent"].get( "raw", 0.0), market_price=price_data["regularMarketPrice"].get("raw", 0.0), volume=summary_data["volume"].get("raw", 0.0), ) except TypeError: raise StonkyException( f"Could not get stock information for '{ticket}'") return stock
def _apply_parsed_args(self): if self._args.currency == "": self.currency = None elif self._args.currency: self.currency = CurrencyType(self._args.currency) if self._args.refresh in ("", 0): self.refresh = None elif self._args.refresh: self.refresh = self._args.refresh if self._args.sort == "": self._args.sort = None elif self._args.sort is not None: self.sort = SortType.from_arg(self._args.sort) if self._args.verbose is not None: if self._args.verbose == 1: self.verbose = VerboseType.EXTENDED else: self.verbose = VerboseType.DEBUG