DEV Community

AION Analytics for AION Analytics (India)

Posted on Originally published at aionanalytics.in

MARKET_CLOSE = time(15, 30) is wrong now. Here is the fix for Indian markets.

Here is a line that exists in a lot of Indian trading code:

MARKET_CLOSE = time(15, 30)
Enter fullscreen mode Exit fullscreen mode

Since 3 August 2026 it is wrong, and wrong in two different directions depending on what you trade.

SEBI's circular of 16 January 2026 (HO/47/11/11(3)2025-MRD-POD2/I/2765/2026) introduced a Closing Auction Session for the cash segment. Stocks that have derivative contracts now stop continuous trading at 15:15 and go into a 20-minute auction until 15:35. Stocks without derivatives still trade continuously to 15:30. Index and stock derivatives now trade to 15:40. So one constant has become three answers, and a script that assumes 15:30 will either send ordinary orders into an auction it does not understand, or stand aside for ten minutes of derivatives trading it thinks has ended.

At AION Analytics (India) we maintain aion-indian-market-calendar, an MIT-licensed Python package for exactly this kind of problem: is this Indian market open right now, is it a trading day, when is the next one. It handles NSE, BSE and MCX, including the MCX evening session and Muhurat trading. No account, no API key.

pip install aion-indian-market-calendar
Enter fullscreen mode Exit fullscreen mode

Every example below was run against version 1.4.1.

The quick checks

from datetime import datetime, date
from aion_indian_market_calendar import is_market_open, next_trading_day

is_market_open("NSE", datetime(2026, 10, 1, 21, 0))   # False
is_market_open("MCX", datetime(2026, 10, 1, 21, 0))   # True, MCX evening session

next_trading_day("NSE", date(2026, 10, 2))           # 2026-10-05
Enter fullscreen mode Exit fullscreen mode

2 October is Gandhi Jayanti, so the next NSE trading day after it is Monday 5 October. One detail worth knowing: next_trading_day returns the same date if that date is itself a trading day, so next_trading_day("NSE", date(2026, 10, 1)) gives you 1 October back. If you want "strictly after", pass the following day.

The closing auction, done properly

For anything time-sensitive, use the calendar object:

from aion_indian_market_calendar import IndiaMarketCalendar

cal = IndiaMarketCalendar.bundled(2026)
when = datetime(2026, 8, 3, 15, 20)

cal.is_market_open(when, market="NSE_EQUITY_FNO_UNDERLYING")         # True:  the auction is running
cal.is_continuous_trading(when, market="NSE_EQUITY_FNO_UNDERLYING")  # False: but it is not continuous
cal.is_continuous_trading(when, market="NSE_EQUITY")                 # True:  stocks without F&O are unaffected
cal.is_market_open(datetime(2026, 8, 3, 15, 35), market="NFO")       # True:  derivatives run to 15:40
Enter fullscreen mode Exit fullscreen mode

This is the distinction that matters. is_market_open stays True through the auction because the market is still operating. If your code places ordinary limit or market orders, gate it on is_continuous_trading instead. That one change is the fix for the hardcoded 15:30.

The segments the package knows about for this change:

Segment Continuous trading Closing auction
NSE_EQUITY_FNO_UNDERLYING, BSE_EQUITY_FNO_UNDERLYING 09:15 to 15:15 15:15 to 15:35
NSE_EQUITY, BSE_EQUITY (no F&O contracts) 09:15 to 15:30 none
NSE_EQUITY_DERIVATIVES, BSE_EQUITY_DERIVATIVES 09:15 to 15:40 none

Queries for dates before 3 August 2026 return the old timings, so your backtests over historical data stay correct without any special casing.

The full session table, including the four auction phases, the reference-price window and the revised pre-open from 7 September 2026, is available as data with the circular paragraph it comes from:

cal.market_timings["NSE_EQUITY_FNO_UNDERLYING"]["closing_auction"]["phases"]
Enter fullscreen mode Exit fullscreen mode

Holidays and special sessions

[str(d) for d in cal.holidays("NSE") if d.month >= 10]
# ['2026-10-02', '2026-10-20', '2026-11-10', '2026-11-24', '2026-12-25']

for e in cal.search("Muhurat"):
    print(e.name, e.start, e.end)
# MCX Muhurat Trading (Diwali) 2026-11-08 17:00:00+05:30 2026-11-08 21:30:00+05:30
# BSE Muhurat Trading (Diwali Laxmi Pujan) 2026-11-08 18:15:00+05:30 2026-11-08 19:15:00+05:30
# NSE Muhurat Trading (Diwali Laxmi Pujan) 2026-11-08 18:15:00+05:30 2026-11-08 19:15:00+05:30
Enter fullscreen mode Exit fullscreen mode

Muhurat trading is the classic case that breaks hardcoded calendars: an evening session on Sunday 8 November, one hour on NSE and BSE and longer on MCX. If your scheduler only knows "weekday and not a holiday", it will miss it.

cal.upcoming(as_of=date(2026, 10, 1), limit=5) gives you the next few market events across all segments, each with its category, which exchanges it applies to, and start and end times in IST.

How the data stays current

Exchanges add closures at short notice. Since 1.4.0, the package fetches holiday data from a published repository at most once a day, verifies it with SHA-256, and swaps it in atomically. A new closure no longer needs a new release of the package. If you run in an air-gapped environment, set AION_IN_CALENDAR_OFFLINE=1 and it uses the bundled data only.

1.4.0 also removed the CLI's anonymous telemetry entirely. It is deleted, not just switched off, and a socket-level test fails the build if anything like it comes back.

Where it fits

  • Order systems: check is_continuous_trading before sending an order, not a clock constant.
  • Schedulers and cron jobs: run the end-of-day job after the right close for the segment, and skip holidays without a hand-maintained list.
  • Backtests: filter bars to real sessions, including the old timings before August 2026.
  • CI: fail a build if a deployment window lands on a trading session.

Get it

pip install aion-indian-market-calendar
Enter fullscreen mode Exit fullscreen mode

User guide: aionanalytics.in/docs/aion-indian-market-calendar-user-guide.txt. The package is free and open source. If you work on Indian markets more broadly, the rest of what we build, including a free daily NIFTY 50 opening band and an event-to-sector impact API with a free tier, is on aionanalytics.in.

Top comments (0)