Getting issue with every market feed

Market feed is getting disconnected with following message.
‘no close frame received or sent’

1 Like

Hello @ankita176

Can you confirm which version of library are you on? And is this random disconnection or disconnection while trying to connect initially?

Hi @Hardik ,

from dhanhq import dhanhq
from dhanhq import marketfeed
import pandas as pd
import logging
import datetime
import sys

try:
data = marketfeed.DhanFeed(client_id, access_token, instruments)
while True:
data.run_forever()
response = data.get_data()
print(response)
LTP = float(response.get(‘LTP’))
print(LTP)
except Exception as e:
print(e)

Close Connection

data.disconnect()

# Subscribe instruments while connection is open

sub_instruments = [(exchange_feed, sec_id, marketfeed.Ticker)]

data.subscribe_symbols(sub_instruments)

print(det)

Unsubscribe instruments which are already active on connection

unsub_instruments = [(exchange_feed, sec_id, 16)]

data.unsubscribe_symbols(unsub_instruments)


Getting this message
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 2, ‘security_id’: 65913, ‘LTP’: ‘95.90’, ‘LTT’: ‘10:03:25’}
95.9
Stop loss = 94
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 2, ‘security_id’: 65913, ‘LTP’: ‘95.90’, ‘LTT’: ‘10:03:27’}
95.9
Stop loss = 94
no close frame received or sent

How to check library version?

@Hardik …Anything incorrect with shared piece of code?

Hi @ankita176
Team is looking into this.
Please refer the mentioned thread :

and to check the version you can run the belwo command in terminal :
pip show dhanhq

Name: dhanhq
Version: 1.3.2
Summary: The official Python client for communicating with the Dhan API
Home-page:
Author: Dhan
Author-email: dhan-oss@dhan.co
License: MIT LICENSE
Location: C:\Users\ankita\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires: pandas, requests, websockets
Required-by:

Hello @ankita176

Checking into this, on random disconnection.