@lacspace/market-clock
v1.0.4
Published
Holiday-aware, timezone-correct trading clock — is NSE/BSE open now, next open/close, pre-open, holidays. Bring your own exchange spec. Zero-dependency.
Maintainers
Readme
@lacspace/market-clock
Is the market open right now? When does it next open or close? — a holiday-aware, timezone-correct trading clock.
Every trading app needs to answer "are we open?" correctly — accounting for weekends, holidays, pre-open sessions and the exchange's timezone. This does it in a few bytes. Ships with NSE / BSE presets (IST, no DST — so the offset is exact).
- 🟢
isOpen()·isPreOpen()·status()→"open" | "pre-open" | "closed" - ⏭️
nextOpen()·nextClose()·msToOpen()·msToClose() - 📅 Weekend + holiday aware · pre-open session support
- 🏦
NSE/BSEpresets, or bring your ownExchangeSpec - ⚡ Zero dependencies · 🌍 isomorphic · 📦 ESM + CJS · fully typed
Install
npm install @lacspace/market-clock # or pnpm add / yarn add / bun addQuick start
import { MarketClock, NSE } from "@lacspace/market-clock";
const nse = new MarketClock(NSE);
nse.isOpen(); // true / false, right now (IST-correct from any timezone)
nse.status(); // "open" | "pre-open" | "closed"
nse.isHoliday(); // is today an exchange holiday?
nse.nextOpen(); // Date — next session open
nse.nextClose(); // Date — next session close
nse.msToClose(); // ms remaining until close (0 if not open)Build a live badge
const label = {
open: "🟢 Market open",
"pre-open": "🟡 Pre-open",
closed: "🔴 Closed",
}[nse.status()];
if (nse.isOpen()) {
const mins = Math.round(nse.msToClose() / 60000);
console.log(`${label} · closes in ${mins} min`);
} else {
console.log(`${label} · opens ${nse.nextOpen().toLocaleString()}`);
}Custom exchange / your own holidays
import { MarketClock, NSE, createClock } from "@lacspace/market-clock";
// extend the built-in list
const nse = new MarketClock({ ...NSE, holidays: [...NSE.holidays, "2026-11-20"] });
// or a completely different exchange
const custom = createClock({
name: "MyExchange",
offsetMinutes: 0, // minutes ahead of UTC (no-DST exchanges)
preOpen: { open: "08:00", close: "08:15" },
regular: { open: "08:15", close: "16:30" },
weekend: [0, 6], // Sun, Sat
holidays: ["2026-12-25"],
});ℹ️ Holiday lists follow the annual exchange circular and can shift year to year. The built-in NSE list covers nationally-fixed days reliably — verify and extend for full-year accuracy.
API
| Member | Returns |
| --- | --- |
| isOpen(at?) isPreOpen(at?) | boolean |
| isHoliday(at?) isWeekend(at?) isTradingDay(at?) | boolean |
| status(at?) | "open" \| "pre-open" \| "closed" |
| nextOpen(from?) nextClose(from?) | Date |
| msToOpen(at?) msToClose(at?) | number (ms) |
| NSE BSE | ExchangeSpec presets |
The Lacspace StockKit
| Package | For |
| --- | --- |
| @lacspace/indicators | Technical indicators |
| @lacspace/market | P&L, XIRR, brokerage & charges |
| @lacspace/market-clock | Market hours & holidays (this package) |
| @lacspace/paper-trade | Headless paper-trading engine |
Licensing
This package is free under the Lacspace Free Licence — MIT-equivalent freedoms. Use it in personal and commercial projects at no cost; just keep the notice.
Not every Lacspace package is free. We also offer Commercial (paid), Client-specific, and Private (proprietary) packages under separate terms. See the full Lacspace Licence Centre.
Part of the Lacspace ecosystem — 35 zero-dependency, isomorphic TypeScript packages.
