Exemple #1
0
 def call_rhhold(self, _):
     try:
         rh_api.show_holdings()
     except Exception as e:
         print(e)
         print("")
Exemple #2
0
def port_menu():
    plt.close("all")
    port_parser = argparse.ArgumentParser(prog="port", add_help=False)
    choices = ["help", "q", "quit", "hold", "rhhist", "login"]
    port_parser.add_argument("cmd", choices=choices)
    completer = NestedCompleter.from_nested_dict({c: None for c in choices})
    should_print_help = True
    print_login = True
    while True:
        if should_print_help:
            print_port(print_login)
            should_print_help = False

        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            as_input = session.prompt(
                f"{get_flair()} (port)> ",
                completer=completer,
            )
        else:
            as_input = input(f"{get_flair()} (port)> ")
        try:
            (ns_known_args,
             l_args) = port_parser.parse_known_args(as_input.split())

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue

        if ns_known_args.cmd == "help":
            should_print_help = True

        elif ns_known_args.cmd == "q":
            # Leave the port menu + logout of robinhood
            # logoff raises error if not logged in
            try:
                rh_api.logoff()
            except Exception:
                pass
            return False

        elif ns_known_args.cmd == "quit":
            # Will raise exception if not logged in
            try:
                rh_api.logoff()
            except Exception:
                pass
            # Abandon the program
            return True

        elif ns_known_args.cmd == "hold":
            try:
                rh_api.show_holdings()
            except Exception as e:
                print(e)
                print("")

        elif ns_known_args.cmd == "rhhist":
            rh_api.plot_historical(l_args)

        elif ns_known_args.cmd == "login":
            try:
                rh_api.login()
                should_print_help = True
                print_login = False
            except Exception as e:
                print("")
                print(e)
                print(
                    "Make sure credentials are defined in config_terminal.py ")
                print("")
                should_print_help = False
                print_login = True

        else:
            print("Command not recognized")
            print("")