Kucoin / kucoin-python-sdk

MIT License
46 stars 16 forks source link

Server Side Error - 429-{"code":"429000","msg":"Too Many Requests"} #83

Open rroline opened 2 years ago

rroline commented 2 years ago

While requesting large amounts of data (1 month or more at 1min candles) using the get_kline() and passing parameters pageSize and currentPage, the server returns the error 429-{"code":"429000","msg":"Too Many Requests"} even when putting 15 - 30 sec wait times in between single execution of the method.

The KucoinBaseRestAPI object from the python-sdk has a static method check_response_data that is set to raise a ValueError if the response is not 200 OK. This is what was causing my app to error out even though this error is a server error. To bypass this I have to put it in a try catch block with a pass action when the error is caught. This works but is not ideal for a variety of reasons.

Might I request that the ability to override this functionality manually or specify a custom error handling method of some sort. Causing anything outside of a 200 response to raise an error seems slightly problematic. Here is the block I am requesting to have reviewed:

def check_response_data(response_data): if response_data.status_code == 200: try: data = response_data.json() except ValueError: raise Exception(response_data.content) else: if data and data.get('code'): if data.get('code') == '200000': if data.get('data'): return data['data'] else: return data else: raise Exception("{}-{}".format(response_data.status_code, response_data.text)) else: raise Exception("{}-{}".format(response_data.status_code, response_data.text))