@lacspace/market-clock 1.0.0 → 1.0.2
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/LICENSE +45 -15
- package/README.md +103 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
Lacspace Free Licence
|
|
2
|
+
Version 1.0, August 2026
|
|
2
3
|
|
|
3
4
|
Copyright (c) 2026 Lacspace
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
6
|
+
PREAMBLE
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
This software is published by Lacspace under the Lacspace Free Licence — a free,
|
|
9
|
+
permissive licence that lets you use this software for any purpose, including in
|
|
10
|
+
commercial products and services, at no cost. It grants the same freedoms as
|
|
11
|
+
common permissive open-source licences; the only condition is that this notice
|
|
12
|
+
travels with the software. The canonical, always-current text of this licence is
|
|
13
|
+
maintained at https://lacspace.com/licenses/lacspace-free-1.0
|
|
14
|
+
|
|
15
|
+
GRANT OF RIGHTS
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person or organisation
|
|
18
|
+
obtaining a copy of this software and its associated documentation and data files
|
|
19
|
+
(the "Software"), to deal in the Software without restriction, including without
|
|
20
|
+
limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
21
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
|
22
|
+
Software is furnished to do so, subject to the conditions below. These rights are
|
|
23
|
+
granted for any purpose, personal or commercial, and are perpetual, worldwide,
|
|
24
|
+
non-exclusive, and royalty-free.
|
|
25
|
+
|
|
26
|
+
CONDITIONS
|
|
27
|
+
|
|
28
|
+
The above copyright notice, this permission notice, and the name of this licence
|
|
29
|
+
("Lacspace Free Licence") shall be included in all copies or substantial portions
|
|
30
|
+
of the Software.
|
|
31
|
+
|
|
32
|
+
TRADEMARKS
|
|
33
|
+
|
|
34
|
+
This licence does not grant permission to use the trade names, trademarks, service
|
|
35
|
+
marks, logos, or product names of Lacspace, except as required to reproduce the
|
|
36
|
+
notice above or to describe the origin of the Software in a truthful manner.
|
|
37
|
+
|
|
38
|
+
DISCLAIMER OF WARRANTY AND LIMITATION OF LIABILITY
|
|
14
39
|
|
|
15
40
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
42
|
+
FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
43
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN
|
|
44
|
+
AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
|
45
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
The Lacspace Free Licence is a source-available, permissive licence and is not (as
|
|
50
|
+
of this version) an OSI-approved licence. In substance it grants the same freedoms
|
|
51
|
+
as the MIT Licence. Learn more at https://lacspace.com/licenses
|
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> · Lacspace Free Licence · <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.2",
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"typescript"
|
|
40
40
|
],
|
|
41
41
|
"author": "Lacspace <contact@lacspace.com>",
|
|
42
|
-
"license": "
|
|
42
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
43
43
|
"homepage": "https://lacspace.com/packages",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|