Issue with WebSocket Data for Indices

Hi,

I recently subscribed to the Data APIs, but I’m unable to receive WebSocket data for Indices. I’ve tried using Security IDs 1 and 1001 (for Sensex and Nifty 50, respectively) multiple times without success. The FnO segment data is working fine.

Here’s the code I’m using:

subscribeMessage := map[string]interface{}{
		"RequestCode":     21,
		"InstrumentCount": 4,
		"InstrumentList": []map[string]string{
			{
				"ExchangeSegment": "NSE_FNO",
				"SecurityId":      "35089",
			},
			{
				"ExchangeSegment": "NSE_FNO",
				"SecurityId":      "42939",
			},
			{
				"ExchangeSegment": "NSE_EQ",
				"SecurityId":      "1001",
			},
			{
				"ExchangeSegment": "BSE_EQ",
				"SecurityId":      "1",
			},
		},
	}

Could you please assist me in resolving this issue?

@Hardik @Dhan @dhan

Hello @Ronak_Mishra

Welcome to MadeForTrade community! Glad to know you are working with Dhan Live Market Feed.

If you want to fetch data for indices, you have to use ExchangeSegment as IDX_I. You can refer the same in annexure part of Documentation.

I have tried that as well as mentioned in the docs.

subscribeMessage := map[string]interface{}{
		"RequestCode":     21,
		"InstrumentCount": 4,
		"InstrumentList": []map[string]string{
			{
				"ExchangeSegment": "NSE_FNO",
				"SecurityId":      "35089",
			},
			{
				"ExchangeSegment": "NSE_FNO",
				"SecurityId":      "42939",
			},
			{
				"ExchangeSegment": "IDX_I",
				"SecurityId":      "1001",
			},
			{
				"ExchangeSegment": "IDX_I",
				"SecurityId":      "1",
			},
		},
	}

@Ronak_Mishra

You are using incorrect Security ID for indices. For Nifty 50, it is 13 and Sensex is 51.

@Hardik are you not using exchange token for Indices? For FnO I noticed that it exchange token only.

And tried with Security ID 13 and 51 with Exchange Segment IDX_I - Still not getting data for Indices.

Hello @Ronak_Mishra

Not sure what you mean here by “Exchange Token”. We have security ID list on which the DhanHQ APIs work, which can be found here: Instrument List - DhanHQ Ver 2.0 / API Document

On not receiving data, it is working with these very security ID for me, when tried replicating.

@Hardik

“Exchange Token” is assigned by the exchange and is consistent across brokers (others use it, and you also do for instruments other than Indices).

I am able to receive the data now, thanks!

And do you have any plans to include 20 market depth (currently 5) in Websocket data feed?

1 Like

Hi mishra can you paste full code here

Hello @Ronak_Mishra

We are still scaling it for Trading View charts as of now, will let you know when we pick this up.

@Hardik data feed is extremely slow and inconsistent, for example I’m getting max 6 ticks in a minute for Nifty Bank Index, was expecting 1-2 ticks per second, same is the case for options as well.

image

Code -

func parseBinaryIndex(inp []byte) models.ExchangeData {
	close := math.Float32frombits(binary.LittleEndian.Uint32(inp[38:42]))
	ltp := math.Float32frombits(binary.LittleEndian.Uint32(inp[8:12]))
	dhanSecurityId := int(binary.LittleEndian.Uint32(inp[4:8]))
	instrumentInfo := inMemoryCacheService.FetchInstrumentInfoFromDhanSecurityId(dhanSecurityId)

	return models.ExchangeData{
		LastPrice:     ltp,
		TradingSymbol: instrumentInfo.TradingSymbol,
		ExchangeToken: instrumentInfo.ExchangeToken,
		Timestamp:     time.Now(),
		OHLC: models.OHLC{
			Open:  math.Float32frombits(binary.LittleEndian.Uint32(inp[34:38])),
			Close: close,
			High:  math.Float32frombits(binary.LittleEndian.Uint32(inp[42:46])),
			Low:   math.Float32frombits(binary.LittleEndian.Uint32(inp[46:50])),
		},
		NetChange: ltp - close,
	}
}

Hello @Ronak_Mishra

Can you confirm which mode are you subscribing to? and whether this is V2 of Websockets or V1?

Using V2. Mode is “Quote Data” for Indices and “Market Depth” for the rest (FnO).

@Hardik

Hi Hardik & Dhan Team,

i am also using V2

i also raised this issue of delay and slow frequency of updates on websockets around 11 days back, this is a very critical issue and i have still not received any update on this.

Hope it is fixed on top priority

Hello @Ronak_Mishra

Just tried Bank Nifty and it is updating at par with Dhan updates.

@Tushar11 we checked this and even observed it in live markets today, for a liquid Options instrument. The update was same as on Dhan and faster than some of the other platforms.

@Hardik
Please notice, getting only 3-4 ticks of Nifty Bank compared to more than 50 for Nifty 50.

NIFTY 50 24710.55 2024-12-05 15:28:32.695531 +0530 IST m=+27.484722001
NIFTY 50 24711.2 2024-12-05 15:28:33.195124 +0530 IST m=+27.984314460
NIFTY BANK 53621.1 2024-12-05 15:28:33.35046 +0530 IST m=+28.139650293
NIFTY 50 24711.1 2024-12-05 15:28:33.696541 +0530 IST m=+28.485730251
NIFTY 50 24710.85 2024-12-05 15:28:34.208819 +0530 IST m=+28.998007960
NIFTY 50 24711.15 2024-12-05 15:28:34.698491 +0530 IST m=+29.487679501
NIFTY 50 24711.05 2024-12-05 15:28:35.196911 +0530 IST m=+29.986099710
NIFTY 50 24712.4 2024-12-05 15:28:35.698037 +0530 IST m=+30.487224835
NIFTY 50 24710.35 2024-12-05 15:28:36.19519 +0530 IST m=+30.984377251
NIFTY 50 24712.25 2024-12-05 15:28:36.702122 +0530 IST m=+31.491308918
NIFTY 50 24711 2024-12-05 15:28:37.194759 +0530 IST m=+31.983945126
NIFTY 50 24709.7 2024-12-05 15:28:37.697718 +0530 IST m=+32.486904293
NIFTY 50 24711.55 2024-12-05 15:28:38.194664 +0530 IST m=+32.983849460
NIFTY 50 24712.05 2024-12-05 15:28:38.700227 +0530 IST m=+33.489412168
NIFTY 50 24711.6 2024-12-05 15:28:39.196366 +0530 IST m=+33.985550168
NIFTY 50 24711.7 2024-12-05 15:28:39.696244 +0530 IST m=+34.485427918
NIFTY 50 24710.25 2024-12-05 15:28:40.196404 +0530 IST m=+34.985588043
NIFTY 50 24712.1 2024-12-05 15:28:40.697271 +0530 IST m=+35.486454126
NIFTY 50 24710.05 2024-12-05 15:28:41.195999 +0530 IST m=+35.985181710
NIFTY 50 24710.5 2024-12-05 15:28:41.696579 +0530 IST m=+36.485760960
NIFTY 50 24710.65 2024-12-05 15:28:42.19691 +0530 IST m=+36.986092460
NIFTY 50 24710.7 2024-12-05 15:28:42.703545 +0530 IST m=+37.492726168
NIFTY 50 24710.55 2024-12-05 15:28:43.200205 +0530 IST m=+37.989386001
NIFTY BANK 53615.3 2024-12-05 15:28:43.351082 +0530 IST m=+38.140262668
NIFTY 50 24711.15 2024-12-05 15:28:43.699366 +0530 IST m=+38.488546835
NIFTY BANK 53620.25 2024-12-05 15:28:43.852063 +0530 IST m=+38.641243460
NIFTY 50 24710.4 2024-12-05 15:28:44.202446 +0530 IST m=+38.991626168
NIFTY 50 24708.95 2024-12-05 15:28:44.694603 +0530 IST m=+39.483782418
NIFTY 50 24711.45 2024-12-05 15:28:45.201649 +0530 IST m=+39.990827918
NIFTY 50 24710.4 2024-12-05 15:28:45.695006 +0530 IST m=+40.484184585
NIFTY 50 24707.25 2024-12-05 15:28:46.204316 +0530 IST m=+40.993494168
NIFTY 50 24707.65 2024-12-05 15:28:46.708038 +0530 IST m=+41.497215585
NIFTY 50 24709.25 2024-12-05 15:28:47.200417 +0530 IST m=+41.989593918
NIFTY 50 24707.95 2024-12-05 15:28:47.70145 +0530 IST m=+42.490627460
NIFTY 50 24707.35 2024-12-05 15:28:48.201306 +0530 IST m=+42.990482710
NIFTY 50 24708.15 2024-12-05 15:28:48.705647 +0530 IST m=+43.494823585
NIFTY 50 24708.95 2024-12-05 15:28:49.202942 +0530 IST m=+43.992117460
NIFTY 50 24709.1 2024-12-05 15:28:49.704804 +0530 IST m=+44.493979668
NIFTY 50 24708 2024-12-05 15:28:50.197499 +0530 IST m=+44.986673793
NIFTY 50 24708.7 2024-12-05 15:28:50.701439 +0530 IST m=+45.490612918
NIFTY 50 24708.05 2024-12-05 15:28:51.203077 +0530 IST m=+45.992251085
NIFTY 50 24706.95 2024-12-05 15:28:51.698593 +0530 IST m=+46.487766626
NIFTY 50 24708.55 2024-12-05 15:28:52.198915 +0530 IST m=+46.988087668
NIFTY 50 24707.2 2024-12-05 15:28:52.699999 +0530 IST m=+47.489171335
NIFTY 50 24707.9 2024-12-05 15:28:53.195674 +0530 IST m=+47.984845918
NIFTY 50 24707.7 2024-12-05 15:28:53.701906 +0530 IST m=+48.491078043
NIFTY 50 24708.75 2024-12-05 15:28:54.200199 +0530 IST m=+48.989369835
NIFTY 50 24708.95 2024-12-05 15:28:54.698145 +0530 IST m=+49.487315543
NIFTY 50 24707.65 2024-12-05 15:28:55.195757 +0530 IST m=+49.984927210
NIFTY 50 24705.7 2024-12-05 15:28:55.698185 +0530 IST m=+50.487354418
NIFTY 50 24703.85 2024-12-05 15:28:56.202126 +0530 IST m=+50.991294876
NIFTY 50 24706.15 2024-12-05 15:28:56.699654 +0530 IST m=+51.488822876
NIFTY BANK 53608 2024-12-05 15:28:56.851678 +0530 IST m=+51.640846543
NIFTY 50 24707.05 2024-12-05 15:28:57.196245 +0530 IST m=+51.985413251
NIFTY 50 24704.15 2024-12-05 15:28:57.699659 +0530 IST m=+52.488827501

@Hardik please try pulling more than 1000 instruments in one connection (allowed limit is 5000 I believe), and you should see this issue.

Hi @Hardik please help resolve this

Hello @Ronak_Mishra

Let me try this, with more that 1000 instruments. Although our systems do run parallel as individual websocket clients as well, to make sure we are logging in any discrepancy of data at our end.