Skip to main content
Question
FYERS API
Ameet Malekar
Algo Trader
Asked a question 2 years ago

How to get nifty weekly and monthly expiry "dates", and trading holidays dates using python?

Join FYERS Community to pick others' brains on Trading/Investing

I know this is not an answer to your question. But sharing how i am handling the exact requirement of mine. What i do is to select the distinct expiry dates from http://public.fyers.in/sym_details/NSE_FO.csv420. Setup a cron to clear old data and update the database comparing current date, so that it remains updated on each day.

I have another table for holidays, where the trading holidays are collected from nse website https://www.nseindia.com/resources/exchange-communication-holidays560. Once in a year process.

You can use pandas_market_calendar module to get list of all holidays historical to current. Refer this https://github.com/rsheftel/pandas_market_calendars445. Make sure to change market to BSE.

instrument_days = (pd.to39_datetime((instruments['year'] + instruments['mon'] + instruments['day']),
                                  format='%y%b%d')).dt.date14
expiry_day = (instrument_days[instrument_days >= date.today17()]).head(1)
date_filter = ((pd.to39_datetime(expiry_day)).strftime('%y-%b-%d')).split('-')
instruments = instruments[(instruments['year'] == date_filter[0]) &
                          (instruments['mon'] == date_filter[1]) & (instruments['day'] == date_filter[2])]

Related Questions