@lacspace/indicators 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 +106 -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,106 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @lacspace/indicators
|
|
4
|
+
|
|
5
|
+
**Streaming technical indicators for live price feeds — push one tick, get the new value in O(1).**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@lacspace/indicators)
|
|
8
|
+
[](https://packagephobia.com/result?p=@lacspace/indicators)
|
|
9
|
+
[](https://bundlephobia.com/package/@lacspace/indicators)
|
|
10
|
+
[](https://www.npmjs.com/package/@lacspace/indicators)
|
|
11
|
+
[](https://github.com/lacspace/npm-packages/blob/main/LICENSE)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
> Most JS indicator libs recompute the entire array on every new candle. This one updates **incrementally** — feed a single live LTP tick and the indicator advances in O(1). Built for real-time charts, screeners and algo bots.
|
|
16
|
+
|
|
17
|
+
- 📈 **RSI, MACD, SMA, EMA, WMA, Bollinger, ATR, VWAP, Stochastic, Supertrend, ADX**
|
|
18
|
+
- ⚡ Incremental `next(tick)` API — perfect for websocket / LTP streams
|
|
19
|
+
- 🧮 Batch helpers too — run over a historical array in one call
|
|
20
|
+
- ✂️ `crossedAbove` / `crossedBelow` for signal logic
|
|
21
|
+
- 🌍 Isomorphic (browser + Node) · 📦 ESM + CJS · 🧩 zero dependencies · fully typed
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @lacspace/indicators # or pnpm add / yarn add / bun add
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Streaming — the whole point
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { RSI, MACD } from "@lacspace/indicators";
|
|
33
|
+
|
|
34
|
+
const rsi = new RSI(14);
|
|
35
|
+
const macd = new MACD(12, 26, 9);
|
|
36
|
+
|
|
37
|
+
// wire straight into your tick feed
|
|
38
|
+
socket.on("ltp", (price) => {
|
|
39
|
+
const r = rsi.next(price); // O(1) — no array recompute
|
|
40
|
+
const m = macd.next(price);
|
|
41
|
+
if (r !== null && r > 70) console.log("overbought", r.toFixed(1));
|
|
42
|
+
if (m) console.log("histogram", m.histogram.toFixed(2));
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Every indicator returns `null` during its warm-up window, then a number (or a struct), and also exposes `.value`.
|
|
47
|
+
|
|
48
|
+
## Batch over history
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { rsi, ema, bollinger, supertrend } from "@lacspace/indicators";
|
|
52
|
+
|
|
53
|
+
const closes = candles.map((c) => c.close);
|
|
54
|
+
|
|
55
|
+
rsi(closes, 14); // (number | null)[]
|
|
56
|
+
ema(closes, 20); // (number | null)[]
|
|
57
|
+
bollinger(closes, 20, 2); // ({ middle, upper, lower, bandwidth } | null)[]
|
|
58
|
+
|
|
59
|
+
// range-based indicators take OHLC bars
|
|
60
|
+
supertrend(candles, 10, 3); // ({ value, direction: 1 | -1 } | null)[]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Signals with crossovers
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { ema, crossedAbove } from "@lacspace/indicators";
|
|
67
|
+
|
|
68
|
+
const fast = ema(closes, 9);
|
|
69
|
+
const slow = ema(closes, 21);
|
|
70
|
+
|
|
71
|
+
for (let i = 1; i < closes.length; i++) {
|
|
72
|
+
if (fast[i - 1] == null || slow[i - 1] == null) continue;
|
|
73
|
+
const golden = crossedAbove(
|
|
74
|
+
{ a: fast[i - 1]!, b: slow[i - 1]! },
|
|
75
|
+
{ a: fast[i]!, b: slow[i]! },
|
|
76
|
+
);
|
|
77
|
+
if (golden) console.log("EMA golden cross at bar", i);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Indicators
|
|
82
|
+
|
|
83
|
+
| Class / fn | Input | Output |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `SMA` `EMA` `WMA` | price | number |
|
|
86
|
+
| `RSI` | price | 0–100 |
|
|
87
|
+
| `MACD` | price | `{ macd, signal, histogram }` |
|
|
88
|
+
| `BollingerBands` | price | `{ middle, upper, lower, bandwidth }` |
|
|
89
|
+
| `ATR` | HLC bar | number |
|
|
90
|
+
| `VWAP` | H/L/C/volume bar | number |
|
|
91
|
+
| `Stochastic` | HLC bar | `{ k, d }` |
|
|
92
|
+
| `Supertrend` | HLC bar | `{ value, direction }` |
|
|
93
|
+
| `ADX` | HLC bar | `{ adx, plusDI, minusDI }` |
|
|
94
|
+
|
|
95
|
+
Batch equivalents: `sma` `ema` `wma` `rsi` `macd` `bollinger` `atr` `supertrend` `adx`.
|
|
96
|
+
|
|
97
|
+
## The Lacspace StockKit
|
|
98
|
+
|
|
99
|
+
| Package | For |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| **`@lacspace/indicators`** | Technical indicators (this package) |
|
|
102
|
+
| [`@lacspace/market`](https://www.npmjs.com/package/@lacspace/market) | P&L, XIRR, brokerage & charges |
|
|
103
|
+
| [`@lacspace/market-clock`](https://www.npmjs.com/package/@lacspace/market-clock) | Is the market open? holidays |
|
|
104
|
+
| [`@lacspace/paper-trade`](https://www.npmjs.com/package/@lacspace/paper-trade) | Headless paper-trading engine |
|
|
105
|
+
|
|
106
|
+
<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/indicators",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Streaming technical indicators (RSI, MACD, EMA, Bollinger, ATR, Supertrend, ADX, VWAP) with O(1) incremental updates for live price feeds. Zero-dependency.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typescript"
|
|
43
43
|
],
|
|
44
44
|
"author": "Lacspace <contact@lacspace.com>",
|
|
45
|
-
"license": "
|
|
45
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
46
46
|
"homepage": "https://lacspace.com/packages",
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|