コード例 #1
0
        def fetch_capital_base(attempt_index=0):
            """
            Fetch the base currency amount required to bootstrap
            the algorithm against the exchange.

            The algorithm cannot continue without this value.

            :param attempt_index:
            :return capital_base: the amount of base currency available for
            trading
            """
            try:
                log.debug('retrieving capital base in {} to bootstrap '
                          'exchange {}'.format(base_currency, exchange_name))
                balances = exchange.get_balances()
            except ExchangeRequestError as e:
                if attempt_index < 20:
                    sleep(5)
                    return fetch_capital_base(attempt_index + 1)
                else:
                    raise ExchangeRequestErrorTooManyAttempts(
                        attempts=attempt_index, error=e)

            if base_currency in balances:
                return balances[base_currency]
            else:
                raise BaseCurrencyNotFoundError(base_currency=base_currency,
                                                exchange=exchange_name)
コード例 #2
0
        def fetch_capital_base(exchange, attempt_index=0):
            """
            Fetch the base currency amount required to bootstrap
            the algorithm against the exchange.

            The algorithm cannot continue without this value.

            :param exchange: the targeted exchange
            :param attempt_index:
            :return capital_base: the amount of base currency available for
            trading
            """
            try:
                log.debug('retrieving capital base in {} to bootstrap '
                          'exchange {}'.format(base_currency, exchange_name))
                balances = exchange.get_balances()
            except ExchangeRequestError as e:
                if attempt_index < 20:
                    log.warn(
                        'could not retrieve balances on {}: {}'.format(
                            exchange.name, e
                        )
                    )
                    sleep(5)
                    return fetch_capital_base(exchange, attempt_index + 1)

                else:
                    raise ExchangeRequestErrorTooManyAttempts(
                        attempts=attempt_index,
                        error=e
                    )

            if base_currency in balances:
                base_currency_available = balances[base_currency]
                log.info(
                    'base currency available in the account: {} {}'.format(
                        base_currency_available, base_currency
                    )
                )

                if capital_base is not None \
                        and capital_base < base_currency_available:
                    log.info(
                        'using capital base limit: {} {}'.format(
                            capital_base, base_currency
                        )
                    )
                    amount = capital_base
                else:
                    amount = base_currency_available

                return amount
            else:
                raise BaseCurrencyNotFoundError(
                    base_currency=base_currency,
                    exchange=exchange_name
                )