Пример #1
0
 def add_statistiko(self):
     exchange_name = self.get_exchange_name()
     quote_asset = self.get_quote_asset()
     base_asset = self.get_base_asset()
     exchange_pair = exchange_name + "coin={}_base={}".format(
         quote_asset, base_asset)
     insert_merkato(exchange=exchange_name,
                    alt=quote_asset,
                    base=base_asset,
                    exchange_pair=exchange_pair)
     self.create_widgets()
Пример #2
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
Пример #3
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
Пример #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,
                 quote_volume=0,
                 base_volume=0,
                 step=1.0033):

        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 = step
        # 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)

        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)

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