Websocket timing out

Hi

Since yesterday, websocket is timing out once in a while during trading hours. Even when I start the websocket client at about 09:10:00 hrs, it takes 3-4 restarts before it starts receiving data. This has been happening for last 2-3 days.

I am using V2 APIs for websocket.

My timeout is set to 15 seconds. If no update is recieved in 15 seconds, the websocket client auto restarts.

I have subscribed to Nifty_50 in full mode and options ±500 from spot in ltpc mode:

        # Data to be sent over the WebSocket. This is the subscription request.
        data = {
            "guid":  str(uuid.uuid4()),
            "method": "sub",
            "data": {
                "mode": "full",
                "instrumentKeys": [NIFTY_50_INST_KEY]
            }
        }

        data_ltpc = {
            "guid":  str(uuid.uuid4()),
            "method": "sub",
            "data": {
                "mode": "ltpc",
                "instrumentKeys": instrument_keys
            }
        }

My app is deployed in AWS (ap-south-1b, Mumbai), EC2 instance. So, network quality is top notch.

Got kicked out of my trade as the option price reported was about 18-19% below ltp :astonished_face: Seeing this the first time.

I can share logs if required.

Also, between 11:02 and 12:11, the timeout has occurred 11 times in ws client:-

amit@bangalore:~/dissect$ grep 'Websocket communication error' chitragupt_2025-06-27.log 
2025-06-27 11:02:36.170 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:03:02.706 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:03:29.256 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:03:55.805 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:52:56.927 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:53:23.556 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:53:50.114 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:54:16.679 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 11:54:47.169 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 
2025-06-27 12:10:33.640 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: sent 1011 (internal error) keepalive ping timeout; no close frame received
2025-06-27 12:11:00.227 - core.websocket_client - INFO - Websocket communication error. Will wait before retry: 

Actual update received. Look at the timestamp ltt (Thursday, June 26, 2025 3:29:59.892 PM). Did it serve it from cache?

2025-06-27 12:10:45.215 - core.websocket_client - INFO - NSE_FO|56781 > {'ltpc': {'ltp': 250.65, 'ltt': '1750931999892', 'ltq': '75', 'cp': 116.6}}
**strong text**
2025-06-27 12:10:20.952 > update received
2025-06-27 12:10:33.640 > Timeout error
2025-06-27 12:10:43.652 > WS client restarts
2025-06-27 12:10:45.207 > Updates start coming in 
2025-06-27 12:10:45.215 > Wrong ltp reported for NSE_FO|56781 INR 250.65 (around 18-19% below actual!!)
                          *** This exited me from my trade *** 

2025-06-27 12:11:00.227 > WS Timeout 
2025-06-27 12:11:10.238 > WS Client restarts 
2025-06-27 12:11:11.794 > Updates start coming in

Guys, help! Something has definately changed in last 2-3 days.

Thankfully, my trade was small in the LTP issue shared above

@MohitGolecha @Pradeep_Jaiswar @Ketan

Checking sir! @Amit_Kumar_Sharma

Hi @Amit_Kumar_Sharma

V2 WebSocket is deprecated and will soon be out of support. Please switch to the V3 WebSocket.
We have also recently observed some issues with V2 data streaming, including client disconnections.

We highly recommend migrating to V3 as soon as possible.

For more information, please refer to this announcement:

Thanks!

That means back to coding and testing all over again :frowning:

@Ketan @MohitGolecha

Wrong price update provided again over websocket today SL hit. This time it was a proper loss!
Time of event 13:09:18.277 IST

2025-07-03 13:09:18.277 - core.websocket_client - INFO - NSE_FO|56781 > {'ltpc': {'ltp': 92.85, 'ltt': '1751450399981', 'ltq': '75', 'cp': 194.45}}

Option :-

"NIFTY_20250703_25400_CE": [
        "NSE_FO|56781",
        "NIFTY2570325400CE",
        "2025-07-03",
        25400,
        "CE"
  ],

Screenshot showing price range of the option at 13:09 1 min candle

Guys, this can not keep on happening. If websocket v2 api is in prod, it should work properly. Else decommission it. It’s real money at stake.

Just saying upgrade to v3 is not a solution. As long as v2 is in production, it should work correctly.

@MohitGolecha @Ketan @Pradeep_Jaiswar Any updates?

@Amit_Kumar_Sharma I have DM you. Please check once.

1 Like

Hi @MohitGolecha @Pradeep_Jaiswar
I upgraded to websocket v3 in production on 2025-07-08. Since then, I have not seen a single timeout. And this includes the 2025-07-10 expiry :smiley:

Great job! Huge improvement! Kudos to team Upstox :raising_hands:

3 Likes