Market feed is stopping abruptly

You can look at the last LTT in terminal and the system time.

@Himanshu_S I’m also trying to get Ticker Data but facing difficulty as I’m other tech stack coder. Would you please guide me we need to get market feed for below scenarios:
1). What is Response Format for Ticker Data?
2). Multiple TimeFrame data of particular index. e.g. NIFTY ticker data of multiple data?

Thanks in advance!

Hi @Dharmender

I am using WebSocket for real-time data and am not working with multiple time frames. I extract the Security ID and LTP from each message. Below is an example of the output format and the corresponding code:

Output

{'type': 'Ticker Data', 'exchange_segment': 2, 'security_id': 37089, 'LTP': '222.25', 'LTT': '15:04:16'}
{'type': 'Previous Close', 'exchange_segment': 2, 'security_id': 37089, 'prev_close': '209.95', 'prev_OI': 1223489152}

Code example

You can further enhance the code.

from dhanhq import marketfeed
import datetime

# Add your Dhan Client ID and Access Token
client_id = "client_ID"
access_token = "access_token"

# Structure for subscribing is (exchange_segment, "security_id", subscription_type)

instruments = [(0, "13", 15), (2, "46118", 15), (2, "46121", 15), (2, "46122", 15), (2, "46125", 15), (2, "46126", 15), (2, "46131", 15), (2, "46132", 15), (2, "46135", 15), (2, "46136", 15), (2, "46139", 15), (2, "46774", 15), (2, "46775", 15), (2, "46776", 15), (2, "46777", 15), (2, "46778", 15), (2, "46786", 15), (2, "46787", 15), (2, "46788", 15), (2, "46789", 15), (2, "46790", 15), (2, "46791", 15), (2, "46794", 15), (2, "46795", 15), (2, "46796", 15), (2, "67073", 15), (2, "67074", 15), (2, "37033", 15), (2, "37034", 15), (2, "37070", 15), (2, "37071", 15), (2, "37089", 15), (2, "37101", 15), (2, "37117", 15), (2, "37118", 15), (2, "37130", 15), (2, "37138", 15)]

version = "v2"          # Mention Version and set to latest version 'v2'

# In case subscription_type is left as blank, by default Ticker mode will be subscribed.

try:
    data = marketfeed.DhanFeed(client_id, access_token, instruments, version)
    while True:
        data.run_forever()
        response = data.get_data()
        # print(response)
        security_id = response.get('security_id')
        LTP = response.get('LTP')
        timestamp = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")
        print(f"Security ID: {security_id}, LTP: {LTP}, Timestamp: {timestamp}")  # Print the security ID, LTP and timestamp 

except Exception as e:
    print(e)

You can refer to my other post HERE, where the discussion appears to have stalled. Despite my persistent follow-ups, it seems the issue is not receiving the attention it deserves.

The issue with the feed provided by Dhan is that it stops abruptly, delivers incomplete responses, and often gets closed due to some SSL error. This has become quite frustrating for me. Kindly test the above code on your end and let me know if it works correctly for you or if you encounter the same issues.

Thanks for sharing details. It really helped.

I also had glimpse to shared thread also. It seems you are facing lots of problems with library. I’m already afraid of it :fearful: