def __init__(self, queue: List[str] = None): """Constructor""" self.port_parser = argparse.ArgumentParser(add_help=False, prog="portfolio") self.port_parser.add_argument( "cmd", choices=self.CHOICES, ) self.completer: Union[None, NestedCompleter] = None if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} self.completer = NestedCompleter.from_nested_dict(choices) if queue: self.queue = queue else: self.queue = list() self.portfolio = pd.DataFrame( columns=[ "Name", "Type", "Quantity", "Date", "Price", "Fees", "Premium", "Side", ] )
def __init__( self, custom_df: pd.DataFrame, file: str, queue: List[str] = None, ): """Constructor""" super().__init__(queue) self.DATA_FILES = [ file.name for file in Path("custom_imports").iterdir() ] self.df = custom_df self.ticker = file self.file = file self.target = custom_df.columns[2] if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["pick"] = {c: None for c in self.df.columns} choices["load"]["-r"] = {c: {} for c in stocks_helper.INTERVALS} choices["pick"] = {c: {} for c in self.df.columns} choices["ets"]["-t"] = {c: {} for c in ets_model.TRENDS} choices["ets"]["-s"] = {c: {} for c in ets_model.SEASONS} choices["arima"]["-i"] = {c: {} for c in arima_model.ICS} choices["mc"]["--dist"] = {c: {} for c in mc_model.DISTRIBUTIONS} self.choices = choices self.completer = NestedCompleter.from_nested_dict(choices)
def menu(ticker: str, start: datetime, interval: str, stock: pd.DataFrame): """Technical Analysis Menu""" ta_controller = TechnicalAnalysisController(ticker, start, interval, stock) 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()} (stocks)>(ta)> ", completer=completer, ) else: an_input = input(f"{get_flair()} (stocks)>(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(): """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(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
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
def __init__( self, queue: List[str] = None, ): """Constructor""" self.scr_parser = argparse.ArgumentParser(add_help=False, prog="scr") self.scr_parser.add_argument( "cmd", choices=self.CHOICES, ) self.completer: Union[None, NestedCompleter] = None if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} choices["view"] = {c: None for c in self.preset_choices} choices["set"] = {c: None for c in self.preset_choices} choices["sbc"] = { c: None for c in financedatabase_model.get_etfs_categories() } self.completer = NestedCompleter.from_nested_dict(choices) self.preset = "etf_config" self.screen_tickers: List = list() if queue: self.queue = queue else: self.queue = list()
def __init__(self, ticker: str, expiration: str, queue: List[str] = None): """Constructor""" super().__init__(queue) self.chain = get_option_chain(ticker, expiration) self.calls = list( zip( self.chain.calls["strike"].tolist(), self.chain.calls["lastPrice"].tolist(), )) self.puts = list( zip( self.chain.puts["strike"].tolist(), self.chain.puts["lastPrice"].tolist(), )) self.ticker = ticker self.current_price = get_price(ticker) self.expiration = expiration self.options: List[Dict[str, str]] = [] self.underlying = 0 self.call_index_choices = range(len(self.calls)) self.put_index_choices = range(len(self.puts)) if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["pick"] = {c: {} for c in self.underlying_asset_choices} choices["add"] = { str(c): {} for c in list(range(max(len(self.puts), len(self.calls)))) } # This menu contains dynamic choices that may change during runtime self.choices = choices self.completer = NestedCompleter.from_nested_dict(choices)
def __init__( self, ticker: str, queue: List[str] = None, ): """Constructor""" self.gov_parser = argparse.ArgumentParser(add_help=False, prog="gov") self.gov_parser.add_argument( "cmd", choices=self.CHOICES, ) self.completer: Union[None, NestedCompleter] = None if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} choices["lasttrades"] = {c: {} for c in self.gov_type_choices} choices["topbuys"] = {c: {} for c in self.gov_type_choices} choices["topsells"] = {c: {} for c in self.gov_type_choices} choices["qtrcontracts"]["-a"] = { c: {} for c in self.analysis_choices } choices["qtrcontracts"]["--analysis"] = { c: {} for c in self.analysis_choices } self.completer = NestedCompleter.from_nested_dict(choices) if queue: self.queue = queue else: self.queue = list() self.ticker = ticker
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
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 test_complete_word() -> None: w = WordCompleter(["aaa", "bbb", "ccc"]) assert complete("", w) == {"aaa", "bbb", "ccc"} assert complete("a", w) == {"aaa"} n = NestedCompleter.from_nested_dict({ "aggregate": WordCompleter(["avg", "sum", "count"]), "ancestors": { "--with-origin": None, "default": { "foo": { "bla": {"bar"} } }, "delete": None, }, }) assert complete("", n) == {"aggregate", "ancestors"} # nested assert complete("anc", n) == {"ancestors"} assert complete("ancestors ", n) == {"--with-origin", "default", "delete"} assert complete("ancestors --", n) == {"--with-origin"} assert complete("ancestors default foo ", n) == {"bla"} assert complete("ancestors default foo bla ", n) == {"bar"} # words assert complete("aggregate ", n) == {"avg", "sum", "count"} assert complete("aggregate a", n) == {"avg"}
def __init__(self, queue: List[str] = None): """Constructor""" self.fund_parser = argparse.ArgumentParser(add_help=False, prog="fund") self.fund_parser.add_argument("cmd", choices=self.CHOICES) self.country = "united states" self.completer: Union[None, NestedCompleter] = None self.data = pd.DataFrame() self.fund_name = "" self.fund_symbol = "" if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} choices["country"] = {c: None for c in self.fund_countries} choices["search"]["-b"] = {c: None for c in self.search_by_choices} choices["search"]["--by"] = { c: None for c in self.search_by_choices } choices["search"]["-s"] = {c: None for c in self.search_cols} choices["search"]["--sortby"] = {c: None for c in self.search_cols} self.completer = NestedCompleter.from_nested_dict(choices) if queue: self.queue = queue else: self.queue = list()
def __init__( self, ticker: str, start: str, interval: str, stock: pd.DataFrame, queue: List[str] = None, ): """Constructor""" self.insider_parser = argparse.ArgumentParser(add_help=False, prog="ins") self.insider_parser.add_argument( "cmd", choices=self.CHOICES, ) self.completer: Union[None, NestedCompleter] = None if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} choices["view"] = {c: None for c in self.preset_choices} choices["set"] = {c: None for c in self.preset_choices} self.completer = NestedCompleter.from_nested_dict(choices) if queue: self.queue = queue else: self.queue = list() self.ticker = ticker self.start = start self.interval = interval self.stock = stock self.preset = "whales"
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(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
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 __init__(self, queue: List[str] = None): """Constructor""" super().__init__(queue) self.symbol = "" self.current_coin = "" self.current_df = pd.DataFrame() self.current_currency = "" self.source = "" self.coin_map_df = pd.DataFrame() self.current_interval = "" self.price_str = "" if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["load"]["--source"] = { c: {} for c in CRYPTO_SOURCES.keys() } choices["find"]["--source"] = { c: {} for c in CRYPTO_SOURCES.keys() } choices["find"]["-k"] = {c: {} for c in FIND_KEYS} choices["headlines"] = {c: {} for c in finbrain_crypto_view.COINS} # choices["prt"]["--vs"] = {c: {} for c in coingecko_coin_ids} # list is huge. makes typing buggy self.completer = NestedCompleter.from_nested_dict(choices)
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
def get_completer(cls): return NestedCompleter.from_nested_dict({ cls.ENV_COMMAND_CLEAR: None, cls.ENV_COMMAND_LIST: { "clusters": None } })
def __init__(self, queue: List[str] = None): """Constructor""" super().__init__(queue) if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} self.completer = NestedCompleter.from_nested_dict(choices)
def prompt(session): ''' mec prompt ''' cmd_list = readline_init(session) # cook our completions completion_dict = dict.fromkeys(cmd_list) completion_dict["target"] = dict.fromkeys(os.listdir("./data")) completion_dict["set"] = dict.fromkeys(["auto-update", "proxy-pool"]) completion_dict["set"]["auto-update"] = dict.fromkeys(["True", "False"]) mec_completer = NestedCompleter.from_nested_dict(completion_dict) mec_ps = ANSI(colors.CYAN + colors.BOLD + "\nmec > " + colors.END) cmd_autosuggest = ThreadedAutoSuggest(MecAutoSuggest(completions=cmd_list)) try: mecprompt = PromptSession(message=mec_ps, mouse_support=True, history=FileHistory(HISTFILE), completer=mec_completer, complete_while_typing=True, reserve_space_for_menu=2, auto_suggest=cmd_autosuggest).prompt() except termios.error as err: colors.colored_print(f"[-] Fatal error: {err}", color_code=colors.RED) os.system("mec stop") return mecprompt
def __init__( self, ticker: str, start: datetime, data: pd.DataFrame, queue: List[str] = None, ): """Constructor""" self.ticker = ticker self.start = start self.data = data self.ta_parser = argparse.ArgumentParser(add_help=False, prog="ta") self.ta_parser.add_argument( "cmd", choices=self.CHOICES, ) self.completer: Union[None, NestedCompleter] = None if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.CHOICES} self.completer = NestedCompleter.from_nested_dict(choices) if queue: self.queue = queue else: self.queue = list()
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(): """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
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()} (stocks)>(disc)> ", completer=completer, ) else: an_input = input(f"{get_flair()} (stocks)>(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 __init__(self, queue: List[str] = None): """Constructor""" super().__init__(queue) self.portfolio = pd.DataFrame(columns=[ "Name", "Type", "Quantity", "Date", "Price", "Fees", "Premium", "Side", ]) self.portfolio_name = "" self.portlist: List[str] = os.listdir(portfolios_path) self.portfolio = portfolio_model.Portfolio() if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["load"] = {c: None for c in self.portlist} choices["save"] = {c: None for c in self.portlist} self.choices = choices self.completer = NestedCompleter.from_nested_dict(choices)
def __init__( self, coin: str, data: pd.DataFrame, queue: List[str] = None, ): """Constructor""" super().__init__(queue) data["Returns"] = data["Close"].pct_change() data["LogRet"] = np.log(data["Close"]) - np.log(data["Close"].shift(1)) data = data.dropna() self.data = data self.coin = coin self.resolution = "1D" self.target = "Close" self.symbol = "" self.current_currency = "" self.source = "" self.coin_map_df = pd.DataFrame() self.current_interval = "" self.price_str = "" if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["load"]["-r"] = {c: {} for c in c_help.INTERVALS} choices["pick"] = {c: {} for c in self.data.columns} choices["ets"]["-t"] = {c: {} for c in ets_model.TRENDS} choices["ets"]["-s"] = {c: {} for c in ets_model.SEASONS} choices["arima"]["-i"] = {c: {} for c in arima_model.ICS} choices["mc"]["--dist"] = {c: {} for c in mc_model.DISTRIBUTIONS} self.completer = NestedCompleter.from_nested_dict(choices)
def __init__( self, ticker: str, start: datetime, interval: str, stock: pd.DataFrame, queue: List[str] = None, ): """Constructor""" super().__init__(queue) stock["Returns"] = stock["Adj Close"].pct_change() stock["LogRet"] = np.log(stock["Adj Close"]) - np.log( stock["Adj Close"].shift(1)) stock["LogPrice"] = np.log(stock["Adj Close"]) stock = stock.rename(columns={"Adj Close": "AdjClose"}) stock = stock.dropna() stock.columns = [x.lower() for x in stock.columns] self.stock = stock self.ticker = ticker self.start = start self.interval = interval self.target = "returns" if session and gtff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} choices["pick"] = {c: None for c in list(stock.columns)} choices["load"]["-i"] = {c: None for c in self.stock_interval} choices["load"]["--interval"] = { c: None for c in self.stock_interval } choices["load"]["--source"] = {c: None for c in self.stock_sources} self.completer = NestedCompleter.from_nested_dict(choices)