示例#1
0
 def handle_errors(self,
                   code,
                   reason,
                   url,
                   method,
                   headers,
                   body,
                   response=None):
     if not isinstance(body, basestring):
         return  # fallback to default error handler
     if len(body) < 2:
         return  # fallback to default error handler
     if body.find('You are not authorized') >= 0:
         raise PermissionDenied(body)
     if body[0] == '{':
         response = json.loads(body)
         if 'responseStatus' in response:
             errorCode = self.safe_string(response['responseStatus'],
                                          'errorCode')
             message = self.safe_string(response['responseStatus'],
                                        'message')
             feedback = self.id + ' ' + body
             if errorCode is not None:
                 exceptions = self.exceptions
                 if errorCode in exceptions:
                     raise exceptions[errorCode](feedback)
                 raise ExchangeError(feedback)
             # Sometimes there isn't 'errorCode' but 'message' is present and is not 'OK'
             elif message is not None and message != 'OK':
                 raise ExchangeError(feedback)
示例#2
0
 def request(self, path, api='public', method='GET', params={}, headers=None, body=None):
     response = self.fetch2(path, api, method, params, headers, body)
     message = self.id + ' ' + self.json(response)
     if 'error' in response:
         if 'code' in response['error']:
             code = response['error']['code']
             if code == '2033':
                 # \u64cd\u4f5c\u5931\u8d25\uff01\u8ba2\u5355\u5df2\u5b8c\u6210\u6216\u5df2\u64a4\u9500
                 # operation failednot  Orders have been completed or revoked
                 # e.g. trying to cancel a filled order
                 raise OrderNotFound(message)
             elif code == '2068':
                 # \u4e0b\u5355\u6570\u91cf\u4e0d\u80fd\u4f4e\u4e8e
                 # The number of orders can not be less than
                 raise InvalidOrder(message)
             elif code == '3012':
                 raise AuthenticationError(message)  # invalid apiKey
             elif code == '3024':
                 raise PermissionDenied(message)  # insufficient apiKey permissions
             elif code == '3025':
                 raise AuthenticationError(message)  # signature failed
             elif code == '4000':
                 # \u5f53\u524d\u7f51\u7edc\u8fde\u63a5\u4e0d\u7a33\u5b9a\uff0c\u8bf7\u7a0d\u5019\u91cd\u8bd5
                 # The current network connection is unstable. Please try again later
                 raise ExchangeNotAvailable(message)
             elif code == '4003':
                 raise DDoSProtection(message)  # server is busy, try again later
         raise ExchangeError(message)
     if not('result' in list(response.keys())):
         raise ExchangeError(message)
     if method == 'GET':
         return response
     else:
         return response['result'][0]