def test_display_historical(mocker): # MOCK CHARTS mocker.patch( target= "gamestonk_terminal.stocks.options.tradier_view.theme.visualize_output" ) # MOCK EXPORT_DATA mocker.patch( target="gamestonk_terminal.stocks.options.tradier_view.export_data") # MOCK USE_COLOR mocker.patch.object(target=tradier_view.gtff, attribute="USE_COLOR", new=True) tradier_view.display_historical( ticker="AAPL", expiry="2022-02-25", strike=180.0, put=True, export="csv", raw=True, chain_id="", )
def test_display_historical(mocker): # MOCK CHARTS mocker.patch.object(target=tradier_view.gtff, attribute="USE_ION", new=True) mocker.patch( target="gamestonk_terminal.stocks.options.tradier_view.plt.ion") mocker.patch( target="gamestonk_terminal.stocks.options.tradier_view.plt.show") # MOCK EXPORT_DATA mocker.patch( target="gamestonk_terminal.stocks.options.tradier_view.export_data") # MOCK USE_COLOR mocker.patch.object(target=tradier_view.gtff, attribute="USE_COLOR", new=True) tradier_view.display_historical( ticker="PM", expiry="2022-01-07", strike=90.0, put=True, export="csv", raw=True, chain_id="", )
def call_hist(self, other_args: List[str]): """Process hist command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="hist", description="Gets historical quotes for given option chain", ) parser.add_argument( "-s", "--strike", dest="strike", type=float, required="--chain" not in other_args and "-c" not in other_args, help="Strike price to look at", ) parser.add_argument( "-p", "--put", dest="put", action="store_true", default=False, help="Flag for showing put option", ) parser.add_argument("-c", "--chain", dest="chain_id", type=str, help="OCC option symbol") parser.add_argument( "-r", "--raw", dest="raw", action="store_true", default=False, help="Display raw data", ) parser.add_argument( "--source", dest="source", type=str, choices=self.hist_source_choices, default="ce" if TRADIER_TOKEN == "REPLACE_ME" else "td", help= "Choose Tradier(TD) or ChartExchange (CE), only affects raw data", ) parser.add_argument( "-l", "--limit", dest="limit", type=int, help="Limit of data rows to display", ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-s") ns_parser = parse_known_args_and_warn( parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES) if ns_parser: if self.ticker: if self.selected_date: if self.chain and ( (ns_parser.put and ns_parser.strike in self.chain.puts["strike"]) or (not ns_parser.put and ns_parser.strike in self.chain.calls["strike"])): if ns_parser.source.lower() == "ce": chartexchange_view.display_raw( self.ticker, self.selected_date, not ns_parser.put, ns_parser.strike, ns_parser.limit, ns_parser.export, ) else: if TRADIER_TOKEN != "REPLACE_ME": tradier_view.display_historical( ticker=self.ticker, expiry=self.selected_date, strike=ns_parser.strike, put=ns_parser.put, raw=ns_parser.raw, chain_id=ns_parser.chain_id, export=ns_parser.export, ) else: print("TRADIER TOKEN not supplied. \n") else: print("No correct strike input\n") else: print("No expiry loaded. First use `exp <expiry date>` \n") else: print("No ticker loaded. First use `load <ticker>`\n")