Wrong underlying security id in detailed security master

Hi, I am seeing wrong underlying security ID in detailed security master. For all the index options, these values are either assigned to wrong index or does not exist in the security master altogether.

Can you please fix it?

Below is my script for you to reproduce the issue.

from io import StringIO
import pandas as pd
import requests

df = pd.read_csv(StringIO(requests.get("https://images.dhan.co/api-data/api-scrip-master-detailed.csv").text), low_memory=False) # detailed

# filter symbol which has either UNDERLYING_SECURITY_ID or UNDERLYING_SYMBOL present
df_filtered = df[df['UNDERLYING_SECURITY_ID'].notna() | df['UNDERLYING_SYMBOL'].notna()]
# convert UNDERLYING_SECURITY_ID to int
df_filtered['UNDERLYING_SECURITY_ID'] = df_filtered['UNDERLYING_SECURITY_ID'].astype('Int64')
# filter in INSTRUMENT OPTIDX
df_filtered = df_filtered[df_filtered['INSTRUMENT'] == 'OPTIDX']


df_filtered = df_filtered[['UNDERLYING_SYMBOL', 'UNDERLYING_SECURITY_ID']].drop_duplicates()

for i, row in df_filtered.iterrows():
    underlying_row = df[df['SECURITY_ID'] == row['UNDERLYING_SECURITY_ID']]
    if underlying_row.shape[0] > 0:
        print(f"Underlying Symbol from row: {underlying_row.iloc[0]['SYMBOL_NAME']}, Underlying symbol from df_filtered: {row['UNDERLYING_SYMBOL']} Security ID: {underlying_row.iloc[0]['SECURITY_ID']}")
    else:
        print(f"No underlying security found for Security ID: {row['UNDERLYING_SYMBOL']}")


@PravinJ @Hardik can you guys please look into this?

This is affecting my option chain construction.

Hey @alpha ,

As checked all the security IDs mentioned in the CSV file for all segments are correct as per our records.

We request you to kindly verify whether the mapping has been done properly on your end. Please note that the security instrument CSV file is updated daily in the morning.

You may refer to the CSV file here for your verification https://images.dhan.co/api-data/api-scrip-master-detailed.csv

The output of the script I shared above is,

Underlying Symbol from row: NIFTY MIDCAP 150, Underlying symbol from df_filtered: SENSEX Security ID: 1
No underlying security found for Security ID: SENSEX50
Underlying Symbol from row: NIFTY ALPHA 50, Underlying symbol from df_filtered: BANKEX Security ID: 12
No underlying security found for Security ID: MCXBULLDEX
No underlying security found for Security ID: BANKNIFTY
No underlying security found for Security ID: MIDCPNIFTY
No underlying security found for Security ID: NIFTY
No underlying security found for Security ID: NIFTYNXT50
No underlying security found for Security ID: FINNIFTY

This means that for a SENSEX option, the underlying security id refers to NIFTY MIDCAP 150 index.

For most of the indices no security exists for underlying security ID.

Can you let me know how did you verify that everything is good on your end?

@Shrutika_Poojari can you please answer my above question?