Can we find out if market is live via python api?

algotrader29
Is there any way we can find out that this moment market is open or not?

I want to add this code so that my algorithm doesnot run when there is a holiday on weekday or if its a mocktrading day.

I can parse the nse site and find out if market is open or close but was wondering if we can find that via kite connect python api.

am sure there is no such function available but was wondering if there is any workaround jugaad or trick so that we can find out the market is live or not?

maybe if livestraming is null? = market is closed?
  • Nikhil.A
    @algotrader29 As of now, there's no real way to determine the market status. We do intend to stream market status in the future though.
  • vandanchopra
    Hey, You'd mentioned in June 2017, that you intend to stream market status in future. Any update here ?
    If not, what do you recommend ? What's the workaround here ?
  • rishiswethan
    rishiswethan edited July 25
    def holiday_list():
    h_list = open(config.HOLIDAY_LIST_FILE, 'r')
    holiday_list = []

    for i in h_list.readlines():
    if i.strip() != '':
    holiday_list.append(i.strip())

    return holiday_list
  • rishiswethan
    rishiswethan edited July 25
    You can compare the current date with the dates returned from this function. and check for if the current day is sat and sun and stop trading accordingly, this is how I currently do it. You can update the holiday list every year
  • rakeshr
    @vandanchopra
    No, it's still not live.
    For time being, we will recommend you to create holiday calender list at your end and don't run your program on those day's.Something as below:
    cds_holiday_list = ['2019-04-01','2019-04-17','2019-04-19','2019-05-01','2019-06-05','2019-08-12','2019-08-15','2019-09-02','2019-09-10','2019-10-02','2019-10-08','2019-10-28','2019-11-12','2019-12-25']
  • tahseen
    Saw this post today, so quickly wrote something in python to return holidays as an array.

    You can import in your program and use it like

    if today not in holidays():
    os.exit(1)

    Code at
    https://github.com/tahseenjamal/nse_holidays
  • ZI4453
    I think you need to add weekends also to the string array an just append the NSE holidays to close this requirement..
    @tahseen
  • tahseen
    tahseen edited September 2
    @ZI4453
    Adding all weekends in array is an inefficient style of programming when you can check today with weekday number and identity if weekend or not. Request was only for Holidays response.

    Anyway, I have modified the code. Now it just returns True / False. Function is trading_day()

    If True means you can trade and if False, means you cannot trade. So nothing can now become simpler than this

    Enjoy!!
    Tahseen
Sign In or Register to comment.