Exemplo n.º 1
0
    def resp(self, req):
        response = super(BitfinexBTCUSDExchange, self).resp(req)
        if 'message' in response:
            errors_string = str(response['message'])
            if 'not enough balance' in errors_string:
                raise exceptions.InsufficientFundsError()
            elif 'Order could not be cancelled' in errors_string:
                raise exceptions.CancelOrderNotFoundError()
            elif 'Nonce is too small' in errors_string:
                raise exceptions.NonceError()
            else:
                raise exceptions.ExchangeAPIErrorException(self, errors_string)

        return response
Exemplo n.º 2
0
    def resp(self, req):
        response = super(GeminiBTCUSDExchange, self).resp(req)

        if 'message' in response:
            errors_string = str(response['message'])

            if 'InsufficientFunds' or 'insufficient funds' in errors_string:
                raise exceptions.InsufficientFundsError()
            elif 'Order' in errors_string and 'not found' in errors_string:
                raise exceptions.CancelOrderNotFoundError()
            elif 'InvalidNonce' in errors_string:
                raise exceptions.NonceError()
            else:
                raise exceptions.ExchangeAPIErrorException(self, errors_string)

        return response
Exemplo n.º 3
0
    def resp(self, req):
        response = super(OKCoinBTCUSDExchange, self).resp(req)

        error_code = response.get('error_code', None)

        if error_code:
            if error_code == 10009:
                raise exceptions.CancelOrderNotFoundError()
            elif error_code in [10016, 10010]:
                raise exceptions.InsufficientFundsError()
            else:
                raise exceptions.ExchangeAPIErrorException(
                    self,
                    self.errors[error_code],
                )

        return response
Exemplo n.º 4
0
    def resp(self, req):
        response = super(KrakenBTCEURExchange, self).resp(req)

        if response.get('error'):
            errors_string = str(response['error'])

            if 'Insufficient funds' in errors_string:
                raise exceptions.InsufficientFundsError()
            elif 'Unknown order' in errors_string:
                raise exceptions.CancelOrderNotFoundError()
            elif 'Invalid nonce' in errors_string:
                raise exceptions.NonceError()
            else:
                raise exceptions.ExchangeAPIErrorException(self, errors_string)

        try:
            return response['result']
        except KeyError:
            raise exceptions.ExchangeAPIFailureException(self, response)
Exemplo n.º 5
0
    def resp(self, req):
        response = super(QuadrigaBTCCADExchange, self).resp(req)

        try:
            if 'error' in response:
                errors_string = response['error']['message']

                if 'exceeds available' in errors_string:
                    raise exceptions.InsufficientFundsError()
                elif 'Cannot perform request - not found' in errors_string:
                    raise exceptions.CancelOrderNotFoundError()
                elif 'Nonce' in errors_string:
                    raise exceptions.NonceError()
                else:
                    logger.info(response['error'])
                    raise exceptions.ExchangeAPIErrorException(
                        self, errors_string)

            return response
        except KeyError:
            raise exceptions.ExchangeAPIFailureException(self, response)
Exemplo n.º 6
0
    def resp(self, req):
        response = super(BitstampBTCUSDExchange, self).resp(req)

        try:
            errors = response.get('error', None)
        except AttributeError:  # Some endpoints return a list.
            errors = None

        if errors:
            errors_string = str(errors)

            if 'You have only' in errors_string:
                raise exceptions.InsufficientFundsError()
            elif 'Order not found' in errors_string:
                raise exceptions.CancelOrderNotFoundError()
            elif 'Minimum order size' in errors_string:
                raise exceptions.MinimumOrderSizeError()
            elif 'Invalid nonce' in errors_string:
                raise exceptions.NonceError()
            else:
                raise exceptions.ExchangeAPIErrorException(self, errors_string)

        return response
Exemplo n.º 7
0
    def resp(self, req):
        response = req.result()

        try:
            data = response.json(parse_float=Decimal)
        except ValueError:
            raise exceptions.ExchangeAPIFailureException(self, response)

        headers = response.headers

        if response.status_code < 200 or response.status_code >= 300:
            try:
                error_string = data['message']
            except KeyError:
                error_string = str(data)

            error_string = error_string.lower()

            if 'notfound' in error_string:
                raise exceptions.NoEffectOrderCancelledError()
            elif ('order already done' in error_string
                  or 'order not found' in error_string):
                raise exceptions.CancelOrderNotFoundError()
            elif 'order size is too small' in error_string:
                raise exceptions.MinimumOrderSizeError()
            elif 'insufficient funds' in error_string:
                raise exceptions.InsufficientFundsError()
            # These errors occur randomly (usually when Coinbase under heavy load).
            # We want to return an ExchangeAPIFailureException so that requests get
            # retried.
            elif ('request timestamp expired' in error_string
                  or 'internal server error' in error_string):
                raise exceptions.ExchangeAPIFailureException(self, response)
            else:
                raise exceptions.ExchangeAPIErrorException(self, error_string)
        else:
            return data, headers
Exemplo n.º 8
0
    def resp(self, req):
        response = super(ItbitBTCUSDExchange, self).resp(req)

        if 'error' in response and response['error']:
            raise exceptions.ExchangeAPIErrorException(self, response['error'])

        if 'code' in response:
            errors_string = str(response['description'])
            error_code = int(response['code'])

            if error_code == 81001:
                raise exceptions.InsufficientFundsError()
            elif error_code == 10002:
                raise exceptions.NonceError()
            elif error_code == 81002:
                raise exceptions.CancelOrderNotFoundError()
            else:
                raise exceptions.ExchangeAPIErrorException(
                    self, 'Code %s: %s' % (
                        error_code,
                        errors_string,
                    ))

        return response