'no close frame received or sent' issue

It is throwing message ’ no close frame received’ after some feeds. How to keep feed capturing open?

2 Likes

same issue for me i’m using paid subscription ,again after 1 or 2 min connection breaks. i not paid for this
Dhan developers kindly let me know any fix for this or my subscription is useless

{‘type’: ‘Ticker Data’, ‘exchange_segment’: 1, ‘security_id’: 5097, ‘LTP’: ‘292.95’, ‘LTT’: ‘13:56:24’}
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 1, ‘security_id’: 5097, ‘LTP’: ‘292.95’, ‘LTT’: ‘13:56:26’}
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 1, ‘security_id’: 5097, ‘LTP’: ‘292.95’, ‘LTT’: ‘13:56:28’}
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 1, ‘security_id’: 5097, ‘LTP’: ‘292.95’, ‘LTT’: ‘13:56:30’}
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 1, ‘security_id’: 5097, ‘LTP’: ‘292.95’, ‘LTT’: ‘13:56:31’}
An error occurred: no close frame received or sent
Connection closed!

4 Likes

Same here …Again and again its disconnecting …

hi Hardik …any reason , Multiple times i need to reconnect …because of below error
Error in DHAN Live Feed no close frame received or sent

1 Like

@Hardik tagging hardik here to bring the issue to his notice.
The issue is happening completely random. it will be working fine and suddenly the code would stop with the mentioned error and we have to trigger it again.

Pls dont rely on 1 datafeed provide, have backup sockets and even if those fail fallback to Quotes/ API calls

1 Like

Hello @avinashpaul01

Thank you for tagging. We are looking into this random occurrence and how it can be avoided.

1 Like

@Hardik This is really a serious issue. I opted for Dhan as my platform for algo trading as it say madefortrade and coded by strategy which is based on Marketfeed and while initially I thought everything will work but in trial I noticed that feed keeps disconnecting after sometime. It is a serious issue to be looked in to and resolved.

1 Like

Hello @rahul108

Would like to connect and resolve this here. This shouldn’t be happening now if the async function is running and while loop is maintained. Let me know if we can connect sometime today or tomorrow to get this resolved. You can DM me directly.

I am facing the same issue. This is really unacceptable

I can see that this issue has been reported in other parts of the forum, weeks back. Shame it hasnt been resolved yet!

Hello @pritam_dhar

Welcome to MadeForTrade community!

Can you confirm if you are using the code on GitHub hands on? Or is there any modification to while loop?

I have tried the native base code as well as calling a custom function instead of the print (response) in your code

For now I am recursively calling the same function in exception block to automatically reconnect on the said exception. This is not ideal

Hello @pritam_dhar

We have pushed some fixes on this, to isolate such instances. Can you check if you are still facing this?

Hello @Hardik - Could you please check this error? This has been happening pretty randomly. Unexpected WebSocket closure: sent 1011 (internal error) keepalive ping timeout; no close frame received

Hello @AmitKAswani

Welcome to MadeForTrade community!

Can you tell me the frequency of these disconnection right now?

It just runs for 3-4 mins and then disconnects…ERROR - Task exception was never retrieved
future: <Task finished name=‘Task-654755’ coro=<WebSocketCommonProtocol.send() done, defined at /home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py:574> exception=ConnectionClosedError(None, Close(code=<CloseCode.INTERNAL_ERROR: 1011>, reason=‘keepalive ping timeout’), None)>
Traceback (most recent call last):
File “/home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py”, line 964, in transfer_data
await asyncio.shield(self._put_message_waiter)
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py”, line 628, in send
await self.ensure_open()
File “/home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py”, line 938, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1011 (internal error) keepalive ping timeout; no close frame received
2024-10-21 12:33:35,439 - ERROR - Task exception was never retrieved
future: <Task finished name=‘Task-654758’ coro=<WebSocketCommonProtocol.send() done, defined at /home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py:574> exception=ConnectionClosedError(None, Close(code=<CloseCode.INTERNAL_ERROR: 1011>, reason=‘keepalive ping timeout’), None)>
Traceback (most recent call last):
File “/home/ec2-user/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py”, line 964, in transfer_data
await asyncio.shield(self._put_message_waiter)
asyncio.exceptions.CancelledError

@Hardik I’m facing the same issue - no close frame received or sent
dhanhq~=1.3.3
I’m saving the data in database, here’s the code for the same
It runs for few minutes and then gives this error.

try:
    data = marketfeed.DhanFeed(client_id, access_token, instruments)
    while True:
        data.run_forever()
        response = data.get_data()
        security_id = str(response['security_id'])
        collection = db[security_id]
        collection.insert_one(response)

except Exception as e:
    print(e)

If you are reading this, I’ll drop here the temporary solution I’m using. this is not ideal but gets the job done. I’ll be using it till this is sorted from Dhan team. I’m calling the function again once exception occurs.

def run_feed():
    try:
        data = marketfeed.DhanFeed(client_id, access_token, instruments)
        while True:
            data.run_forever()
            response = data.get_data()
            print(response)

    except Exception as e:
        print(e)

    finally:
        # Close Connection if it was opened
        try:
            data.disconnect()
        except:
            pass

while True:
    run_feed()

Thanks!! @Vishal_Gawde. I’m doing that too!