def handle_errors(self, code, reason, url, method, headers, body): response = None try: response = json.loads(body) except Exception as e: # syntax error, resort to default error handler return if 'error' in response: error = response['error'] feedback = self.id + ' ' + self.json(response) if error == 'Invalid order number, or you are not the person who placed the order.': raise OrderNotFound(feedback) elif error == 'Internal error. Please try again.': raise ExchangeNotAvailable(feedback) elif error == 'Order not found, or you are not the person who placed it.': raise OrderNotFound(feedback) elif error == 'Invalid API key/secret pair.': raise AuthenticationError(feedback) elif error == 'Please do not make more than 8 API calls per second.': raise DDoSProtection(feedback) elif error.find('Total must be at least') >= 0: raise InvalidOrder(feedback) elif error.find('Not enough') >= 0: raise InsufficientFunds(feedback) elif error.find('Nonce must be greater') >= 0: raise InvalidNonce(feedback) elif error.find( 'You have already called cancelOrder or moveOrder on self order.' ) >= 0: raise CancelPending(feedback) else: raise ExchangeError(self.id + ': unknown error: ' + self.json(response))
async def withdraw(self, currency, amount, address, tag=None, params={}): # Sometimes the response with be {key: null} for all keys. # An example is if you attempt to withdraw more than is allowed when withdrawal fees are considered. await self.load_markets() self.check_address(address) wallet = address if tag is not None: wallet += '::' + tag withdrawal = { 'amount': self.truncate( amount, self.currencies[currency] ['precision']), # throws an error when amount is too precise 'currency': self.common_currency_code(currency), 'wallet': wallet, } response = await self.privatePostPaymentOutCoin( self.extend(withdrawal, params)) id = self.safe_integer(response, 'id') if id is None: raise InsufficientFunds( self.id + ' insufficient funds to cover requested withdrawal amount post fees ' + self.json(response)) return { 'info': response, 'id': id, }
def handle_errors(self, code, reason, url, method, headers, body): if body.find('Invalid order') >= 0: raise InvalidOrder(self.id + ' ' + body) if body.find('Invalid nonce') >= 0: raise InvalidNonce(self.id + ' ' + body) if body.find('Insufficient funds') >= 0: raise InsufficientFunds(self.id + ' ' + body) if body.find('Cancel pending') >= 0: raise CancelPending(self.id + ' ' + body) if body.find('Invalid arguments:volume') >= 0: raise InvalidOrder(self.id + ' ' + body)
def handle_errors(self, code, reason, url, method, headers, body): if code == 400: if body[0] == '{': response = json.loads(body) if 'error' in response: if 'message' in response['error']: message = response['error']['message'] if message == 'Order not found': raise OrderNotFound(self.id + ' order not found in active orders') elif message == 'Quantity not a valid number': raise InvalidOrder(self.id + ' ' + body) elif message == 'Insufficient funds': raise InsufficientFunds(self.id + ' ' + body) elif message == 'Duplicate clientOrderId': raise InvalidOrder(self.id + ' ' + body) raise ExchangeError(self.id + ' ' + body)
async def request(self, path, api='public', method='GET', params={}, headers=None, body=None): response = await self.fetch2(path, api, method, params, headers, body) if 'code' in response: if 'ExecutionReport' in response: if response['ExecutionReport'][ 'orderRejectReason'] == 'orderExceedsLimit': raise InsufficientFunds(self.id + ' ' + self.json(response)) raise ExchangeError(self.id + ' ' + self.json(response)) return response
def request(self, path, api='public', method='GET', params={}, headers=None, body=None): response = self.fetch2(path, api, method, params, headers, body) if response: if 'Success' in response: if response['Success']: return response elif 'Error' in response: if response['Error'] == 'Insufficient Funds.': raise InsufficientFunds(self.id + ' ' + self.json(response)) raise ExchangeError(self.id + ' ' + self.json(response))
def handle_errors(self, code, reason, url, method, headers, body, response=None): # {success: 0, error: "invalid order."} # or # [{data, ...}, {...}, ...] if response is None: if body[0] == '{' or body[0] == '[': response = json.loads(body) if isinstance(response, list): return # public endpoints may return []-arrays if not ('success' in list(response.keys())): return # no 'success' property on public responses if response['success'] == 1: # {success: 1, return: {orders: []}} if not ('return' in list(response.keys())): raise ExchangeError(self.id + ': malformed response: ' + self.json(response)) else: return message = response['error'] feedback = self.id + ' ' + self.json(response) if message == 'Insufficient balance.': raise InsufficientFunds(feedback) elif message == 'invalid order.': raise OrderNotFound(feedback) # cancelOrder(1) elif message.find('Minimum price ') >= 0: raise InvalidOrder( feedback ) # price < limits.price.min, on createLimitBuyOrder('ETH/BTC', 1, 0) elif message.find('Minimum order ') >= 0: raise InvalidOrder( feedback ) # cost < limits.cost.min on createLimitBuyOrder('ETH/BTC', 0, 1) elif message == 'Invalid credentials. API not found or session has expired.': raise AuthenticationError(feedback) # on bad apiKey elif message == 'Invalid credentials. Bad sign.': raise AuthenticationError(feedback) # on bad secret raise ExchangeError(self.id + ': unknown error: ' + self.json(response))
def handle_errors(self, code, reason, url, method, headers, body): if (code == 400) or (code == 404): if body[0] == '{': response = json.loads(body) message = response['message'] error = self.id + ' ' + message if message.find('price too small') >= 0: raise InvalidOrder(error) elif message.find('price too precise') >= 0: raise InvalidOrder(error) elif message == 'Insufficient funds': raise InsufficientFunds(error) elif message == 'NotFound': raise OrderNotFound(error) elif message == 'Invalid API Key': raise AuthenticationError(error) raise ExchangeError(self.id + ' ' + message) raise ExchangeError(self.id + ' ' + body)
def request(self, path, api='public', method='GET', params={}, headers=None, body=None): response = self.fetch2(path, api, method, params, headers, body) if response: if 'message' in response: if response['message'].find( 'not enough exchange balance') >= 0: raise InsufficientFunds(self.id + ' ' + self.json(response)) raise ExchangeError(self.id + ' ' + self.json(response)) return response elif response == '': raise ExchangeError(self.id + ' returned empty response') return response
def throw_exception_on_error(self, response): # # API endpoints return the following formats # {success: False, code: "ERROR", msg: "Min price:100.0"} # {success: True, code: "OK", msg: "Operation succeeded."} # # Web OHLCV endpoint returns self: # {s: "ok", o: [], h: [], l: [], c: [], v: []} # # This particular method handles API responses only # if not ('success' in list(response.keys())): return if response['success'] is True: return # not an error if not ('code' in list(response.keys())) or not ('msg' in list( response.keys())): raise ExchangeError(self.id + ': malformed response: ' + self.json(response)) code = self.safe_string(response, 'code') message = self.safe_string(response, 'msg') feedback = self.id + ' ' + self.json(response) if code == 'UNAUTH': if message == 'Invalid nonce': raise InvalidNonce(feedback) raise AuthenticationError(feedback) elif code == 'ERROR': if message.find('The precision of amount') >= 0: raise InvalidOrder( feedback) # amount violates precision.amount if message.find('Min amount each order') >= 0: raise InvalidOrder(feedback) # amount < limits.amount.min if message.find('Min price:') >= 0: raise InvalidOrder(feedback) # price < limits.price.min if message.find('The precision of price') >= 0: raise InvalidOrder(feedback) # price violates precision.price elif code == 'NO_BALANCE': if message.find('Insufficient balance') >= 0: raise InsufficientFunds(feedback) raise ExchangeError(self.id + ': unknown response: ' + self.json(response))
def request(self, path, api='public', method='GET', params={}, headers=None, body=None): response = self.fetch2(path, api, method, params, headers, body) if 'success' in response: if not response['success']: if response['error'].find( 'Insufficient funds' ) >= 0: # not enougTh is a typo inside Liqui's own API... raise InsufficientFunds(self.id + ' ' + self.json(response)) elif response['error'] == 'Requests too often': raise DDoSProtection(self.id + ' ' + self.json(response)) elif (response['error'] == 'not available') or ( response['error'] == 'external service unavailable'): raise DDoSProtection(self.id + ' ' + self.json(response)) else: raise ExchangeError(self.id + ' ' + self.json(response)) return response
def handle_errors(self, code, reason, url, method, headers, body): if code == 200: if body[0] != '{': # response is not JSON -> resort to default error handler return response = json.loads(body) if 'success' in response: if not response['success']: error = self.safe_string(response, 'error') if not error: raise ExchangeError(self.id + ' returned a malformed error: ' + body) if error == 'no orders': # returned by fetchOpenOrders if no open orders(fix for #489) -> not an error return feedback = self.id + ' ' + self.json(response) messages = self.exceptions['messages'] if error in messages: raise messages[error](feedback) if error.find('It is not enough') >= 0: raise InsufficientFunds(feedback) else: raise ExchangeError(feedback)