Example #1
0
 def start_statistikos(self):
     merkatos = get_all_merkatos()
     instances = []
     for merkato in merkatos:
         print(merkato['exchange'])
         if merkato['exchange'] == 'test':
             continue
         exchange = get_exchange(merkato['exchange'])
         exchange["public_api_key"] = ''
         exchange["private_api_key"] = ''
         exchange_class = get_relevant_exchange(merkato['exchange'])
         exchange_instance = exchange_class(exchange,
                                            coin=merkato['alt'],
                                            base=merkato['base'])
         instances.append(exchange_instance)
     while True:
         for instance in instances:
             now = round(datetime.datetime.now().timestamp())
             last_trade_price = instance.get_last_trade_price()
             if last_trade_price == 'Error':
                 print('error on ' + instance.name)
                 continue
             insert_price_data(instance.name, last_trade_price,
                               instance.ticker, now)
             # print('Price Data for {}_{}_{}'.format(instance.name, instance.coin, instance.base), context)
         time.sleep(60)
Example #2
0
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))
Example #3
0
 def start_statistiko(self, password, base, quote, exchange):
     root.destroy()
     exchange_config = get_exchange(exchange)
     decrypt_keys(exchange_config, password)
     exchange_class = get_relevant_exchange(exchange)
     self.exchange = exchange_class(exchange_config, coin=quote, base=base)
     while True:
         now = str(datetime.datetime.now().isoformat()[:-7].replace(
             "T", " "))
         last_trade_price = self.exchange.get_last_trade_price()
         context = {"price": (now, last_trade_price)}
         print('context', context)
         f = open("price_data.txt", "a")
         f.write(json.dumps(context))
         time.sleep(60)
Example #4
0
    def __init__(self,
                 configuration,
                 coin,
                 base,
                 spread,
                 bid_reserved_balance,
                 ask_reserved_balance,
                 user_interface=None,
                 profit_margin=0,
                 first_order='',
                 starting_price=.018,
                 increased_orders=0,
                 step=1.0033,
                 distribution_strategy=1,
                 init_base_balance=0,
                 init_quote_balance=0,
                 base_profit=0,
                 quote_profit=0,
                 buy_volume=0,
                 sell_volume=0):

        UUID = configuration[EXCHANGE] + "coin={}_base={}".format(coin, base)
        self.mutex_UUID = UUID
        self.spread = Decimal(spread)
        self.profit_margin = Decimal(profit_margin)
        self.starting_price = starting_price
        self.step = step
        self.increased_orders = increased_orders
        self.quote_profit = Decimal(quote_profit)
        self.base_profit = Decimal(base_profit)
        self.bid_reserved_balance = Decimal(float(bid_reserved_balance))
        self.ask_reserved_balance = Decimal(float(ask_reserved_balance))
        self.init_base_balance = init_base_balance
        self.init_quote_balance = init_quote_balance
        # The current sum of all partially filled orders
        self.base_partials_balance = 0
        self.quote_partials_balance = 0
        self.buy_volume = buy_volume
        self.sell_volume = sell_volume
        self.last_placed_UUID = ''  #this assures that no faulty doubled up orders will be placed sequentially

        self.user_interface = user_interface

        exchange_class = get_relevant_exchange(configuration[EXCHANGE])
        self.exchange = exchange_class(configuration, coin=coin, base=base)
Example #5
0
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)
Example #6
0
    def __init__(self, configuration, coin, base, spread,
                 bid_reserved_balance, ask_reserved_balance,
                 user_interface=None, profit_margin=0, first_order=''):

        validate_merkato_initialization(configuration, coin, base, spread)
        self.initialized = False
        UUID = configuration[EXCHANGE] + "coin={}_base={}".format(coin,base)
        self.mutex_UUID = UUID
        self.distribution_strategy = 1
        self.spread = float(spread)
        self.profit_margin = profit_margin
        # Create ladders from the bid and ask bidget here
        self.bid_reserved_balance = bid_reserved_balance
        self.ask_reserved_balance = ask_reserved_balance
        self.user_interface = user_interface
        exchange_class = get_relevant_exchange(configuration[EXCHANGE])
        self.exchange = exchange_class(configuration, coin=coin, base=base)
        merkato_does_exist = merkato_exists(UUID)

        if not merkato_does_exist:
            log.info("Creating New Merkato")
            self.cancelrange(ONE_SATOSHI, ONE_BITCOIN)
            total_pair_balances = self.exchange.get_balances()
            log.info("total pair balances", total_pair_balances)
            allocated_pair_balances = get_allocated_pair_balances(configuration['exchange'], base, coin)
            check_reserve_balances(total_pair_balances, allocated_pair_balances, coin_reserve=ask_reserved_balance, base_reserve=bid_reserved_balance)
            insert_merkato(configuration[EXCHANGE], UUID, base, coin, spread, bid_reserved_balance, ask_reserved_balance, first_order)
            history = self.exchange.get_my_trade_history()
            print('initial history', history)
            if len(history) > 0:
                print('updating history', history[0]['orderId'])
                new_last_order = history[0]['orderId']
                update_merkato(self.mutex_UUID, LAST_ORDER, new_last_order)
            self.distribute_initial_orders(total_base=bid_reserved_balance, total_alt=ask_reserved_balance)

        else:
            #self.history = get_old_history(self.exchange.get_my_trade_history(), self.mutex_UUID)
            first_order = get_first_order(self.mutex_UUID)
            current_history = self.exchange.get_my_trade_history(first_order)
            last_order = get_last_order(self.mutex_UUID)
            new_history = get_new_history(current_history, last_order)
            self.rebalance_orders(new_history)
        self.initialized = True  # to avoid being updated before orders placed
Example #7
0
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))
Example #8
0
    def __init__(self,
                 configuration,
                 coin,
                 base,
                 spread,
                 bid_reserved_balance,
                 ask_reserved_balance,
                 user_interface=None,
                 profit_margin=0,
                 first_order='',
                 starting_price=.018,
                 quote_volume=0,
                 base_volume=0,
                 step=1.0033,
                 distribution_strategy=1,
                 start=0):

        # validate_merkato_initialization(configuration, coin, base, spread)
        self.initialized = False
        UUID = configuration[EXCHANGE] + "coin={}_base={}".format(coin, base)
        self.mutex_UUID = UUID
        self.distribution_strategy = distribution_strategy
        self.spread = Decimal(spread)
        self.profit_margin = Decimal(profit_margin)
        self.starting_price = starting_price
        self.quote_volume = Decimal(quote_volume)
        self.base_volume = Decimal(base_volume)
        self.step = step
        self.first_order = ''
        self.last_order = ''
        # Exchanges have a maximum number of orders every user can place. Due
        # to this, every Merkato has a reserve of coins that are not currently
        # allocated. As the price approaches unallocated regions, the reserves
        # are deployed.
        self.bid_reserved_balance = Decimal(float(bid_reserved_balance))
        self.ask_reserved_balance = Decimal(float(ask_reserved_balance))

        # The current sum of all partially filled orders
        self.base_partials_balance = 0
        self.quote_partials_balance = 0

        self.user_interface = user_interface

        exchange_class = get_relevant_exchange(configuration[EXCHANGE])
        self.exchange = exchange_class(configuration, coin=coin, base=base)

        log.info("Creating New Merkato")

        total_pair_balances = self.exchange.get_balances()

        log.info("total pair balances: {}".format(total_pair_balances))

        history = self.exchange.get_my_trade_history()

        if len(history) > 0:
            log.debug('updating history first ID: {}'.format(history[0][ID]))
            new_last_order = history[0][ID]
            self.last_order = new_last_order
        self.distribute_initial_orders(total_base=bid_reserved_balance,
                                       total_alt=ask_reserved_balance)

        self.initialized = True  # to avoid being updated before orders placed
Example #9
0
    def __init__(self,
                 configuration,
                 coin,
                 base,
                 spread,
                 bid_reserved_balance,
                 ask_reserved_balance,
                 user_interface=None,
                 profit_margin=0,
                 first_order='',
                 starting_price=.018,
                 increased_orders=0,
                 step=1.0033,
                 distribution_strategy=1,
                 init_base_balance=0,
                 init_quote_balance=0,
                 base_profit=0,
                 quote_profit=0,
                 buy_volume=0,
                 sell_volume=0):

        validate_merkato_initialization(configuration, coin, base, spread)
        self.initialized = False
        UUID = configuration[EXCHANGE] + "coin={}_base={}".format(coin, base)
        self.mutex_UUID = UUID
        self.distribution_strategy = distribution_strategy
        self.spread = Decimal(spread)
        self.profit_margin = Decimal(profit_margin)
        self.starting_price = starting_price
        self.step = step
        self.increased_orders = increased_orders
        self.quote_profit = Decimal(quote_profit)
        self.base_profit = Decimal(base_profit)
        self.bid_reserved_balance = Decimal(float(bid_reserved_balance))
        self.ask_reserved_balance = Decimal(float(ask_reserved_balance))
        self.init_base_balance = init_base_balance
        self.init_quote_balance = init_quote_balance
        # The current sum of all partially filled orders
        self.base_partials_balance = 0
        self.quote_partials_balance = 0
        self.buy_volume = buy_volume
        self.sell_volume = sell_volume
        self.last_placed_UUID = ''  #this assures that no faulty doubled up orders will be placed sequentially

        self.user_interface = user_interface

        exchange_class = get_relevant_exchange(configuration[EXCHANGE])
        self.exchange = exchange_class(configuration, coin=coin, base=base)

        merkato_does_exist = merkato_exists(self.mutex_UUID)

        if not merkato_does_exist:
            log.info("Creating New Merkato")

            self.cancelrange(ONE_SATOSHI, ONE_BITCOIN)

            total_pair_balances = self.exchange.get_balances()

            log.info("total pair balances: {}".format(total_pair_balances))

            allocated_pair_balances = get_allocated_pair_balances(
                configuration['exchange'], base, coin)
            check_reserve_balances(total_pair_balances,
                                   allocated_pair_balances,
                                   coin_reserve=ask_reserved_balance,
                                   base_reserve=bid_reserved_balance)

            insert_merkato(configuration[EXCHANGE],
                           self.mutex_UUID,
                           base,
                           coin,
                           spread,
                           bid_reserved_balance,
                           ask_reserved_balance,
                           first_order,
                           starting_price,
                           init_base_balance=bid_reserved_balance,
                           init_quote_balance=ask_reserved_balance,
                           step=step)
            history = self.exchange.get_my_trade_history()

            log.debug('initial history: {}'.format(history))

            if len(history) > 0:
                log.debug('updating history first ID: {}'.format(
                    history[0][ID]))
                new_last_order = history[0][ID]
                update_merkato(self.mutex_UUID, LAST_ORDER, new_last_order)
            self.distribute_initial_orders(total_base=bid_reserved_balance,
                                           total_alt=ask_reserved_balance)

        else:
            first_order = get_first_order(self.mutex_UUID)
            current_history = self.exchange.get_my_trade_history()
            last_order = get_last_order(self.mutex_UUID)
            new_history = get_new_history(current_history, last_order)
            self.rebalance_orders(new_history)

        self.initialized = True  # to avoid being updated before orders placed
Example #10
0
    def __init__(self,
                 configuration,
                 coin,
                 base,
                 spread,
                 bid_reserved_balance,
                 ask_reserved_balance,
                 user_interface=None,
                 profit_margin=0,
                 first_order='',
                 starting_price=.018,
                 quote_volume=0,
                 base_volume=0):

        validate_merkato_initialization(configuration, coin, base, spread)
        self.initialized = False
        UUID = configuration[EXCHANGE] + "coin={}_base={}".format(coin, base)
        self.mutex_UUID = UUID
        self.distribution_strategy = 1
        self.spread = Decimal(spread)
        self.profit_margin = Decimal(profit_margin)
        self.starting_price = starting_price
        self.quote_volume = Decimal(quote_volume)
        self.base_volume = Decimal(base_volume)
        self.step = 1.0033
        # Exchanges have a maximum number of orders every user can place. Due
        # to this, every Merkato has a reserve of coins that are not currently
        # allocated. As the price approaches unallocated regions, the reserves
        # are deployed.
        self.bid_reserved_balance = Decimal(float(bid_reserved_balance))
        self.ask_reserved_balance = Decimal(float(ask_reserved_balance))

        # The current sum of all partially filled orders
        self.base_partials_balance = 0
        self.quote_partials_balance = 0

        self.user_interface = user_interface

        exchange_class = get_relevant_exchange(configuration[EXCHANGE])
        self.exchange = exchange_class(configuration, coin=coin, base=base)

        merkato_does_exist = merkato_exists(self.mutex_UUID)

        if not merkato_does_exist:
            log.info("Creating New Merkato")

            self.cancelrange(ONE_SATOSHI, ONE_BITCOIN)

            total_pair_balances = self.exchange.get_balances()

            log.info("total pair balances: {}".format(total_pair_balances))

            allocated_pair_balances = get_allocated_pair_balances(
                configuration['exchange'], base, coin)
            check_reserve_balances(total_pair_balances,
                                   allocated_pair_balances,
                                   coin_reserve=ask_reserved_balance,
                                   base_reserve=bid_reserved_balance)

            insert_merkato(configuration[EXCHANGE], self.mutex_UUID, base,
                           coin, spread, bid_reserved_balance,
                           ask_reserved_balance, first_order, starting_price)
            history = self.exchange.get_my_trade_history()

            log.debug('initial history: {}'.format(history))

            if len(history) > 0:
                log.debug('updating history first ID: {}'.format(
                    history[0][ID]))
                new_last_order = history[0][ID]
                update_merkato(self.mutex_UUID, LAST_ORDER, new_last_order)
            self.distribute_initial_orders(total_base=bid_reserved_balance,
                                           total_alt=ask_reserved_balance)

        else:
            first_order = get_first_order(self.mutex_UUID)
            current_history = self.exchange.get_my_trade_history(first_order)
            last_order = get_last_order(self.mutex_UUID)
            new_history = get_new_history(current_history, last_order)
            self.rebalance_orders(new_history)

        self.initialized = True  # to avoid being updated before orders placed