How to get the base symbol name for an FNO script

Shaha
The tick data received has instrument token as the key.

Using instrument token, i can get the instrument symbol(tradingsymbol) from instrument list.
The tradingsymbol for FNO is e.g. HDFC18NOVFUT.

Now, from this i want to detect the base script name (i.e. HDFCBANK), to fetch certain static parameters of HDFCBANK from a seperate table and apply it for my logic on HDFC18NOVFUT.

I cant just simply strip the symbol HDFC18NOVFUT from the first occurring digit, as there are some symbols that has digit in base name also (e.g. TV18BRDCST18NOVFUT). Also it would not be the best way to do, as there can be any new symbols like that in future, where the method will behave weird.

There would already be a better ready way to do it. Perhaps a ready one to one mapping of the FNO scripts with base symbol available to download from kite connect like the instrument list.

Is there a mapping available? Or any alternative? Any suggestions pls?


  • prakash.jj
    prakash.jj edited November 23
    An easier way would be to remove 8 characters from right for future scrips... If its Option then its bit difficult as the length changes as per the strike price...
  • raja1sttarde
    Hi,

    Do not use instrument token. instrument token numbers get re-assigned. A instrument token that is ABC18NOVFUT may be reassigned to XYZOption AFTER ABC18NOVFUT expires.


    I don't know of any easy way to parse Z-Trading symbols.

    I started my database based on day-end files from NSE. NSE FO files have individual fields for 'script name', 'strike price', 'expiry date', 'instrument type' ('ce'/'pe'), and the most useful field i find is 'instrument' values optstk=>option stock, optidx=>option index, futstk=>equity futures, etc.

    in my FO table, pk would be (date, 'script name', 'strike price', 'expiry date') which would make my index's heavy and slow.

    What I do is;

    assign a numeric code to each script name
    table1(auto `id`, `symbol` txt)

    table2(auto `myToken`, 'scriptCd' (from table1), 'expiry date')

    at the time of insert data, i populate these fields and insert my data into data tables.

    so now `script` has a code and [`script` and `expiry dt`] has a code.

    in my equity data table i can use pk(date, scriptCd)
    and fo table pk(date, `myToken`, strike)

    this comes real handy when i want to look at my options data.
    i can select by date & myToken, which will bring up all options data for all strike price for that date (think option chain), instead of calling each and every tradingsymbol to get the complete map.
    for futures, same select only strike price=0

    Here is the kicker. Companies change their names. NSE provides a file for all name changes too. NSE infact provides every kind of data that you will ever need. It really is an awesome exchange.

    I pick up these file daily, amongst others.
    list of all symbols => if new script, assign new code
    name change list=> update script code in my tables with new script code

    I have data from NSE going back to 2012. some companies have changed there names 9 times since.
    if you want, NSE provides data going back to the day they started. wget does not work. use curl. also NSE has some kind of limit. after so many files it will make you wait 2 minutes before giving your the next set of files.

    It was hard work the, innitial set up.

    Another thing, Z-trading symbols, I have not been able to find a naming convention.
    for eg. normaly a option tradingsymbol is; concat('script name', 'year 2 digit', 'month 3 letter caps', 'strike price', 'instrument type')
    now a option that has more than one expiry in a month (banknifty and sometimes nifty) is; concat('script name', 'date dd', 'month 3 letter caps', year 2 digit, 'strike price', 'instrument type')

    normally it would have been so much easier to follow one naming convention. if bank nifty can have multiple expiries who is to say sometime in the future all derivatives can't have multiple expiry dates with in a month.

    It is a good idea to to capture NSE day end files. Z-feed will give data for within market times. When I match with NSE day end data I find lots of data for transaction, which i guess are AMO or periods when only NSE brokers can do settlement trade. IF open interest is important in your calculations.

    Hope it helps.

    Happy coding.
    Cheers.
  • Shaha
    @prakash.jj and @raja1sttarde , both of your inputs helped.

    For my usecase, i used a simple way out to strip last 8 chars, as per @prakash.jj as i am currently looking for in Futures only. The instrument token changes i am taking care of by an EOD script which is linked to NSE website data.

    Thanks.

    PS: Some other references,
    https://www.nseindia.com/content/fo/fo_underlyinglist.htm
    https://www.nseindia.com/products/content/derivatives/equities/contract_specifitns.htm
Sign In or Register to comment.