@lacspace/market-clock 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @lacspace/market-clock
|
|
4
|
+
|
|
5
|
+
**Is the market open right now? When does it next open or close? — a holiday-aware, timezone-correct trading clock.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@lacspace/market-clock)
|
|
8
|
+
[](https://packagephobia.com/result?p=@lacspace/market-clock)
|
|
9
|
+
[](https://bundlephobia.com/package/@lacspace/market-clock)
|
|
10
|
+
[](https://www.npmjs.com/package/@lacspace/market-clock)
|
|
11
|
+
[](https://github.com/lacspace/npm-packages/blob/main/LICENSE)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
> 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).
|
|
16
|
+
|
|
17
|
+
- 🟢 `isOpen()` · `isPreOpen()` · `status()` → `"open" | "pre-open" | "closed"`
|
|
18
|
+
- ⏭️ `nextOpen()` · `nextClose()` · `msToOpen()` · `msToClose()`
|
|
19
|
+
- 📅 Weekend + holiday aware · pre-open session support
|
|
20
|
+
- 🏦 `NSE` / `BSE` presets, or bring your own `ExchangeSpec`
|
|
21
|
+
- ⚡ Zero dependencies · 🌍 isomorphic · 📦 ESM + CJS · fully typed
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @lacspace/market-clock # or pnpm add / yarn add / bun add
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { MarketClock, NSE } from "@lacspace/market-clock";
|
|
33
|
+
|
|
34
|
+
const nse = new MarketClock(NSE);
|
|
35
|
+
|
|
36
|
+
nse.isOpen(); // true / false, right now (IST-correct from any timezone)
|
|
37
|
+
nse.status(); // "open" | "pre-open" | "closed"
|
|
38
|
+
nse.isHoliday(); // is today an exchange holiday?
|
|
39
|
+
|
|
40
|
+
nse.nextOpen(); // Date — next session open
|
|
41
|
+
nse.nextClose(); // Date — next session close
|
|
42
|
+
nse.msToClose(); // ms remaining until close (0 if not open)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Build a live badge
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const label = {
|
|
49
|
+
open: "🟢 Market open",
|
|
50
|
+
"pre-open": "🟡 Pre-open",
|
|
51
|
+
closed: "🔴 Closed",
|
|
52
|
+
}[nse.status()];
|
|
53
|
+
|
|
54
|
+
if (nse.isOpen()) {
|
|
55
|
+
const mins = Math.round(nse.msToClose() / 60000);
|
|
56
|
+
console.log(`${label} · closes in ${mins} min`);
|
|
57
|
+
} else {
|
|
58
|
+
console.log(`${label} · opens ${nse.nextOpen().toLocaleString()}`);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Custom exchange / your own holidays
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { MarketClock, NSE, createClock } from "@lacspace/market-clock";
|
|
66
|
+
|
|
67
|
+
// extend the built-in list
|
|
68
|
+
const nse = new MarketClock({ ...NSE, holidays: [...NSE.holidays, "2026-11-20"] });
|
|
69
|
+
|
|
70
|
+
// or a completely different exchange
|
|
71
|
+
const custom = createClock({
|
|
72
|
+
name: "MyExchange",
|
|
73
|
+
offsetMinutes: 0, // minutes ahead of UTC (no-DST exchanges)
|
|
74
|
+
preOpen: { open: "08:00", close: "08:15" },
|
|
75
|
+
regular: { open: "08:15", close: "16:30" },
|
|
76
|
+
weekend: [0, 6], // Sun, Sat
|
|
77
|
+
holidays: ["2026-12-25"],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> ℹ️ 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.
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
| Member | Returns |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `isOpen(at?)` `isPreOpen(at?)` | boolean |
|
|
88
|
+
| `isHoliday(at?)` `isWeekend(at?)` `isTradingDay(at?)` | boolean |
|
|
89
|
+
| `status(at?)` | `"open" \| "pre-open" \| "closed"` |
|
|
90
|
+
| `nextOpen(from?)` `nextClose(from?)` | Date |
|
|
91
|
+
| `msToOpen(at?)` `msToClose(at?)` | number (ms) |
|
|
92
|
+
| `NSE` `BSE` | `ExchangeSpec` presets |
|
|
93
|
+
|
|
94
|
+
## The Lacspace StockKit
|
|
95
|
+
|
|
96
|
+
| Package | For |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| [`@lacspace/indicators`](https://www.npmjs.com/package/@lacspace/indicators) | Technical indicators |
|
|
99
|
+
| [`@lacspace/market`](https://www.npmjs.com/package/@lacspace/market) | P&L, XIRR, brokerage & charges |
|
|
100
|
+
| **`@lacspace/market-clock`** | Market hours & holidays (this package) |
|
|
101
|
+
| [`@lacspace/paper-trade`](https://www.npmjs.com/package/@lacspace/paper-trade) | Headless paper-trading engine |
|
|
102
|
+
|
|
103
|
+
<div align="center"><sub>Built with care by <a href="https://lacspace.com">Lacspace</a> · powers <a href="https://stockyatra.com">StockYatra</a> · MIT licensed · <a href="https://github.com/lacspace/npm-packages">source</a></sub></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lacspace/market-clock",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Holiday-aware, timezone-correct trading clock — is NSE/BSE open now, next open/close, pre-open, holidays. Bring your own exchange spec. Zero-dependency.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|