Although We can use the oneliner fnolist() function from NSEPython API, Lets use Zerodha API to get list of all FNO stocks as a diversification. In case You want to see fnolist() function –
import pandas as pd
instrumentList = pd.read_csv("https://api.kite.trade/instruments")
print(instrumentList)
Triggered at Count Stocks (new stocks are highlighted) Trigger Date Trigger Time
0 Fri Apr 21 2023, 10:07 am 1 APOLLOTYRE 2023-04-21 10:07:00
1 Fri Apr 21 2023, 9:58 am 1 ASIANPAINT 2023-04-21 09:58:00
2 Thu Apr 20 2023, 3:21 pm 1 TATACONSUM 2023-04-20 15:21:00
3 Thu Apr 20 2023, 2:16 pm 1 BAJAJ-AUTO 2023-04-20 14:16:00
4 Thu Apr 20 2023, 12:49 pm 1 CUB 2023-04-20 12:49:00
... ... ... ... ... ...
775 Tue Sep 13 2022, 10:03 am 3 DIXON 2022-09-13 10:03:00
776 Tue Sep 13 2022, 10:03 am 3 DRREDDY 2022-09-13 10:03:00
777 Tue Sep 13 2022, 10:03 am 3 HEROMOTOCO 2022-09-13 10:03:00
778 Tue Sep 13 2022, 10:01 am 2 DRREDDY 2022-09-13 10:01:00
779 Tue Sep 13 2022, 10:01 am 2 HEROMOTOCO 2022-09-13 10:01:00
780 rows × 5 columns
fno_stocks = list(set(instrumentList[instrumentList['segment'] == 'NFO-FUT']["name"].to_list()))
instrumentList[instrumentList['segment'] == 'NFO-FUT']
filters the DataFrame to only include rows where the ‘segment’ column has the value ‘NFO-FUT’. This filtering step narrows down the DataFrame to F&O stocks in the NSE F&O Futures segment..to_list()
converts the filtered DataFrame column into a Python list.list(set(...))
is used to remove any duplicate entries and ensure that each stock name appears only once in the list. The result is assigned to the variable fno_stocks
.
symbol_list = list(set(instrumentList[instrumentList['segment'] == 'NFO-FUT']["tradingsymbol"].to_list()))
symbol_list
symbol_list
.fno_stocks
. Zerodha follows a certain nomenclauture, so it is adhering to it. Now one can write the same above code in single line too!
symbol_list = ['NSE:' + {'NIFTY': 'NIFTY 50', 'BANKNIFTY': 'NIFTY BANK', 'FINNIFTY': 'NIFTY FIN SERVICE'}.get(stocks.upper(), stocks.upper()) for stocks in fno_stocks]