@Hardik it seems that the api_scrip_master has some incorrect data. RELINFRA in EQ has NO as ALLOWEDTOTRADE which is not true. Please check and resolve this.
Hello @sv28
Which link are you using to download the file, as this is not the formatting for API security master.
You can use following link to generate the file: https://images.dhan.co/api-data/api-scrip-master.csv
@Hardik I am using this link https://images.dhan.co/api-data ; I had to change the file because of the issue mentioned below
Ref conversation: [Issue] Same equity symbol for multiple instrument
@Hardik any update on this? Because RELINFRA was not allowed to trade as per the sheet, my system didn’t track it and did not sell it. It was one of the examples where I tracked, but there could had been other case where I might have not.
Sheets like these are mission critical because without their accuracy the systems cannot function. Also, such issues are hard to debug because this is the last place I’ll look into
Hello @sv28
This is not the security master file that we suggest for getting Security ID for API orders, as highlighted before:
On the duplicacy issue, we deployed fixes on that, can you check that?
Okay, now that the fix is deployed, I’ll use the original one.
@Hardik Which field has been added for better identification? I work only in cash market
@sv28 You can find following new columns on the Security Master:
- SEM_EXCH_INSTRUMENT_TYPE
- SEM_SERIES
- SM_SYMBOL_NAME
@Hardik Thank you. I altered the conditions. Can you please confirm if the conditions are fine here? It would help me fixing any nuances which I might have skipped:
PS: I trade in cash segment only
def filter_csv_file(file_path, stocks):
"""Filters SCRIP_MASTER file for specific instruments based on a list of symbols.
Args:
file_path: The path to the CSV file.
stocks: A list of instrument symbols.
Returns:
A dictionary mapping symbols to their corresponding security IDs.
"""
filtered_rows = {}
missing_symbols = set()
with open(file_path, 'r') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
# Extract and normalize instrument information
instrument_name = row['SEM_INSTRUMENT_NAME'].strip()
exchange_id = row['SEM_EXM_EXCH_ID'].strip()
instrument_type = row['SEM_EXCH_INSTRUMENT_TYPE'].strip()
series = row['SEM_SERIES'].strip()
# Check if the instrument is an equity and matches the exchange and series criteria
if instrument_name == 'EQUITY':
if exchange_id in ['NSE'] and series in ['EQ', 'BE']:
is_valid = True
elif exchange_id in ['BSE'] and instrument_type in ['EQ', 'ES']:
is_valid = True
else:
is_valid = False
# If valid, process the symbol and security ID
if is_valid:
symbol = f"{exchange_id}:{row['SEM_TRADING_SYMBOL'].strip()}-{series}"
if symbol in stocks:
filtered_rows[symbol] = row["SEM_SMST_SECURITY_ID"]
else:
missing_symbols.add(symbol)
if missing_symbols:
logging.error(f"The following symbols were not found in the CSV file: {missing_symbols}")
return filtered_rows
Hello @sv28
This looks good. Let me know if you face any issues with the file.