I have a problem when I send an order to kucoin exchange with the API.
"code":"429000","msg":"Too Many Requests"
It seems that my code send too many requests to Kucoin, my IP address exceed the rate limit (the request rate limit is 30 times/3s).
It happen when I create only one order, when I create an order, I only have 3 requests:
- to get Wallet balance
- to get the contract size of a symbol
- to create an order
get Wallet balance:
def get_usdt_balance(): try: acc_balance = exchange.fetch_balance() return acc_balance['USDT']['free'] except Exception as e: print("an exception occured - {}".format(e)) return False
get the contract size of a symbol:
def get_contractSize(symbol): contractsize= exchange.market(symbol)['contractSize'] return contractsize
create an order
def order(side, quantity, symbol): i = 0 while i < 10: i += 1 try: params = {'leverage': 15} order = exchange.create_order( symbol=symbol, side=side, type='market', amount=quantity, params=params) except Exception as e: print("an exception occured - {}".format(e)) print ('- Retry n°',i,'...') time.sleep(11) continue else: print ("ORDER EXECUTED") print(f"sending order {side} - {symbol}") i == 0 return order
As you can see in the last request, I should set up a "retry if fail" because the 429 error always come, the code wait 11 seconds, and retry, sometime it should retry 6 times to work. So I'll lose more than one minute retrying, (its a scalping strategy I cannot wait that much) for only one order (3 requests) for only one account.
So how can we explain that the code exceed the request rate limit with only 3 requests?