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 1 order, when I create an order, I only have 3 requests :
- 1/ to get Wallet balance
- 2/ to get the contract size of a symbol
- 3/ to create an order
1/ 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
2/ get the contract size of a symbol:
def get_contractSize(symbol):
contractsize= exchange.market(symbol)['contractSize']
return contractsize
3/ 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 secondes, and retry, sometime it should retry 6 times to work. So i ll loose 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 ?
If someone can help me, thank you so much.