Exemple #1
0
def menu():
    crypto_controller = CryptoController()
    crypto_controller.print_help(crypto_controller.current_coin)
    plt.close("all")
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in crypto_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (crypto)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (crypto)> ")

        try:
            process_input = crypto_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu():
    """Onchain Menu"""
    onchain_controller = OnchainController()
    onchain_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in onchain_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (crypto)>(onchain)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (crypto)>(onchain)> ")

        try:
            process_input = onchain_controller.switch(an_input)
        except SystemExit:
            print("The command selected doesn't exist\n")
            continue

        if process_input is False:
            return False

        if process_input is True:
            return True
Exemple #3
0
def menu():
    """Screener Menu"""

    scr_controller = ScreenerController()
    scr_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in scr_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(scr)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(scr)> ")

        try:
            plt.close("all")

            process_input = scr_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(ticker: str, start: str, interval: str, stock: pd.DataFrame):
    """Insider Menu"""
    ins_controller = InsiderController(ticker, start, interval, stock)
    ins_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in ins_controller.CHOICES}
            )
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(ins)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(ins)> ")

        try:
            process_input = ins_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #5
0
def menu():
    """Portfolio Analysis Menu"""

    port_controller = PortfolioController()
    port_controller.print_help(port_controller.broker_list)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in port_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (pa)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (pa)> ")

        try:
            process_input = port_controller.switch(an_input)

            if process_input is not None:
                return process_input

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

    econ_controller = EconomyController()
    econ_controller.print_help()

    # Loop forever and ever
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in econ_controller.CHOICES})

            an_input = session.prompt(
                f"{get_flair()} (economy)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (economy)> ")
        try:
            process_input = econ_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #7
0
def menu():
    """Resource Collection Menu"""

    rc_controller = ResourceCollectionController()
    rc_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in rc_controller.CHOICES}
            )
            an_input = session.prompt(
                f"{get_flair()} (resources)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (resources)> ")

        try:
            process_input = rc_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #8
0
def menu(ticker: str, start: datetime, interval: str):
    """Research Menu"""

    res_controller = ResearchController(ticker, start, interval)
    res_controller.call_help(None)
    print("")

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in res_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(res)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(res)> ")

        try:
            process_input = res_controller.switch(an_input)
            print("")

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #9
0
def menu():
    """Forex Menu"""
    fx_controller = ForexController()
    fx_controller.call_help(None)
    while True:
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in fx_controller.CHOICES}
            )

            an_input = session.prompt(
                f"{get_flair()} (forex)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (forex)> ")

        try:
            process_input = fx_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exit\n")
            continue
Exemple #10
0
def menu():
    """Degiro Menu"""

    # SETUP CONTROLLER
    degiro_controller = DegiroController()
    degiro_controller.help()

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in degiro_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (pa)>(degiro)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (pa)>(degiro)> ")

        try:
            process_input = degiro_controller.switch(an_input)

            if process_input is not None:
                return process_input

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

    disc_controller = DiscoveryController()
    disc_controller.call_help(None)

    # Loop forever and ever
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in disc_controller.CHOICES}
            )

            an_input = session.prompt(
                f"{get_flair()} (disc)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (disc)> ")

        try:
            plt.close("all")

            process_input = disc_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(ticker: str, start: Union[str, datetime]):
    """Backtesting Menu"""
    plt.close("all")
    bt_controller = BacktestingController(ticker, start)
    bt_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in bt_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(bt)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(bt)> ")

        try:
            plt.close("all")

            process_input = bt_controller.switch(an_input)
            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(ticker: str, start: datetime, context: str = ""):
    """Behavioural Analysis Menu"""

    ba_controller = BehaviouralAnalysisController(ticker, start)
    ba_controller.call_help(None)

    if context:
        context = f"({context})>"

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in ba_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} {context}(ba)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} {context}(ba)> ")

        try:
            process_input = ba_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #14
0
def menu(ticker: str):
    """Options info Menu."""

    op_controller = OptionsController(ticker)
    op_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in op_controller.CHOICES}
            )
            an_input = session.prompt(
                f"{get_flair()} (op)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (op)> ")

        try:
            plt.close("all")

            process_input = op_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(tickers: List[str]):
    """Portfolio Optimization Menu"""
    if tickers == [""]:
        tickers = []
    plt.close("all")
    po_controller = PortfolioOptimization(tickers)
    po_controller.call_help(tickers)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in po_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (po)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (po)> ")

        try:
            plt.close("all")

            process_input = po_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #16
0
def menu(stock: pd.DataFrame, ticker: str, start: datetime, interval: str):
    """Technical Analysis Menu"""

    ta_controller = TechnicalAnalysisController(stock, ticker, start, interval)
    ta_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in ta_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (ta)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (ta)> ")

        try:
            plt.close("all")

            process_input = ta_controller.switch(an_input)

            if process_input is not None:
                return process_input

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

    robinhood_controller = RobinhoodController()
    robinhood_controller.print_help()

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in robinhood_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (bro)>(rh)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (bro)>(rh)> ")

        try:
            process_input = robinhood_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(coin=None, source=None):

    source = source if source else "cg"
    dd_controller = DueDiligenceController(coin=coin, source=source)
    dd_controller.print_help()

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in dd_controller.CHOICES}
            )
            an_input = session.prompt(
                f"{get_flair()} (crypto)>(dd)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (crypto)>(dd)> ")

        try:
            process_input = dd_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #19
0
def opt_menu(s_ticker):

    # Add list of arguments that the options parser accepts
    opt_parser = argparse.ArgumentParser(prog="opt", add_help=False)
    choices = ["help", "q", "quit", "volume", "oi"]
    opt_parser.add_argument("cmd", choices=choices)
    completer = NestedCompleter.from_nested_dict({c: None for c in choices})

    # print_options(s_ticker, s_start, s_interval)

    # Loop forever and ever
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            as_input = session.prompt(
                f"{get_flair()} (opt)> ",
                completer=completer,
            )
        else:
            as_input = input(f"{get_flair()} (opt)> ")

        # Parse fundamental analysis command of the list of possible commands
        try:
            (ns_known_args,
             l_args) = opt_parser.parse_known_args(as_input.split())

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

        if ns_known_args.cmd == "help":
            pass
            # print_options(s_ticker)

        elif ns_known_args.cmd == "q":
            # Just leave the options menu
            return False

        elif ns_known_args.cmd == "quit":
            # Abandon the program
            return True

        elif ns_known_args.cmd == "volume":
            # call the volume graph
            vol.volume_graph(l_args, s_ticker)

        elif ns_known_args.cmd == "oi":
            # call the volume graph
            vol.open_interest_graph(l_args, s_ticker)
        else:
            print("Command not recognized!")
Exemple #20
0
    def call_exp(self, _):
        """Process exp command."""
        self.print_exp_dates(self.expiry_date, self.raw_data_options.options)

        date_index_choices = list(
            range(len(self.raw_data_options.options) - 1))
        while True:
            # Get input command from user
            if session and gtff.USE_PROMPT_TOOLKIT:
                completer = NestedCompleter.from_nested_dict(
                    {c: None
                     for c in date_index_choices})
                an_input = session.prompt(
                    f"{get_flair()} (exp)> ",
                    completer=completer,
                )
            else:
                an_input = input(f"{get_flair()} (exp)> ")

            try:
                plt.close("all")

                process_input = an_input

                if process_input is not None:
                    try:
                        self.__set_exp_date(int(an_input))
                        print(
                            f"\nNew selected expiry date : [{self.expiry_date}]\n"
                        )
                        return
                        # menu(self.ticker, self)
                    except IndexError:
                        print(
                            f"\nSelection must be between [0 - {len(self.raw_data_options.options) - 1}]\n"
                        )
                        continue
                    except ValueError:
                        print("The command selected doesn't exist\n")
                        self.print_exp_dates(self.expiry_date,
                                             self.raw_data_options.options)

            except SystemExit:
                print("The command selected doesn't exist\n")
                continue
Exemple #21
0
def menu(ticker: str = "",
         start: str = "",
         stock: pd.DataFrame = pd.DataFrame()):
    """Dark Pool Shorts Menu

    Parameters
    ----------
    stock : DataFrame
        Due diligence stock dataframe
    ticker : str
        Due diligence ticker symbol
    start : str
        Start date of the stock data
    """
    dps_controller = DarkPoolShortsController(ticker, start, stock)
    dps_controller.call_help(None)

    # Loop forever and ever
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in dps_controller.CHOICES})

            an_input = session.prompt(
                f"{get_flair()} (stocks)>(dps)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(dps)> ")

        try:
            plt.close("all")

            process_input = dps_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(ticker: str, start: str, interval: str, stock: pd.DataFrame):
    """Comparison Analysis Menu

    Parameters
    ----------
    ticker : str
        Stock ticker
    start : str
        Time start
    interval : str
        Time interval
    stock : pd.DataFrame
        Stock data
    """

    ca_controller = ComparisonAnalysisController(ticker, start, interval,
                                                 stock)
    ca_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in ca_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(ca)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(ca)> ")

        try:
            plt.close("all")

            process_input = ca_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #23
0
def menu(stock: DataFrame, ticker: str, start: str, interval: str):
    """Due Diligence Menu

    Parameters
    ----------
    stock : DataFrame
        Due diligence stock dataframe
    ticker : str
        Due diligence ticker symbol
    start : str
        Start date of the stock data
    interval : str
        Stock data interval
    """

    dd_controller = DueDiligenceController(stock, ticker, start, interval)
    dd_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None for c in dd_controller.CHOICES}
            )

            an_input = session.prompt(
                f"{get_flair()} (dd)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (dd)> ")

        try:
            process_input = dd_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
def menu(ticker: str, start: str, interval: str):
    """Fundamental Analysis menu

    Parameters
    ----------
    ticker : str
        Fundamental analysis ticker symbol
    start : str
        Start date of the stock data
    interval : str
        Stock data interval
    """

    fa_controller = FundamentalAnalysisController(ticker, start, interval)
    fa_controller.call_help(None)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in fa_controller.CHOICES})

            an_input = session.prompt(
                f"{get_flair()} (fa)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (fa)> ")

        try:
            process_input = fa_controller.switch(an_input)

            if process_input is not None:
                return process_input

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

    # SETUP CREDENTIALS
    credentials = Credentials(
        int_account=None,
        username=config.DG_USERNAME,
        password=config.DG_PASSWORD,
        one_time_password=None,
        totp_secret_key=config.DG_TOTP_SECRET,
    )

    # SETUP CONTROLLER
    degiro_controller = DegiroController(credentials=credentials)
    degiro_controller.help()

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in degiro_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (pa)>(degiro)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (pa)>(degiro)> ")

        try:
            process_input = degiro_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #26
0
def menu():
    """Brokers Menu"""
    bro_controller = BrokersController()
    print(
        "\nUSE THIS MENU AT YOUR OWN DISCRETION\n"
        "   - This menu is the only one in the entire repository that has access to your broker accounts. "
        "If you have provided your login details on the config_terminal.py file"
        "   - We review the code thoroughly from each contributor, hence, we can ensure that our codebase "
        "does not take advantage of your data.\n"
        "   - HOWEVER, our project imports almost 200 different open source python modules. Therefore, it "
        "is impossible for us to check the coding standards and security of each of these modules. "
        "Hence why adding this disclaimer here.\n")
    bro_controller.print_help()

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in bro_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (bro)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (bro)> ")

        try:
            process_input = bro_controller.switch(an_input)

            if process_input is not None:
                return process_input

        except SystemExit:
            print("The command selected doesn't exist\n")
            continue
Exemple #27
0
def menu():
    """Report Menu"""
    report_controller = ReportController()
    report_controller.call_help(None)

    # Initialize jupyter notebook
    cmd = f"jupyter notebook --port={config_terminal.PAPERMILL_NOTEBOOK_REPORT_PORT}"
    proc = subprocess.Popen(cmd,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT)

    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            completer = NestedCompleter.from_nested_dict(
                {c: None
                 for c in report_controller.CHOICES})
            an_input = session.prompt(
                f"{get_flair()} (stocks)>(report)> ",
                completer=completer,
            )
        else:
            an_input = input(f"{get_flair()} (stocks)>(report)> ")

        try:
            process_input = report_controller.switch(an_input, proc)
        except SystemExit:
            print("The command selected doesn't exist\n")
            continue

        if process_input is False:
            return False

        if process_input is True:
            return True
Exemple #28
0
def menu(queue: List[str] = None):
    """NFT Menu"""
    nft_controller = NFTController(queue=queue)
    an_input = "HELP_ME"

    while True:
        # There is a command in the queue
        if nft_controller.queue and len(nft_controller.queue) > 0:
            # If the command is quitting the menu we want to return in here
            if nft_controller.queue[0] in ("q", "..", "quit"):
                if len(nft_controller.queue) > 1:
                    return nft_controller.queue[1:]
                return []

            # Consume 1 element from the queue
            an_input = nft_controller.queue[0]
            nft_controller.queue = nft_controller.queue[1:]

            # Print the current location because this was an instruction and we want user to know what was the action
            if an_input and an_input.split(" ")[0] in nft_controller.CHOICES_COMMANDS:
                print(f"{get_flair()} /crypto/nft/ $ {an_input}")

        # Get input command from user
        else:
            # Display help menu when entering on this menu from a level above
            if an_input == "HELP_ME":
                nft_controller.print_help()

            # Get input from user using auto-completion
            if session and gtff.USE_PROMPT_TOOLKIT and nft_controller.completer:
                an_input = session.prompt(
                    f"{get_flair()} /crypto/nft/ $ ",
                    completer=nft_controller.completer,
                    search_ignore_case=True,
                )
            # Get input from user without auto-completion
            else:
                an_input = input(f"{get_flair()} /crypto/nft/ $ ")

        try:
            # Process the input command
            nft_controller.queue = nft_controller.switch(an_input)

        except SystemExit:
            print(
                f"\nThe command '{an_input}' doesn't exist on the /stocks/options menu.",
                end="",
            )
            similar_cmd = difflib.get_close_matches(
                an_input.split(" ")[0] if " " in an_input else an_input,
                nft_controller.CHOICES,
                n=1,
                cutoff=0.7,
            )
            if similar_cmd:
                if " " in an_input:
                    candidate_input = (
                        f"{similar_cmd[0]} {' '.join(an_input.split(' ')[1:])}"
                    )
                    if candidate_input == an_input:
                        an_input = ""
                        nft_controller.queue = []
                        print("\n")
                        continue
                    an_input = candidate_input
                else:
                    an_input = similar_cmd[0]

                print(f" Replacing by '{an_input}'.")
                nft_controller.queue.insert(0, an_input)
            else:
                print("\n")
Exemple #29
0
def terminal():
    """Terminal Menu"""

    bootup()
    process_input = False
    t_controller = TerminalController()

    if config_terminal.DEFAULT_CONTEXT:
        if config_terminal.DEFAULT_CONTEXT in t_controller.CHOICES_MENUS:
            try:
                print("")
                process_input = t_controller.switch(
                    config_terminal.DEFAULT_CONTEXT.lower())
            except SystemExit:
                print("")
        else:
            print("\nInvalid DEFAULT_CONTEXT config selected!", "\n")

    if not process_input:
        t_controller.print_help()
        parsed_stdin = False

        while True:
            if gtff.ENABLE_QUICK_EXIT:
                print("Quick exit enabled")
                break

            # Get input command from stdin or user
            if not parsed_stdin and len(sys.argv) > 1:
                an_input = " ".join(sys.argv[1:])
                print(f"{get_flair()}> {an_input}")
                parsed_stdin = True

            elif session and gtff.USE_PROMPT_TOOLKIT:
                an_input = session.prompt(f"{get_flair()}> ",
                                          completer=t_controller.completer)

            else:
                an_input = input(f"{get_flair()}> ")

            # Is command empty
            if not an_input:
                print("")
                continue

            # Process list of commands selected by user
            try:
                process_input = t_controller.switch(an_input)
                # None - Keep loop
                # True - Quit or Reset based on flag
                # False - Keep loop and show help menu

                if process_input is not None:
                    # Quit terminal
                    if process_input:
                        break

                    t_controller.print_help()

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

        if not gtff.ENABLE_QUICK_EXIT:
            # Check if the user wants to reset application
            if an_input == "reset" or t_controller.update_succcess:
                ret_code = reset()
                if ret_code != 0:
                    print_goodbye()
            else:
                print_goodbye()
def sen_menu(s_ticker, s_start):

    # Add list of arguments that the discovery parser accepts
    sen_parser = argparse.ArgumentParser(prog="sen", add_help=False)
    choices = [
        "help",
        "q",
        "quit",
        "watchlist",
        "spac",
        "spac_c",
        "wsb",
        "popular",
        "bullbear",
        "messages",
        "trending",
        "stalker",
        "infer",
        "sentiment",
        "mentions",
        "regions",
        "queries",
        "rise",
    ]
    sen_parser.add_argument("cmd", choices=choices)
    completer = NestedCompleter.from_nested_dict({c: None for c in choices})

    print_sentiment()

    # Loop forever and ever
    while True:
        # Get input command from user
        if session and gtff.USE_PROMPT_TOOLKIT:
            as_input = session.prompt(
                f"{get_flair()} (sen)> ",
                completer=completer,
            )
        else:
            as_input = input(f"{get_flair()} (sen)> ")

        # Parse sentiment command of the list of possible commands
        try:
            (ns_known_args,
             l_args) = sen_parser.parse_known_args(as_input.split())

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

        if ns_known_args.cmd == "help":
            print_sentiment()

        elif ns_known_args.cmd == "q":
            # Just leave the DISC menu
            return False

        elif ns_known_args.cmd == "quit":
            # Abandon the program
            return True

        elif ns_known_args.cmd == "watchlist":
            reddit_api.watchlist(l_args)

        elif ns_known_args.cmd == "spac":
            reddit_api.spac(l_args)

        elif ns_known_args.cmd == "spac_c":
            reddit_api.spac_community(l_args)

        elif ns_known_args.cmd == "wsb":
            reddit_api.wsb_community(l_args)

        elif ns_known_args.cmd == "popular":
            reddit_api.popular_tickers(l_args)

        elif ns_known_args.cmd == "bullbear":
            stocktwits_api.bullbear(l_args, s_ticker)

        elif ns_known_args.cmd == "messages":
            stocktwits_api.messages(l_args, s_ticker)

        elif ns_known_args.cmd == "trending":
            stocktwits_api.trending(l_args)

        elif ns_known_args.cmd == "stalker":
            stocktwits_api.stalker(l_args)

        elif ns_known_args.cmd == "infer":
            if not gtff.ENABLE_PREDICT:
                print("Predict is not enabled in feature_flags.py")
                print("Twitter inference menu is disabled")
                print("")
                continue

            try:
                # pylint: disable=import-outside-toplevel
                from gamestonk_terminal.sentiment import twitter_api
            except ModuleNotFoundError as e:
                print("One of the optional packages seems to be missing")
                print("Optional packages need to be installed")
                print(e)
                print("")
                continue
            except Exception as e:
                print(e)
                print("")
                continue

            twitter_api.inference(l_args, s_ticker)

        elif ns_known_args.cmd == "sentiment":
            if not gtff.ENABLE_PREDICT:
                print("Predict is not enabled in config_terminal.py")
                print("Twitter sentiment menu is disabled")
                print("")
                continue

            try:
                # pylint: disable=import-outside-toplevel
                from gamestonk_terminal.sentiment import twitter_api
            except ModuleNotFoundError as e:
                print("One of the optional packages seems to be missing")
                print("Optional packages need to be installed")
                print(e)
                print("")
                continue
            except Exception as e:
                print(e)
                print("")
                continue

            twitter_api.sentiment(l_args, s_ticker)

        elif ns_known_args.cmd == "mentions":
            google_api.mentions(l_args, s_ticker, s_start)

        elif ns_known_args.cmd == "regions":
            google_api.regions(l_args, s_ticker)

        elif ns_known_args.cmd == "queries":
            google_api.queries(l_args, s_ticker)

        elif ns_known_args.cmd == "rise":
            google_api.rise(l_args, s_ticker)

        else:
            print("Command not recognized!")