MCPcopy Create free account
hub / github.com/ccxt/ccxt / handle_errors

Method handle_errors

python/ccxt/async_support/bitrue.py:3134–3184  ·  view source on GitHub ↗
(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody)

Source from the content-addressed store, hash-verified

3132 return {'url': url, 'method': method, 'body': body, 'headers': headers}
3133
3134 def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
3135 if (code == 418) or (code == 429):
3136 raise DDoSProtection(self.id + ' ' + str(code) + ' ' + reason + ' ' + body)
3137 # error response in a form: {"code": -1013, "msg": "Invalid quantity."}
3138 # following block cointains legacy checks against message patterns in "msg" property
3139 # will switch "code" checks eventually, when we know all of them
3140 if code >= 400:
3141 if body.find('Price * QTY is zero or less') >= 0:
3142 raise InvalidOrder(self.id + ' order cost = amount * price is zero or less ' + body)
3143 if body.find('LOT_SIZE') >= 0:
3144 raise InvalidOrder(self.id + ' order amount should be evenly divisible by lot size ' + body)
3145 if body.find('PRICE_FILTER') >= 0:
3146 raise InvalidOrder(self.id + ' order price is invalid, i.e. exceeds allowed price precision, exceeds min price or max price limits or is invalid float value in general, use self.price_to_precision(symbol, amount) ' + body)
3147 if response is None:
3148 return None # fallback to default error handler
3149 # check success value for wapi endpoints
3150 # response in format {'msg': 'The coin does not exist.', 'success': True/false}
3151 success = self.safe_bool(response, 'success', True)
3152 if not success:
3153 messageInner = self.safe_string(response, 'msg')
3154 parsedMessage = None
3155 if messageInner is not None:
3156 try:
3157 parsedMessage = json.loads(messageInner)
3158 except Exception as e:
3159 # do nothing
3160 parsedMessage = None
3161 if parsedMessage is not None:
3162 response = parsedMessage
3163 message = self.safe_string(response, 'msg')
3164 if message is not None:
3165 self.throw_exactly_matched_exception(self.exceptions['exact'], message, self.id + ' ' + message)
3166 self.throw_broadly_matched_exception(self.exceptions['broad'], message, self.id + ' ' + message)
3167 # checks against error codes
3168 error = self.safe_string(response, 'code')
3169 if error is not None:
3170 # https://github.com/ccxt/ccxt/issues/6501
3171 # https://github.com/ccxt/ccxt/issues/7742
3172 if (error == '200') or Precise.string_equals(error, '0'):
3173 return None
3174 # a workaround for {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}
3175 # despite that their message is very confusing, it is raised by Binance
3176 # on a temporary ban, the API key is valid, but disabled for a while
3177 if (error == '-2015') and self.options['hasAlreadyAuthenticatedSuccessfully']:
3178 raise DDoSProtection(self.id + ' temporary banned: ' + body)
3179 feedback = self.id + ' ' + body
3180 self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback)
3181 raise ExchangeError(feedback)
3182 if not success:
3183 raise ExchangeError(self.id + ' ' + body)
3184 return None
3185
3186 def calculate_rate_limiter_cost(self, api, method, path, params, config={}):
3187 if ('noSymbol' in config) and not ('symbol' in params):

Callers

nothing calls this directly

Calls 10

DDoSProtectionClass · 0.90
InvalidOrderClass · 0.90
ExchangeErrorClass · 0.90
findMethod · 0.80
safe_boolMethod · 0.80
safe_stringMethod · 0.80
string_equalsMethod · 0.80
loadsMethod · 0.45

Tested by

no test coverage detected