@lacspace/indicators 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.
Files changed (2) hide show
  1. package/README.md +106 -0
  2. package/package.json +1 -1
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
+ [![npm version](https://img.shields.io/npm/v/@lacspace/indicators?color=%2316a34a&label=npm)](https://www.npmjs.com/package/@lacspace/indicators)
8
+ [![install size](https://packagephobia.com/badge?p=@lacspace/indicators)](https://packagephobia.com/result?p=@lacspace/indicators)
9
+ [![minzipped](https://img.shields.io/bundlephobia/minzip/@lacspace/indicators?label=minzip)](https://bundlephobia.com/package/@lacspace/indicators)
10
+ [![types](https://img.shields.io/badge/types-included-blue)](https://www.npmjs.com/package/@lacspace/indicators)
11
+ [![license](https://img.shields.io/npm/l/@lacspace/indicators?color=green)](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> · 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/indicators",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",