OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Kucoin futures API [python] - "code":"429000","msg":"Too Many Requests"

  • Thread starter Thread starter Robin Charles
  • Start date Start date
R

Robin Charles

Guest
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 sends 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:

  1. to get Wallet balance
  2. to get the contract size of a symbol
  3. to create an order

  1. get Wallet balance:

    Code:
     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:

    Code:
     def get_contractSize(symbol):
             contractsize= exchange.market(symbol)['contractSize']
             return contractsize

  3. create an order

    Code:
     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?
<p>I have a problem when I send an order to kucoin exchange with the API.</p>
<blockquote>
<p>"code":"429000","msg":"Too Many Requests"</p>
</blockquote>
<p>It seems that my code sends too many requests to Kucoin,
my IP address exceed the rate limit (the request rate limit is 30 times/3s).</p>
<p>It happen when I create only one order,
when I create an order,
I only have 3 requests:</p>
<ol>
<li>to get Wallet balance</li>
<li>to get the contract size of a symbol</li>
<li>to create an order</li>
</ol>

<ol>
<li><p>get Wallet balance:</p>
<pre><code> 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
</code></pre>
</li>
<li><p>get the contract size of a symbol:</p>
<pre><code> def get_contractSize(symbol):
contractsize= exchange.market(symbol)['contractSize']
return contractsize
</code></pre>
</li>
<li><p>create an order</p>
<pre><code> 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
</code></pre>
</li>
</ol>
<p>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.</p>
<p>So how can we explain that the code exceed the request rate limit with only 3 requests?</p>
 

Latest posts

Top