Get Nifty 50 Price using Dhan API

Question 1: How do we get Nifty 50 price in our code using Dhan API?
Question 2: Security Id for Nifty 50?

Hello @abhimaneu

Welcome to Dhan Community!

Can you confirm which Data are you trying to fetch - whether it is Intraday Minute data or Live Market Feed? Also, Security ID for Nifty 50 is 13.

Thankyou, I want to get the current Nifty 50 price 22,325.
Is there any way to fetch that into the program.

@abhimaneu

You can either fetch the same via Websockets i.e. Live Market Feed or even call Intraday Historical Data API.

Hi Dhan Team,

I am facing an issue while pulling live feed for Nifty50

I see there are two indexes which has same security_id 2, and both are indexes.
SEM_EXM_EXCH_ID SEM_SMST_SECURITY_ID SEM_INSTRUMENT_NAME SEM_TRADING_SYMBOL SEM_LOT_UNITS SEM_CUSTOM_SYMBOL
58118 BSE 2 INDEX BSEDSI 1.0 BSE DSI
68123 NSE 2 INDEX NIFTY 1.0 NaN

When I am passing the instrument data to the feed api:
start_feed(instruments, subscription_code, self._on_ticker_connect, self._on_ticker_message)

(Pdb) instruments
[(0, ‘2’)]

as , 0 is for index (IDX) and 2 is security id of Nifty.

I am getting the feed for BSEDSI instead of NIFTY
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 0, ‘security_id’: 2, ‘LTP’: ‘966.22’, ‘LTT’: ‘08:46:00’}
{‘type’: ‘Ticker Data’, ‘exchange_segment’: 0, ‘security_id’: 2, ‘LTP’: ‘966.22’, ‘LTT’: ‘08:46:08’}

Did anyone face this issue? How do we solve this?

Hello @Vikash_Saini

Welcome to Dhan Community!

Over here, 0 is correct, for the exchange segment of Index. But the security ID for Nifty 50 is 13. Do check that on the Security ID List.

If you provide another example to fetch indexes like nifty on the documentation page the confusion will be gone.

I also took a lot of time figuring out this information. I have been trying with marketfeed.NSE instead of marketfeed.IDX

1 Like

Please provide security ids for following below:
FIN NIFTY
MID CAP
BANK NIFITY
SENSEX

Thanks!

Hello @Vivek3

You can fetch the same from Security ID List itself. You just need to add instrument type as INDEX when filtering the list.

@Hardik , can u please give some examples how to fetch security ID from that list
as a curl command

@Vivek3 , just run this command it will provi
curl --location ‘https://api.dhan.co/v2/instrument/IDX_I’ > Index_security_ids.csv

FIN NIFTY 27
MIDCAP 442
BANKNIFTY 25
etc