def render_defaults(feedback): defaults, types = plumb.GetDefaults(False) tradier_key_warning = "" if ("tradier key" in defaults): if (defaults['tradier key'] == "" or defaults['tradier key'] == "demo"): tradier_key_warning = "Remember to obtain your lifetime API key from tradier, this is needed for getting the market calendar and quotes" IEX_key_warning = "" if ("IEX key" in defaults): if (defaults['IEX key'] == "" or defaults['IEX key'] == "demo"): IEX_key_warning = "Remember to obtain your lifetime API key from IEX cloud, this is needed for getting company ticker information" coin_key_warning = "" if ("coin key" in defaults): if (defaults['coin key'] == "" or defaults['coin key'] == "demo"): coin_key_warning = "Remember to obtain your lifetime API key from coin market cap, this is needed for getting cryptocoin information" table, column_options, name_options, folder_options = plumb.PrintDefaults( False) hide_folder = "" if (name_options == ""): hide_folder = "hidden" notes, initialize_day = plumb.GetAIMNotes(10, False) if os.name == 'nt': pid = plumb.get_pid("poll_stocks.py") else: pid = plumb.get_pid("folder_daemon.py") daemon_check = "" daemon_color = "green;" daemon_action = "" if (pid == []): daemon_check = "WARNING: stock polling is not running, your stocks are not updating, please start" daemon_color = "red;" daemon_action = "start" else: daemon_check = "stock polling is running on pid: {0}".format(pid[0]) daemon_action = "restart" daemon_table, status = plumb.PrintDaemon("all", False) daemon_info = "" checkOpen = plumb.Holiday(False) if checkOpen: if (checkOpen['status'] == "closed"): daemon_info = checkOpen['description'] else: daemon_info = "{0}, Last active status: {1}".format( checkOpen['description'], status) return (render_template('defaults.html', table=table, feedback=feedback, column_options=column_options, notes=notes, daemon_table=daemon_table, daemon_check=daemon_check, daemon_color=daemon_color, daemon_info=daemon_info, daemon_action=daemon_action, name_options=name_options, folder_options=folder_options, hide_folder=hide_folder, tradier_key_warning=tradier_key_warning, IEX_key_warning=IEX_key_warning, coin_key_warning=coin_key_warning))
def render_folder(ticker_style, feedback, symbol): defaults, types = plumb.GetDefaults(False) folder_name = "folder" if ("folder name" in defaults): folder_name = defaults['folder name'] table, symbol_options, balance_options, amount_options = plumb.PrintFolder( False) notes, initialize_day = plumb.GetAIMNotes(10, False) co = {} if (symbol > ""): co = plumb.Company(symbol, False) if not co: feedback = "symbol not found." ticker_style = "display: none;" worksheet_table, worksheet_warning = plumb.PrintWorksheet(False) worksheet_style = "display: none;" if worksheet_table > "": worksheet_style = "display: block;" return (render_template('folder.html', table=table, ticker_style=ticker_style, symbol_options=symbol_options, balance_options=balance_options, notes=notes, ticker=co, feedback=feedback, amount_options=amount_options, folder_name=folder_name, worksheet_table=worksheet_table, worksheet_style=worksheet_style, worksheet_warning=worksheet_warning))
def render_history(feedback): notes, initialize_day = plumb.GetAIMNotes(10, False) table, export_options = plumb.PrintAIM("all", False) archive_table = plumb.PrintSummary(False) return render_template('history.html', table=table, notes=notes, feedback=feedback, archive_table=archive_table, export_options=export_options)
def render_index(feedback): if os.name == 'nt': pid = plumb.get_pid("poll_stocks.py") else: pid = plumb.get_pid("folder_daemon.py") if (pid == []): if os.name == 'nt': plumb.run_script("poll_stocks.py") else: plumb.run_script("./folder_daemon.py") if (feedback == ""): feedback = "stock polling started" l, table, db = plumb.Look(False) trends, lives, percents = plumb.AllocationTrends(False) notes, initialize_day = plumb.GetAIMNotes(10, False) post_display = "post" initialize_prompt = "" if db == {} or initialize_day: post_display = "initialize" initialize_prompt = "You may reinitialize until tomorrow to make sure you have your portfolio balances the way you want." post_background = "" if not initialize_day: if "market order" in db: if (db['market order'] > 0): post_background = "background: blue;" post_display = "buy" if (db['market order'] < 0): post_background = "background: green;" post_display = "sell" balance_list = "" initial_value = "" profit_value = "" profit_percent = "" if "percent list" in l: balance_list = l['percent list'] initial_value = l['initial value'] profit_value = l['profit value'] profit_percent = l['profit percent'] return render_template('index.html', table=table, balance_list=balance_list, initial_value=initial_value, profit_value=profit_value, profit_percent=profit_percent, notes=notes, feedback=feedback, post_display=post_display, post_background=post_background, initialize_prompt=initialize_prompt, trends=trends, lives=lives, percents=percents)
def main(argv): verbose = False test = "" aim = "" initialize = False notes = "" look = False update = False allo = False export = "" save = False try: opts, args = getopt.getopt(argv, "se:ailun:hvt:", ["help", "verbose", "test=", "notes=", "look", "update", "initialize", "allocation", "export=", "save"]) except getopt.GetoptError as err: print(err) usage() sys.exit(2) for o, a in opts: if o in ("-v", "--verbose"): verbose = True elif o in ("-a", "--allocation"): allo = True elif o in ("-t", "--test"): test = a elif o in ("-h", "--help"): usage() exit() elif o in ("-n", "--notes"): notes = a elif o in ("-e", "--export"): export = a elif o in ("-i", "--initialize"): initialize = True elif o in ("-l", "--look"): look = True elif o in ("-s", "--save"): save = True elif o in ("-u", "--update"): update = True else: assert False, "unhandled option" defaults, types = plumb.GetDefaults(False) if defaults['folder name'] is None: print ("\tWarning, the folder name is missing, please correct") exit() if defaults['test root'] is None: print ("\tWarning, the test root path is not set, please correct") exit() if (test > ""): testResult = plumb.TestAIM(test, verbose) print (testResult['output']) exit() if (notes > ""): notesResult, initialize_day = plumb.GetAIMNotes(notes, verbose) print (notesResult) if initialize_day: print("AIM system was initialized today") exit() if (initialize): nowResult, log = plumb.CreateAIM(verbose) print (nowResult, log) exit() if (look): lookResult, lookHTML, lookDB = plumb.Look(verbose) pprint.pprint(lookResult) pprint.pprint(lookHTML) pprint.pprint(lookDB) exit() if (update): postResult = plumb.Post(verbose) if (postResult): print ("updated.") else: print ("failed.") exit() if (allo): allocation_list, trending_list, life_list = plumb.AllocationTrends(verbose) pprint.pprint(allocation_list) pprint.pprint(trending_list) pprint.pprint(life_list) exit() if (export > ""): exportResult = plumb.Export(export, "", verbose) print (exportResult) exit() if (save): saveResult = plumb.Archive(verbose) if (saveResult): print ("updated.") else: print ("failed.") exit() usage()