sensex option symbol not working
-
Re: sensex symbol name is wrong
https://smartapi.angelbroking.com/topic/4871/sensex-symbol-name-is-wrong/4?_=1739357182047
can some help to fix this issue ?
def get_option_symbol():
"""Finds the nearest SENSEX Call Option (CE) for the appropriate expiry."""
try:
# Fetch the spot price for SENSEX
spot = smart_api.ltpData("BSE", "SENSEX", "99919000")
sensex_spot = spot['data']['ltp']# Calculate the nearest strike price (rounded to the nearest 100) strike = round(sensex_spot / 100) * 100 # Get today's date and determine the expiry date today = datetime.datetime.now() expiry_date = datetime.datetime.strptime(get_next_expiry_date(), "%d%b%y") # Format the expiry date in the correct "YYMNDD" format expiry_str = expiry_date.strftime("%y") + expiry_date.strftime("%b").upper()[0] + expiry_date.strftime("%d").zfill(2) # Construct the symbol in the correct format with no spaces symbol = f"SENSEX{expiry_str}{strike}CE" print(f"Searching for symbol: {symbol}") # Print the symbol being searched # Search for the symbol on BSE scrip_info = smart_api.searchScrip("BFO", symbol) if scrip_info and 'data' in scrip_info: token = scrip_info['data'][0]['symboltoken'] ltp = smart_api.ltpData("BFO", symbol, token) if ltp and 'data' in ltp: return {'symbol': symbol, 'token': token, 'premium': ltp['data']['ltp']} else: print(f"⚠️ LTP data not found for {symbol}, skipping.") return None # Skip if no LTP data else: print(f"⚠️ No matching scrip found for {symbol}") return None
i tried many symbol format provided in the above link but still not working
typical output
[I 250212 16:19:09 smartConnect:124] in pool
✅ Successfully logged in!🔍 Checking Entry Condition:
🔹 Current Candle Close: 76238.33 > super_trend: 76034.532? True
🔹 Current Candle Close: 76238.33 > EMA: 76110.50785751663? True
🔹 Supertrend value for current candle: 76034.532
Searching for symbol: SENSEX25F1876200CE
[I 250212 16:19:11 smartConnect:499] Search successful. No matching trading symbols found for the given query.
🚨 Option fetch error: list index out of range
🛑 Manual interruption!can some one please help?
-
@admin , I TRY WITH BFO BUT SAME PROBLEM FOUND NOT WORKED , SAME CODE WORKING IN NIFTY PROPERLY , PLEASE GIVE ME SOLUTION , TNX
-
@gauravbhimani Sensex is BFO and not NFO.
-
@admin , i have same problem like this-
D:\copy trading\nifty\sENSEX>python 123.py
✅ Downloaded and saved instrument data to OpenAPIScripMaster.json
ℹ️ Loading data from local file...
✅ Loaded 2910 SENSEX options instruments
[I 250218 13:58:48 smartConnect:124] in pool
✅ Login Successful!
📅 Nearest expiry date: 18FEB25
Fetching LTP for SENSEX26DEC77000PE (Token: 1114271)
[E 250218 13:58:49 smartConnect:246] Error occurred while making a POST request to https://apiconnect.angelone.in/rest/secure/angelbroking/order/v1/getLtpData. Error: Failed to get symbol details. URL: https://apiconnect.angelone.in/rest/secure/angelbroking/order/v1/getLtpData, Headers: {'Content-type': 'application/json', 'X-ClientLocalIP': '127.0.0.1', 'X-ClientPublicIP': '106.193.147.98', 'X-MACAddress': 'e0:73:e7:11:02:27', 'Accept': 'application/json', 'X-PrivateKey': '4aSo0b8N', 'X-UserType': 'USER', 'X-SourceID': 'WEB'}, Request: {'exchange': 'NFO', 'tradingsymbol': 'SENSEX26DEC77000PE', 'symboltoken': '1114271'}, Response: {'message': 'Failed to get symbol details', 'errorcode': 'AB1018', 'status': False, 'data': None}
❌ Error fetching LTP for SENSEX26DEC77000PE (Token: 1114271): argument of type 'NoneType' is not iterable
Retrying to fetch LTP for SENSEX26DEC77000PE (Token: 1114271)... Attempt 1/3
Fetching LTP for SENSEX26DEC77000PE (Token: 1114271) -
@admin i was able to decode using the master list, you are right.
Thanks
-
@manjunathn1988 it would be easier to fetch the sensex symbol from the instrument master. https://margincalculator.angelone.in/OpenAPI_File/files/OpenAPIScripMaster.json