Kucoin / kucoin-futures-python-sdk

MIT License
7 stars 3 forks source link

Exception: 429-{"code":"429000","msg":"Too Many Requests"} #36

Open rezalove3 opened 2 years ago

rezalove3 commented 2 years ago

Exception: 429-{"code":"429000","msg":"Too Many Requests"}

Homeyli commented 1 year ago

I have the same error. I think this error started two weeks ago. What is the cause? I checked the requests. I had a maximum of one request per minute.

clubbrb commented 1 year ago

Also having this error.

@Homeyli where did you find your maximum one request per minute limit?

Docs suggest a rate limit of 30 times/3s for both Trade and User endpoints. I'm definitely not requesting more than that but still getting this error so maybe I also have a one request per minute limit...

Homeyli commented 1 year ago

I also have this fucking problem, my requests are less than what is said in the document.

clubbrb commented 1 year ago

It turns out this error means their server is overloaded and you just have to try again. (docs)

JPizzal commented 1 year ago

Has this situation been fixed?

progressivehed commented 1 year ago

Hi. We are working on it to optimize it.

clubbrb commented 1 year ago

I'm working around this with a While True loop and a 5 minute timeout:

timeout = time.time() + 300
price = None
while price is None:
    try:
        price = market.get_ticker("ETHUSDTM")
    except:
        if time.time() > timeout:
            print("Timeout")
            exit()
        else:
            time.sleep(.5)
            pass
JPizzal commented 1 year ago

Can you adjust the timeout? To say 10secs?

clubbrb commented 1 year ago

for sure!

timeout = time.time() + 10

you may also want to tweak the sleep time in between tries, or just remove it completely if you like eg.

        else:
            time.sleep(.1)
            pass
JPizzal commented 1 year ago

So is it helping bypass that issue? My trade strategy is super fast HFT so I need the info asap all in the blink. What time do you recommend for that to not get to many requests again>?

clubbrb commented 1 year ago

I don't run HFT so I'm not sure if this loop will be fast enough but I think if I were you I would try it without the time.sleep()

JPizzal commented 1 year ago

Love the knowledge and help. Would you be available for hire as a consultant to my coders? Maybe oversea them time to time couple hours a week?

JPizzal commented 1 year ago

So when this 429 loop happens all it does is allow you to retry an order?

But if the order or opportunity is already gone by then it's kinda hurtful to a strategy.

So are you not have any connection issues anymore?

hemswayy commented 1 year ago

This has a solution, you can simply send the request again within the next 2-3 seconds and it will fulfil the order, it is best used with a market order type. Hope this helps

JPizzal commented 1 year ago

So when this 429 loop happens all it does is allow you to retry an order?

But if the order or opportunity is already gone by then it's kinda hurtful to a strategy.

So are you not have any connection issues anymore?

I need maker maker ability 
null-routed commented 1 year ago

I can confirm this issue is still present and it's making me lose quite a bit of opportunities and money. My bot is failing to close orders on time causing me to have to close the orders manually.

A quick example to reproduce the issue:

from kucoin_futures.client import Trade
import time
from datetime import datetime
class Bot():

    def __init__(self, key, secret, passphrase):
        self.client = Trade(key=key, secret=secret, passphrase=passphrase, is_sandbox=False, url='')

    def placeOrder(self, symbol, side, closeOrder = False):

        msg = "CLOSE" if closeOrder else "OPEN"

        try:
            order_id = self.client.create_market_order(symbol = symbol, side = side, lever = 1, size = 1, closeOrder = closeOrder)
            print(f'[{datetime.now().strftime("%H:%M:%S")}] -> {symbol} {msg} order: {order_id}')
        except Exception as e:
            print(f'[{datetime.now().strftime("%H:%M:%S")}] -> {symbol} {msg} order failed: {str(e)}')

myBot = Bot("myKey", "mySecret", "myPassphrase")

# opening orders
for s in ["XBTUSDTM","ETHUSDTM","BNBUSDTM", "BCHUSDTM","CHZUSDTM"]:
    myBot.placeOrder(s,"buy")
    time.sleep(1)

# Sleeping and closing orders
time.sleep(5)

for s in ["XBTUSDTM","ETHUSDTM","BNBUSDTM", "BCHUSDTM","CHZUSDTM"]:
    myBot.placeOrder(s,"buy", True)
    time.sleep(1)

which prompts the following output:

[14:00:21] -> XBTUSDTM OPEN order: {'orderId': '632070d557de1d0001d9ead0'}
[14:00:22] -> ETHUSDTM OPEN order: {'orderId': '632070d6eb20e6000146777b'}
[14:00:24] -> BNBUSDTM OPEN order: {'orderId': '632070d8beda7100015e44d0'}
[14:00:25] -> BCHUSDTM OPEN order: {'orderId': '632070d94fb1ef000127c27a'}
[14:00:27] -> CHZUSDTM OPEN order: {'orderId': '632070db95236400016ddbc3'}
[14:00:33] -> XBTUSDTM CLOSE order failed: 429-{"code":"429000","msg":"Too Many Requests"}
[14:00:35] -> ETHUSDTM CLOSE order: {'orderId': '632070e3eb20e60001469736'}
[14:00:36] -> BNBUSDTM CLOSE order: {'orderId': '632070e44f3b000001233f85'}
[14:00:37] -> BCHUSDTM CLOSE order failed: 429-{"code":"429000","msg":"Too Many Requests"}
[14:00:39] -> CHZUSDTM CLOSE order failed: 429-{"code":"429000","msg":"Too Many Requests"}

even if I am well under the 30/3s rate limit. This needs to be fixed.