def initialize_tables(self): if no_price_data_table_exists(): create_price_data_table() if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table()
def main(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() merkatos = get_all_merkatos() for merkato in merkatos: exchange_name = merkato['exchange'] exchange_class = get_relevant_exchange(exchange_name) round_trip_fee = round_trip_exchange_fees[exchange_name] config = load_config(exchange_name) exchange = exchange_class(config, merkato['alt'], merkato['base']) last_trade_price = exchange.get_last_trade_price() spread = merkato['spread'] initial_base = float(merkato['bid_reserved_balance']) * 4 + float(merkato['base_profit']) initial_quote = float(merkato['ask_reserved_balance']) * 4 + float(merkato['quote_profit']) quote_volume = merkato['quote_volume'] base_volume = merkato['base_volume'] UUID = merkato['exchange_pair'] base_profit = (base_volume) * (spread - round_trip_fee) quote_profit = (quote_volume) * (spread - round_trip_fee) print('STATS FOR {}'.format(UUID)) print('Quote Volume: {} Base Volume: {}'.format(quote_volume, base_volume)) print('Quote Profit: {} Base Profit: {}'.format(quote_profit, base_profit)) relative_base_prof = str((base_profit/initial_base) * 100) + '%' relative_quote_prof = str((quote_profit/initial_quote ) * 100) + '%' print('Relative Quote Profit: {} Relative Base Profit: {}'.format(relative_quote_prof, relative_base_prof)) print('*WARNING THIS RESET SHOULD ONLY BE DONE ON AT THE END OF EVERY MONTH, AND WILL REMOVE ALL CURRENT VOLUME*') print('*ANY FEE SHOULD BE REMOVED FROM THE ACCOUNT IMMIEDIATELY AFTER*') choice_to_continue = input('Would you like to continue? (y/n)') should_continue = choice_to_continue == 'y' or choice_to_continue == 'Y' if should_continue: print('The base profit that will be added to the account is {}'.format(base_profit * .7)) print('The quote profit that will be added to the account is {}'.format(quote_profit * .7)) print('The starting_price that will be updated for the merkato is {}'.format(last_trade_price)) finalize_choice = input('Do these numbers look correct?(y/n)') should_execute = finalize_choice == 'y' or choice_to_continue == 'Y' if should_execute: new_base_profit = merkato['base_profit'] + (base_profit * .7) new_quote_profit = merkato['quote_profit'] + (quote_profit * .7) update_merkato(UUID, 'base_profit', new_base_profit) update_merkato(UUID, 'quote_profit', new_quote_profit) update_merkato(UUID, 'base_volume', 0) update_merkato(UUID, 'quote_volume', 0) update_merkato(UUID, 'starting_price', last_trade_price) print('Profits updated new base:{} new quote: {} new starting_price: {}'.format(new_base_profit, new_quote_profit, last_trade_price))
def main(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() else: should_drop_merkatos = input('Do you want to drop merkatos? y/n: ') if should_drop_merkatos == 'y': drop_merkatos_table() create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() configuration = parse() if not configuration: configuration = get_config() if not configuration: raise Exception("Failed to get configuration.") base = "BTC" coin = "XMR" spread = .02 coin_reserve = 17 base_reserve = .4 print("Would you like to start the merkato?") print("1. If so, type 'Y'") print("2. If not, 'N'") should_start = input("Selection: ") print('should_start', should_start) if should_start != 'Y' and should_start != 'y': return False merkato = Merkato(configuration, coin, base, spread, base_reserve, coin_reserve) context = merkato.update() print('context', context) visualize_orderbook(context["orderbook"]) while True: context = merkato.update() print("\n" * 2) if context["filled_orders"]: print("---- Filled: -----") pprint.pprint(context["filled_orders"]) print("lowest ask: ", context["orderbook"]["asks"][0]) print("current price: ", context["price"][1]) print("highest bid: ", context["orderbook"]["bids"][0]) if context["filled_orders"]: visualize_orderbook(context["orderbook"]) time.sleep(1)
def main(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() merkatos = get_all_merkatos() for merkato in merkatos: exchange_class = get_relevant_exchange(merkato['exchange']) config = load_config(merkato['exchange']) exchange = exchange_class(config, merkato['alt'], merkato['base']) orders = exchange.client.get_open_orders(symbol=exchange.ticker, recvWindow=10000000) orders.sort(key=sort_orders) find_problems(orders)
def main(): print("Merkato Alpha v0.1.1\n") if no_transactions_table_exists(): create_transactions_table() if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() option = get_start_option() process_result = process_start_option(option) if process_result == False: return elif process_result != None: start_merkatos(process_result) else: main()
def get_merkato_params_from_user(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() else: should_drop_merkatos = input('Do you want to drop merkatos? y/n: ') if should_drop_merkatos == 'y': drop_merkatos_table() create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() else: should_drop_exchanges = input('Do you want to drop exchanges? y/n: ') if should_drop_exchanges == 'y': drop_exchanges_table() create_exchanges_table() configuration = parse() if not configuration: configuration = get_config() if not configuration: raise Exception("Failed to get configuration.") base = input("Base: ") coin = input("Coin: ") spread = input("Spread: ") coin_reserve = input("Coin reserve: ") base_reserve = input("Base reserve: ") return { 'configuration': configuration, 'base': base, 'coin': coin, 'spread': float(spread), 'bid_reserved_balance': float(base_reserve), 'ask_reserved_balance': float(coin_reserve) }
def main(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() merkatos = get_all_merkatos() for merkato in merkatos: exchange = load_exchange_by_merkato(merkato) initial_base = float(merkato['init_base_balance']) initial_quote = float(merkato['init_quote_balance']) absolute_balances = exchange.get_balances() current_used_quote = float( exchange.get_balance(merkato['alt'])['locked']) current_used_base = float( exchange.get_balance(merkato['base'])['locked']) absolute_base = float(absolute_balances['base']['amount']['balance']) absolute_quote = float(absolute_balances['coin']['amount']['balance']) base_profit = float(merkato['base_profit']) quote_profit = float(merkato['quote_profit']) print('STATS FOR {}'.format(merkato['exchange_pair'])) print('Initial Base: {} Initial Quote: {} '.format( initial_base, initial_quote)) print( '(INCLUDES UNUSED FUNDS) Current Base Total: {} Current Quote Total: {}' .format(absolute_base, absolute_quote)) print( '(DOES NOT INCLUDE UNUSED FUNDS) Absolute Base Diff: {} Absolute Quote Diff: {}' .format(current_used_base - initial_base, current_used_quote - initial_quote)) print('MarketMaking Base Profit: {} Quote Profit: {}'.format( base_profit, quote_profit))
def main(): print("Merkato Alpha v0.1.1\n") if no_merkatos_table_exists(): create_merkatos_table() if no_exchanges_table_exists(): create_exchanges_table() merkatos = get_all_merkatos() for merkato in merkatos: exchange_name = merkato['exchange'] exchange_class = get_relevant_exchange(exchange_name) round_trip_fee = round_trip_exchange_fees[exchange_name] config = load_config(exchange_name) exchange = exchange_class(config, merkato['alt'], merkato['base']) spread = merkato['spread'] initial_base = float(merkato['bid_reserved_balance']) * 4 + float( merkato['base_profit']) initial_quote = float(merkato['ask_reserved_balance']) * 4 + float( merkato['quote_profit']) quote_volume = merkato['quote_volume'] base_volume = merkato['base_volume'] base_profit = (base_volume) * (spread - round_trip_fee) quote_profit = (quote_volume) * (spread - round_trip_fee) print('STATS FOR {}'.format(merkato['exchange_pair'])) print('Quote Volume: {} Base Volume: {}'.format( quote_volume, base_volume)) print('Quote Profit: {} Base Profit: {}'.format( quote_profit, base_profit)) relative_base_prof = str((base_profit / initial_base) * 100) + '%' relative_quote_prof = str((quote_profit / initial_quote) * 100) + '%' print('Relative Quote Profit: {} Relative Base Profit: {}'.format( relative_quote_prof, relative_base_prof))
def run_remove_tables_prompts(self): if no_merkatos_table_exists(): create_merkatos_table() self.run_remove_exchanges_prompts() else: self.run_remove_merkatos_prompt()
def start_merkatos(entered_password): if platform.system().lower() == "darwin": def mainloop(): while True: try: root.update_idletasks() root.update() time.sleep(1) except UnicodeDecodeError: print("Caught Scroll Error") else: def mainloop(): while True: try: root.update_idletasks() root.update() except UnicodeDecodeError: print("Caught Scroll Error") parser = argparse.ArgumentParser() parser.add_argument('-b', '--blockOnError', action='store_true', help="DEBUGGING ONLY: blocks all bots on error") parser.add_argument('-p', '--password', default="", help="password for decrypting db") parser.add_argument( '-d', '--delay', type=int, default=10000, help="delay in milliseconds between bot updates. Default 10000.") args = parser.parse_args() if not args.password: password = entered_password else: password = args.password root = tk.Tk() root.title("merkato (pre-release)") mystyle = ttk.Style() mystyle.theme_use('clam') # ('clam', 'alt', 'default', 'classic') mystyle.configure("app.TLabel", foreground="white", background="black", font=('Liberation Mono', '10', 'normal')) # "#4C4C4C") mystyle.configure("unlocked.TLabel", foreground="light green", background="black", font=('Liberation Mono', '12', 'normal')) # "#4C4C4C") mystyle.configure("smaller.TLabel", foreground="white", background="black", font=('Liberation Mono', '10', 'normal')) # "#4C4C4C") mystyle.configure("heading.TLabel", foreground="white", background="black", font=('Liberation Mono', '36', 'normal')) # "#4C4C4C") mystyle.configure("app.TFrame", foreground="gray55", background="black") # "#4C4C4C",) mystyle.configure("app.TButton", foreground="gray55", background="#D15101", activeforeground="#F2681C") # F2681C mystyle.configure("app.TCheckbutton", foreground="gray55", background="black") # "#4C4C4C") mystyle.configure("app.TCombobox", background="#F2681C", selectbackground="#D15101") # postoffset = (0,0,500,0)) mystyle.configure("app.TEntry", foreground="black", background="gray55") mystyle.configure("pass.TEntry", foreground="gray55", background="gray55", insertofftime=5000) root.option_add("*TCombobox*Listbox*selectBackground", "#D15101") # ------------------------------ if db.no_merkatos_table_exists(): db.create_merkatos_table() if db.no_exchanges_table_exists(): db.create_exchanges_table() test = konfig.encrypt_keys( dict(exchange="test", public_api_key='abc', private_api_key='123', limit_only=True), password) db.insert_exchange(**test) merkatos = db.get_all_merkatos() complete_merkato_configs = generate_complete_merkato_configs(merkatos) # ------------------------------ app = App(master=root, block_on_error=args.blockOnError, password=password, delay=args.delay, side=tk.RIGHT) for persisted in complete_merkato_configs: # pprint(persisted) konfig.decrypt_keys(config=persisted['configuration'], password=password) bot = Bot(root, app(), app, persist=persisted) app.add_screen(bot, "null", textvariable=bot.title_var, bg="gray75", fg="black", selectcolor="lightblue") for i in range(1): bot = Bot( root, app(), app, ) app.add_screen(bot, "null", textvariable=bot.title_var, bg="gray75", fg="black", selectcolor="lightblue") root.after(1000, lambda: app.update_frames(initialize=True)) root.after(100, app.finish_new_button()) mainloop()
activeforeground="#F2681C") # F2681C mystyle.configure("app.TCheckbutton", foreground="gray55", background="black") # "#4C4C4C") mystyle.configure("app.TCombobox", background="#F2681C", selectbackground="#D15101") # postoffset = (0,0,500,0)) mystyle.configure("app.TEntry", foreground="black", background="gray55") mystyle.configure("pass.TEntry", foreground="gray55", background="gray55", insertofftime=5000) root.option_add("*TCombobox*Listbox*selectBackground", "#D15101") # ------------------------------ if db.no_merkatos_table_exists(): db.create_merkatos_table() if db.no_exchanges_table_exists(): db.create_exchanges_table() test = konfig.encrypt_keys( dict(exchange="test", public_api_key='abc', private_api_key='123', limit_only=True), password) db.insert_exchange(**test) merkatos = db.get_all_merkatos() complete_merkato_configs = generate_complete_merkato_configs(merkatos) # ------------------------------