API to get Holiday


  • Is there any API available that tell us today market holiday or not?


  • Hi @Vishal-naykawala

    Apologies for delayed response.
    Currently we are not providing the market holidays on smartAPI.

    Thanks & Regards,
    SmartAPI team


  • @Vishal-naykawala
    We can write our own script to find the market Holidays
    I am having three methods

    1. Web scalping
    2. Excel file holiday data
    3. Directly paste the holiday from know sites into our script

  • You can use NSE API

    import datetime
    
    import pandas as pd
    import requests
    
    
    def is_holiday(date: datetime.date):
        headers = {'user-agent': 'PostmanRuntime/7.26.5'}
        endpoint = "https://www.nseindia.com/api/holiday-master?type=trading"
        response = requests.get(endpoint, headers=headers)
        assert response.status_code == 200, response.json()
        holidays_json = response.json()['FO']
        holidays_df = pd.DataFrame(holidays_json)
        holidays_df['tradingDate'] = pd.to_datetime(holidays_df['tradingDate'])
        return pd.Timestamp(date) in holidays_df['tradingDate'].values