New release - Subscribe to new segment when connection is ON

HI Team,
With the recent release of subscription with new segment when connection is on. With below code I see the newly subscribed segment on a condition met, its continuously printing the logs in a loop. This is not behaving as per the already subscribed segments?

Is there any way when connection is on, we can quickly get currentmarket rate for any new segment?
try:
data = marketfeed.DhanFeed(client_id, access_token, instruments)
while True:
data.run_forever()
response = data.get_data()
print(response)
if(condition):
res_new = data.subscribe_symbols(sub_instruments)
print(res_new)

except Exception as e:
print(e)

Hello @shbtechno

Welcome to MadeForTrade community!

You can add instruments with subscribe_symbols function now. You will have to handle the part where you get just current market price and then unsubscribe the symbol again.

1 Like

@Hardik please look at this From last 1 week i am waiting for rply

im using websockets to fetch real-time market data, but I’m encountering an issue where the open, high, low, and close values I receive are not updating correctly. Despite receiving new data every second, these values seem to remain stuck at the market open values (9:15 AM) and do not reflect the current time frame.

Here is a snippet of my code:

CODE:

from dhanhq import marketfeed

Add your Dhan Client ID and Access Token

client_id = “Dhan Client ID”
access_token = “Access Token”

Structure for subscribing is (exchange_segment, “security_id”, subscription_type)

instruments = [(marketfeed.NSE, “1333”, marketfeed.Quote)]

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)

Close Connection

data.disconnect()

And here is the output I’m getting:

{‘type’: ‘Quote Data’, ‘exchange_segment’: 1, ‘security_id’: 1333, ‘LTP’: ‘1633.55’, ‘LTQ’: 5, ‘LTT’: ‘12:52:08’, ‘avg_price’: ‘1635.49’, ‘volume’: 4677293, ‘total_sell_quantity’: 959632, ‘total_buy_quantity’: 423493, ‘open’: ‘1637.75’, ‘close’: ‘1637.75’, ‘high’: ‘1639.75’, ‘low’: ‘1630.20’}
{‘type’: ‘Quote Data’, ‘exchange_segment’: 1, ‘security_id’: 1333, ‘LTP’: ‘1633.55’, ‘LTQ’: 5, ‘LTT’: ‘12:52:09’, ‘avg_price’: ‘1635.49’, ‘volume’: 4677298, ‘total_sell_quantity’: 959635, ‘total_buy_quantity’: 423033, ‘open’: ‘1637.75’, ‘close’: ‘1637.75’, ‘high’: ‘1639.75’, ‘low’: ‘1630.20’}
{‘type’: ‘Quote Data’, ‘exchange_segment’: 1, ‘security_id’: 1333, ‘LTP’: ‘1633.65’, ‘LTQ’: 1, ‘LTT’: ‘12:52:09’, ‘avg_price’: ‘1635.49’, ‘volume’: 4678543, ‘total_sell_quantity’: 961004, ‘total_buy_quantity’: 422714, ‘open’: ‘1637.75’, ‘close’: ‘1637.75’, ‘high’: ‘1639.75’, ‘low’: ‘1630.20’}

As you can see, the OHLC values remain constant and do not update with each new tick. Could you please help me resolve this issue?

Thanks!

Hello @Vivek3

As you can refer from Documentation, here OHLC is Day OHLC value, and hence will remain the same throughout the day.