async def run_app(host: str, reader_port: int, writer_port: int, token: str, history_path: str) -> None: messages_queue = asyncio.Queue() sending_queue = asyncio.Queue() status_updates_queue = asyncio.Queue() history_queue = asyncio.Queue() watchdog_queue = asyncio.Queue() history.load_history(history_path, messages_queue) async with create_handy_nursery() as nursery: nursery.start_soon( gui.draw(messages_queue, sending_queue, status_updates_queue)) nursery.start_soon( history.save_messages(filepath=history_path, history_queue=history_queue)) nursery.start_soon( handle_connection(host=host, reader_port=reader_port, writer_port=writer_port, token=token, messages_queue=messages_queue, status_queue=status_updates_queue, history_queue=history_queue, sending_queue=sending_queue, watchdog_queue=watchdog_queue))
def HandleHistory(): history_object = history.load_history(Data) oc = ObjectContainer(title2=unicode(L('History'))) if history_object: data = sorted(history_object.values(), key=lambda k: k['time'], reverse=True) service.queue.handle_queue_items(oc, HandleContainer, data) return oc
def output_history(): db = history.load_history() if db["games"] is 0: print(figlet_format("0 games played!", font="big")) else: if db["games"] is 1: print(figlet_format("{0} total game!".format(db["games"]), font="big")) else: print(figlet_format("{0} total games!".format(db["games"]), font="big")) if "draw" in db["wins"]: if db["wins"]["draw"] is 1: print(figlet_format("{0} draw!".format(db["wins"]["draw"]), font="big")) else: print(figlet_format("{0} draws!".format(db["wins"]["draw"]), font="big")) for name in db["wins"]: if name != "draw": if db["wins"][name] is 1: print(figlet_format("{0} has {1} win!".format(name, db["wins"][name]), font="big")) else: print(figlet_format("{0} has {1} wins!".format(name, db["wins"][name]), font="big"))
def init_terminal(): # Init readline history.load_history() # Tab completion readline.parse_and_bind('tab: complete')
def main_arbitrage(): # sym = 'tqqq' # sym = 'spy' sym = 'qqq' options_date = '2020-06-18' # stats_df = history.find_correlations_with('SPY', abscorrthresh=.99) stats_df = history.find_correlations_with(sym, abscorrthresh=.98) # stats_df.index = stats_df['Symbol'] stats_df.set_index(stats_df['Symbol'], inplace=True) calls0, puts0, bid, ask = options_for_symbol( sym, date=options_date, normalize=True) # curprice0 = infer_underlying_curprice(calls0, puts0) # calls0 = normalize_options(calls0, curprice0) # puts0 = normalize_options(puts0, curprice0) hist0 = history.load_history(sym, resolution='week') solutions = [] for s in stats_df['Symbol'].values: try: calls, puts, bid, ask = options_for_symbol( s, date=options_date, normalize=True) except IndexError: continue # yfinance failed at downloading the options # curprice = infer_underlying_curprice(calls, puts) print("s, curprice: ", s, bid) # calls = normalize_options(calls, curprice) # puts = normalize_options(puts, curprice) stats = stats_df.loc[s] # print(stats) hist1 = history.load_history(s, resolution='week') # TODO use actual histories / pdfs as samples keys, score, best_outcomes = check_arbitrage( stats, calls0, puts0, calls, puts) # stats, calls0, puts0, calls, puts, # samples0=hist0, samples1=hist1) if score > 0: k0, k1 = keys opt0 = [sym, *k0[:2], np.round(k0[2] * bid * 2) / 2] opt1 = [s, *k1[:2], np.round(k1[2] * bid * 2) / 2] solutions.append((opt0, opt1, score, best_outcomes.mean())) # solutions.append((sym, s, keys, score, best_outcomes)) # print(solutions) # sym_s_key_score_list = [soln[:4] for soln in solutions] import pprint pprint.pprint(solutions) # pprint.pprint(sym_s_key_score_list) # sym_s_key_score_list = sorted(sym_s_key_score_list, key=lambda tup: tup[-1]) # for i, elem in enumerate(sym_s_key_score_list): # k0, k1 = elem[2] # k # print(solutions) return solutions