WebSocket connection upgrade failed (429 - TooManyRequests)

D11458 edited May 2021 in Python client
Hello @rakeshr @sujith ,

I am running a code with a new thread but getting below error after working fine for few minutes:

Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
def on_ticks(ws,ticks):

def on_connect(ws,response):

while True:
def insert_ticks(ticks):
for one_tick in ticks:
**my workings**
# pdb.set_trace()
if condition meets:

now = datetime.datetime.now()
if (now.hour >= 11 and now.minute >= 22 ):
if (now.hour >= 15 and now.minute >= 35):
Initially I was using the main ticks thread for strategy workings and placing order and same thing happened, worked fine for a few minutes then threw error of Toomanyrequests so I tried to move to another thread as above but still same issue.

FYI - Despite this error the code resumes functioning properly in some time but we miss the right price and poses big risk.
  • rakeshr
    WebSocket connection upgrade failed (429 - TooManyRequests)
    You are exceeding the maximum limit for WebSocket connection(it's fixed to 3). So, make sure you are not creating multiple instances at the same time.
  • D11458
    I am running just the above code that too for only 4 instruments. I was earlier placing 4 separate modify orders in this code, so thought that might be >3 connections issue so clubbed that in one modify order as shown in above code. Still same issue.
    Note: After posting this query I commented out "if condition meets:
    kite.modify_order(trd_list[one_tick_token]['m_id'],order_type="MARKET")" and used print command just to check, and it is running without any problem since more than 2 hours.
    FYI - I have gone through multiple threads no help.
  • sujith
    Abrupt disconnections don't get registered at the server. You need to make sure you are not suspending the script which might result in hanging connection at the server and check all the edge-cases in your code wherein disconnect is not called.
  • D11458
    ok...Am I doing this efficient way on establishing connection? could you please see if any changes I can do:

    kws = KiteTicker(api_key, access_token)
  • D11458
    Have sorted this out - the thread can be closed.
This discussion has been closed.