def setUp(self): configuration = { "exchange": "tux", "privatekey": "abc123", "publickey": "def456" } self.merkato = Merkato(configuration, ticker='XMR', spread='15')
def handle_add_asset(): merkatos = get_all_merkatos() complete_merkato_configs = generate_complete_merkato_configs(merkatos) print('Select Merkato from available IDs') for counter, complete_config in enumerate(complete_merkato_configs): exchange_name = complete_config['configuration'][ 'exchange'] + '_' + complete_config[ 'base'] + '_' + complete_config['coin'] print('{} -> {}'.format(counter + 1, exchange_name)) selection = input('Selection: ') num_selection = int(selection) - 1 selection_exists = len(complete_merkato_configs) > num_selection + 1 if selection_exists: complete_config = complete_merkato_configs[num_selection] asset_to_add = input('Do you want to add to {} or {}: '.format( complete_config['coin'], complete_config['base'])) while asset_to_add != complete_config[ 'coin'] and asset_to_add != complete_config['base']: print('Wrong Asset, try again') asset_to_add = input('Do you want to add to {} or {}: '.format( complete_config['coin'], complete_config['base'])) amount_to_add = input( 'How much {} do you want to add: '.format(asset_to_add)) password = getpass.getpass('Enter password for merkato: ') decrypt_keys(config=complete_config['configuration'], password=password) merkato = Merkato(**complete_config) merkato.update_orders(asset_to_add, amount_to_add) else: handle_add_asset()
def main(): print("Merkato Alpha v0.1.1\n") configuration = config.get_config() if not configuration: raise Exception("Failed to get configuration.") print(configuration) merkato = Merkato(configuration) merkato.exchange.get_all_orders()
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 setUp(self, *_): config = { "exchange": "tux", "private_api_key": "abc123", "public_api_key": "def456", "limit_only": False } self.merkato = Merkato(config, coin='XMR', base='BTC', spread='.1', bid_reserved_balance='1', ask_reserved_balance='1')
async def on_connected(self, ws, path): log.info("Connected.") while True: msg = await ws.recv() msg = json.loads(msg) if 'merkato_params' in msg: merkato_params = msg['merkato_params'] log.info("Received Merkato params: {}".format(merkato_params)) self.merkato = Merkato(**merkato_params) self.initialized = True log.info("===> Initialized Merkato") break await asyncio.sleep(0.1)
def start_tuner(step, spread, start_base, start_quote, distribution_strategy, start=0): config = generate_tuner_config(step, spread, start_base, start_quote, distribution_strategy, start) tuner = Merkato(**config) done = False while done == False: stuff = tuner.update() if stuff == "stuffs": # Get bprofit and qprofit and ending balances balances = tuner.exchange.get_balances() abs_b_profit = balances['base']['amount']['balance'] - start_base abs_q_profit = balances['coin']['amount']['balance'] - start_quote print("------------ qprofit: {} bprofit: {}".format(abs_q_profit, abs_b_profit)) done = True return abs_q_profit, abs_b_profit
def start(self): for widget in [ self.exchange_name, self.coin, self.base, self.ask_budget, self.bid_budget ]: print("{}:\t\t{}".format(widget.handle, widget.get()[0])) self.merk_args = {} self.merk_args["configuration"] = konfig.decrypt_keys( self.exchange_index[self.exchange_name.get()[0]], self.owner.password) self.merk_args["coin"] = self.coin.get()[0] self.merk_args["base"] = self.base.get()[0] self.merk_args["ask_reserved_balance"] = float( self.ask_budget.get()[0]) self.merk_args["bid_reserved_balance"] = float( self.bid_budget.get()[0]) self.merk_args["spread"] = float(self.spread.get()[0]) / 100.0 self.merk_args["profit_margin"] = float(self.margin.get()[0]) / 100.0 self.merk_args["user_interface"] = self self.coin_title = self.merk_args["coin"] self.base_title = self.merk_args["base"] self.graph.profit_base.config(text="%s \u0394bal:" % self.base_title[:4]) self.graph.profit_alt.config(text="%s \u0394bal:" % self.coin_title[:4]) self.exchange_title = self.merk_args["configuration"]["exchange"] self.name = str(self.merk_args["coin"]) + "/" + str( self.merk_args["base"]) + " " + self.exchange_title self.title_var.set(str(self.name)) if not self.stub: try: self.bot = Merkato(**self.merk_args) self.update(initial_update=True) except Exception as e: raise Exception('bot failed to start', e) e2 = traceback.format_exc() safe_show = self.merk_args.copy() safe_show["configuration"] = "obfuscated: " + str( safe_show["configuration"]["exchange"]) MessageBox.showerror("Bot Start Fail", str(e2) + "\n" + repr(self.merk_args)) else: self.exchange_frame.destroy()
def create_new_merkato(): password = getpass.getpass() exchange_name = get_exchange() exchange = get_exchange_from_db(exchange_name) merkato_args = {} merkato_args['configuration'] = decrypt_keys(exchange, password) merkato_args['coin'] = get_asset('quote') merkato_args['base'] = get_asset('base') merkato_args['ask_reserved_balance'] = get_reserve_balance('quote') merkato_args['bid_reserved_balance'] = get_reserve_balance('base') merkato_args['spread'] = get_merkato_variable('spread') merkato_args['profit_margin'] = get_merkato_variable('profit margin') merkato_args['step'] = get_merkato_variable('step') Merkato(**merkato_args) return password
def start_tuner(step, spread, start_base, start_quote): config = generate_tuner_config(step, spread, start_base, start_quote) tuner = Merkato(**config) done = False while done == False: stuff = tuner.update() if stuff == "stuffs": # Get bprofit and qprofit and ending balances quote_volume = float(tuner.quote_volume) base_volume = float(tuner.base_volume) spread = tuner.spread q_profit = quote_volume * (float(spread) - .002) b_profit = base_volume * (float(spread) - .002) print("------------ qprofit: {} bprofit: {}".format( q_profit, b_profit)) done = True
def start_merkatos(password=None): if password == None: password = getpass.getpass() merkatos = get_all_merkatos() complete_merkato_configs = generate_complete_merkato_configs(merkatos) initialized_merkatos = [] for complete_config in complete_merkato_configs: decrypt_keys(config=complete_config['configuration'], password=password) merkato = Merkato(**complete_config) initialized_merkatos.append(merkato) while True: for merkato in initialized_merkatos: merkato.update() time.sleep(6)
def create_new_merkato(): password = getpass.getpass() exchange_name = get_exchange() exchange = get_exchange_from_db(exchange_name) merkato_args = {} merkato_args['configuration'] = decrypt_keys(exchange, password) merkato_args['coin'] = get_asset('quote') merkato_args['base'] = get_asset('base') merkato_args['ask_reserved_balance'] = get_reserve_balance('quote') merkato_args['bid_reserved_balance'] = get_reserve_balance('base') merkato_args['spread'] = get_merkato_variable('spread', 'for 5% spread use .05') merkato_args['profit_margin'] = get_merkato_variable('profit margin') merkato_args['step'] = get_merkato_variable('step', 'for 5% step use "1.05"') merkato_args['distribution_strategy'] = get_merkato_variable( 'distribution strategy', 'Input "1 for aggressive, "2" for neutral, "3" for hyper aggro:') merkato_args['increased_orders'] = get_merkato_variable( 'Increased Orders', 'SUGGESTED IS 0, 1, or 2') Merkato(**merkato_args) return password
def setUp(self): config = {"exchange": "tux", "privatekey": "abc123", "publickey": "def456", "limit_only": False} self.merkato = Merkato(config, ticker='XMR', spread='15', ask_budget=10, bid_budget=10)
def __init__(self, app, parent, owner, persist=None, stub=False, auto_start=False, starting_stats=None, *args, **kwargs): ttk.Frame.__init__(self, parent, style="app.TFrame", *args, **kwargs) self.app = app # root self.parent = parent # containing frame self.owner = owner self.stub = stub self.is_active = False self.title_var = tk.StringVar() self.coin_title = "coin" self.base_title = "base" self.exchange_title = "<exchange>" if self.stub: self.name = "XMR/BTC Stub" else: self.name = "New Merkato" self.title_var.set(str(self.name)) # merkato args #self.auth_frame = ttk.Frame(self, style="app.TFrame") self.bot = None if persist: self.name = persist["coin"] + "/" + persist[ "base"] + " " + persist["configuration"]["exchange"] self.title_var.set(str(self.name)) self.bot = Merkato(**persist) #presumably from db # -------------------- self.exchange_frame = ttk.Frame(self, style="app.TFrame") self.exchange_menu, self.exchange_index = database_utils.get_all_exchanges( ) self.exchange_name = MyWidget(self.app, self.exchange_frame, handle="exchange", startVal="test", choices=self.exchange_menu) self.coin = MyWidget(self.app, self.exchange_frame, handle="coin", startVal="XMR", choices=["XMR", "LTC", "ETH", "DOGE", "PEPECASH"]) self.base = MyWidget(self.app, self.exchange_frame, handle="base", startVal="BTC", choices=["BTC", "USDT"]) #self.public_key = MyWidget(self.app, self.exchange_frame, handle="pub. key", choices="entry") #self.private_key = MyWidget(self.app, self.exchange_frame, handle="priv. key", is_password=True, choices="entry") self.ask_budget = MyWidget(self.app, self.exchange_frame, handle="coin reserve", startVal=636, choices="entry") self.bid_budget = MyWidget(self.app, self.exchange_frame, handle="base reserve", startVal=10, choices="entry") self.spread = MyWidget(self.app, self.exchange_frame, handle="spread [%]", startVal=5.0, choices="entry") self.margin = MyWidget(self.app, self.exchange_frame, handle="profit margin [%]", startVal="0", choices=[str(i) for i in range(101)]) self.execute = ttk.Button(self.exchange_frame, text="Launch", cursor="shuttle", command=self.start) self.exchange_name.grid(row=0, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.coin.grid(row=1, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.base.grid(row=2, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.public_key.grid(row=3, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.private_key.grid(row=4, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.ask_budget.grid(row=5, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.bid_budget.grid(row=6, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.spread.grid(row=7, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.margin.grid(row=8, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.execute.grid(row=9, column=0, sticky=tk.NE, padx=(10, 5), pady=(15, 5)) # -------------------- self.util_frame = ttk.Frame(self, style="app.TFrame") self.kill_button = ttk.Button(self.util_frame, text="Kill", cursor="shuttle", command=self.kill) self.kill_button.grid(row=0, column=0, sticky=tk.SE, padx=(10, 5), pady=(15, 5)) self.add_assets_type = MyWidget( self.app, self.util_frame, handle="Add Asset", startVal="XMR", choices=["XMR", "BTC", "ETH", "DOGE", "PEPECASH"]) self.add_assets_type.grid(row=1, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_amount = MyWidget(self.app, self.util_frame, handle="amount to add", startVal=1.0, choices="entry") self.add_assets_amount.grid(row=2, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_button = ttk.Button(self.util_frame, text="Add Assets", cursor="shuttle", command=self.add_assets) self.add_assets_button.grid(row=3, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) # -------------------- if not starting_stats: starting_stats = {"price_x": []} self.graph = Graph(self.app, self, stub=self.stub, **starting_stats) self.graph.grid(row=0, column=0, rowspan=3, padx=(5, 10)) #self.auth_frame.grid(row = 0, column=1, sticky=tk.NE, padx=(10,10), pady=(20,5)) if not self.bot: self.exchange_frame.grid(row=0, column=1, sticky=tk.NE, padx=(10, 10), pady=(20, 5)) self.util_frame.grid(row=1, column=1, sticky=tk.SE, padx=(10, 10), pady=(10, 5))