Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ const vs = vwapSession(high, low, close, volume, [1, 1]);
## Stateful API (streaming)

```ts
import { createRSI, createVWAPSession } from "ta-crypto";
import { createSMA, createEMA, createRSI, createVWAPSession } from "ta-crypto";

const sma14 = createSMA(14);
const ema14 = createEMA(14);
const rsi14 = createRSI(14);
const nextSma = sma14.next(101.25);
const nextEma = ema14.next(101.25);
const nextRsi = rsi14.next(101.25);

const vwap = createVWAPSession();
Expand All @@ -48,6 +52,24 @@ const nextVwap = vwap.next({
});
```

Websocket-like streaming loop:

```ts
import { createEMA, createRSI } from "ta-crypto";

const ema21 = createEMA(21);
const rsi14 = createRSI(14);

ws.on("message", (tick) => {
const price = Number(tick.last);
const e = ema21.next(price);
const r = rsi14.next(price);
if (e !== null && r !== null) {
// strategy signal path
}
});
```

## Examples

Real-world entry points live in `examples/`:
Expand Down Expand Up @@ -158,28 +180,57 @@ Limitations:
- Orderflow proxies infer pressure from candle direction and volume; they are not a replacement for L2/L3 order book data.
- Different libraries use different warmup conventions; comparisons use overlapping non-null windows.

## Candle Contracts
## Typing and Inputs

`ta-crypto` public APIs accept two input styles:
- Primitive arrays (`number[]`) for low-level control.
- Candle objects with long keys (`open/high/low/close/volume/time`) or aliases (`o/h/l/c/v/t`).

Single-series APIs (for example `sma`, `ema`, `rsi`, `macd`, `bbands`) accept:

```ts
import { rsi } from "ta-crypto";

const close = [101, 102, 103, 104];
const candles = [{ o: 100, h: 102, l: 99, c: 101, v: 10, t: 1 }];

rsi(close, 14);
rsi(candles, 14); // uses candle close/c
```

OHLC/OHLCV APIs (for example `vwap`, `stoch`, `atr`, `natr`, `mfi`, `adx`) accept:

```ts
import { atr, vwap } from "ta-crypto";

atr([102, 103], [99, 100], [101, 102], 14);
atr([{ open: 100, high: 102, low: 99, close: 101, volume: 10 }], 14);

vwap([102, 103], [99, 100], [101, 102], [10, 12]);
vwap([{ o: 100, h: 102, l: 99, c: 101, v: 10 }]);
```

Use typed candles plus helpers:
Helpers:

```ts
import { pluckClose, toOHLCV } from "ta-crypto";

const close = pluckClose(candles);
const { open, high, low, close: c, volume } = toOHLCV(candles, 0);
const ohlcv = toOHLCV(candles, 0);
const ohlcvFromArrays = toOHLCV({ o: [1, 2], h: [3, 4], l: [0, 1], c: [2, 3], v: [5, 6] });
```

Validation:
- Multi-series indicators enforce equal lengths (`assertSameLength`).
- Candle helpers validate finite numeric fields with index-specific error messages.
- Multi-series APIs enforce equal lengths.
- Numeric inputs are validated as finite numbers with index-aware messages when possible.

## Module Imports

```ts
import { sma } from "ta-crypto/indicators";
import { vwapSession } from "ta-crypto/crypto";
import { toOHLCV } from "ta-crypto/candles";
import { createRSI } from "ta-crypto/stateful";
import { createSMA, createEMA, createRSI } from "ta-crypto/stateful";
```

## Bench (internal baseline, 10k candles)
Expand Down
Loading