tradelab 1.1.0 → 1.2.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 (39) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +183 -373
  3. package/dist/cjs/index.cjs +39 -12
  4. package/dist/cjs/live.cjs +457 -18
  5. package/docs/README.md +32 -66
  6. package/docs/api-reference.md +269 -144
  7. package/docs/backtest-engine.md +167 -321
  8. package/docs/data-reporting-cli.md +114 -156
  9. package/docs/examples.md +6 -6
  10. package/docs/live-trading.md +254 -134
  11. package/docs/mcp.md +244 -23
  12. package/docs/research.md +99 -45
  13. package/examples/mcpLiveTrading.js +77 -0
  14. package/package.json +11 -3
  15. package/src/engine/optimize.js +25 -1
  16. package/src/engine/portfolio.js +6 -2
  17. package/src/live/dashboard/server.js +67 -8
  18. package/src/live/engine/paperEngine.js +21 -11
  19. package/src/live/index.js +2 -0
  20. package/src/live/session.js +439 -0
  21. package/src/mcp/liveTools.js +202 -0
  22. package/src/mcp/schemas.js +119 -0
  23. package/src/mcp/server.js +5 -1
  24. package/src/mcp/tools.js +125 -2
  25. package/src/research/monteCarlo.js +6 -2
  26. package/templates/dashboard.html +595 -108
  27. package/types/index.d.ts +25 -0
  28. package/types/live.d.ts +102 -1
  29. package/types/mcp.d.ts +17 -0
  30. package/docs/superpowers/plans/2026-00-overview.md +0 -101
  31. package/docs/superpowers/plans/2026-01-metrics-correctness.md +0 -873
  32. package/docs/superpowers/plans/2026-02-indicator-library.md +0 -677
  33. package/docs/superpowers/plans/2026-03-overfitting-toolkit.md +0 -882
  34. package/docs/superpowers/plans/2026-04-async-signals-seeding.md +0 -981
  35. package/docs/superpowers/plans/2026-05-mcp-server.md +0 -758
  36. package/docs/superpowers/plans/2026-06-parallel-param-sweep.md +0 -508
  37. package/docs/superpowers/plans/2026-07-funding-carry-costs.md +0 -535
  38. package/docs/superpowers/plans/2026-08-live-dashboard.md +0 -547
  39. package/docs/superpowers/plans/HANDOFF.md +0 -88
package/docs/README.md CHANGED
@@ -1,78 +1,44 @@
1
- # tradelab docs
1
+ # Documentation
2
2
 
3
- ## Guides
3
+ Use this page to choose the right guide. If you are new to tradelab, read the first three links in order.
4
4
 
5
- - [Backtest engine](backtest-engine.md)
6
- - [Data, reporting, and CLI](data-reporting-cli.md)
7
- - [Live trading](live-trading.md)
8
- - [Strategy examples](examples.md)
9
- - [API reference](api-reference.md)
5
+ ## Start Here
10
6
 
11
- ## Choose a path
7
+ 1. [Backtesting](backtest-engine.md) - the `signal()` contract, result shape, costs, portfolio runs, walk-forward validation, and parameter sweeps.
8
+ 2. [Data, reporting, and CLI](data-reporting-cli.md) - Yahoo data, CSV files, cache helpers, exported reports, and terminal commands.
9
+ 3. [Live trading](live-trading.md) - paper mode, broker adapters, persisted state, multi-system orchestration, and the local dashboard.
12
10
 
13
- | Goal | Start here |
14
- | ------------------------------------------ | ------------------------------------------------- |
15
- | Run one strategy on one dataset | [Backtest engine](backtest-engine.md) |
16
- | Load Yahoo or CSV data | [Data, reporting, and CLI](data-reporting-cli.md) |
17
- | Export reports or machine-readable results | [Data, reporting, and CLI](data-reporting-cli.md) |
18
- | Run multiple symbols together | [Backtest engine](backtest-engine.md) |
19
- | Run walk-forward validation | [Backtest engine](backtest-engine.md) |
20
- | Run one strategy live or in paper mode | [Live trading](live-trading.md) |
21
- | Run multiple live systems together | [Live trading](live-trading.md) |
22
- | See complete strategy patterns | [Strategy examples](examples.md) |
23
- | Check the exact public exports | [API reference](api-reference.md) |
11
+ ## Reference
24
12
 
25
- ## Package scope
13
+ - [API reference](api-reference.md) - public exports by module.
14
+ - [Research tools](research.md) - Monte Carlo, deflated Sharpe, PBO, and CPCV.
15
+ - [MCP server](mcp.md) - `tradelab-mcp` setup and tool list.
16
+ - [Strategy examples](examples.md) - complete strategy patterns you can adapt.
26
17
 
27
- tradelab is built for:
18
+ ## Common Paths
28
19
 
29
- - candle-based strategy research
30
- - optional tick or quote replay with event-driven fills
31
- - historical backtests with configurable fills and costs
32
- - live and paper execution using broker adapters
33
- - CSV and Yahoo-based data workflows
34
- - exportable outputs for review or automation
20
+ | If you want to... | Read |
21
+ | --------------------------------- | --------------------------------------------------------- |
22
+ | Run one strategy on OHLCV candles | [Backtesting](backtest-engine.md) |
23
+ | Load Yahoo or CSV data | [Data, reporting, and CLI](data-reporting-cli.md) |
24
+ | Export HTML, CSV, or JSON | [Data, reporting, and CLI](data-reporting-cli.md) |
25
+ | Combine several systems | [Backtesting](backtest-engine.md#portfolio-backtests) |
26
+ | Test parameter stability | [Backtesting](backtest-engine.md#walk-forward-validation) |
27
+ | Run a local paper session | [Live trading](live-trading.md) |
28
+ | Connect an MCP client | [MCP server](mcp.md) |
29
+ | Check exact function names | [API reference](api-reference.md) |
35
30
 
36
- tradelab is not built for:
31
+ ## Package Scope
37
32
 
38
- - exchange microstructure modeling
33
+ tradelab is built for strategy research and operational dry-runs:
39
34
 
40
- ## Common workflows
35
+ - candle and tick backtests
36
+ - shared-capital portfolio simulation
37
+ - realistic cost assumptions
38
+ - walk-forward validation and overfitting checks
39
+ - paper and live execution through broker adapters
40
+ - local reports and machine-readable exports
41
41
 
42
- ### Single strategy workflow
42
+ It is not an exchange simulator. It does not try to model full market depth, queue priority, latency, or venue-specific microstructure.
43
43
 
44
- 1. Load candles with `getHistoricalCandles()` or your own dataset
45
- 2. Run `backtest()`
46
- 3. Inspect `result.metrics` and `result.positions`
47
- 4. Export HTML, CSV, or JSON if needed
48
-
49
- ### Multi-symbol workflow
50
-
51
- 1. Prepare one candle array per symbol
52
- 2. Run `backtestPortfolio()`
53
- 3. Review combined `metrics`, `positions`, and `eqSeries`
54
-
55
- ### Validation workflow
56
-
57
- 1. Build a `signalFactory(params)`
58
- 2. Create parameter sets
59
- 3. Run `walkForwardOptimize()`
60
- 4. Review per-window winners before trusting the aggregate result
61
-
62
- ### Live execution workflow
63
-
64
- 1. Build a `signal()` used in backtest first
65
- 2. Wire it into `LiveEngine` with a broker or `PaperEngine`
66
- 3. Persist state with `JsonFileStorage`
67
- 4. Start with `tradelab paper` or `tradelab live --paper`
68
- 5. Inspect persisted state with `tradelab status`
69
-
70
- ## Documentation map
71
-
72
- - [Backtest engine](backtest-engine.md): strategy inputs, engine options, result shape, portfolio mode, walk-forward mode
73
- - [Data, reporting, and CLI](data-reporting-cli.md): data loading, cache behavior, exports, terminal usage
74
- - [Live trading](live-trading.md): live engine, broker adapters, paper mode, orchestration, lifecycle, and state
75
- - [Strategy examples](examples.md): mean reversion, breakout, sentiment, LLM, and portfolio research patterns
76
- - [API reference](api-reference.md): compact export index
77
-
78
- <small>[Back to README.md](../README.md)</small>
44
+ [Back to README](../README.md)
@@ -1,179 +1,304 @@
1
1
  # API reference
2
2
 
3
- <small>[Back to main page](README.md)</small>
3
+ <small>[Back to docs](README.md)</small>
4
4
 
5
- This page is the compact index of public exports.
5
+ This is the import index for the public package surface. For explanations and longer examples, start with the guides linked from [docs/README.md](README.md).
6
6
 
7
- If you are learning the package, start with [backtest-engine.md](backtest-engine.md) or [data-reporting-cli.md](data-reporting-cli.md). This page is for quick lookup.
7
+ ## Entry Points
8
8
 
9
- ## Backtesting
9
+ | Import path | Use it for |
10
+ | --------------- | ---------------------------------------------- |
11
+ | `tradelab` | Backtests, data, reports, research, indicators |
12
+ | `tradelab/data` | Data helpers only |
13
+ | `tradelab/live` | Paper/live engines, broker adapters, dashboard |
14
+ | `tradelab/ta` | Technical indicators |
15
+ | `tradelab/mcp` | Programmatic MCP server creation |
10
16
 
11
- | Export | Summary |
12
- | ------------------------------ | -------------------------------------------------------------- |
13
- | `backtest(options)` | Run one strategy on one candle series |
14
- | `backtestTicks(options)` | Run one strategy on tick or quote data |
15
- | `backtestPortfolio(options)` | Run multiple systems through a shared-capital portfolio engine |
16
- | `walkForwardOptimize(options)` | Run rolling or anchored train/test validation |
17
- | `buildMetrics(input)` | Compute metrics from realized trades and equity data |
17
+ CLI binaries:
18
18
 
19
- ## Data
19
+ | Binary | Use it for |
20
+ | -------------- | ------------------------------- |
21
+ | `tradelab` | Backtests, reports, live, paper |
22
+ | `tradelab-mcp` | stdio MCP server |
20
23
 
21
- | Export | Summary |
22
- | -------------------------------------------------------- | --------------------------------------------- |
23
- | `getHistoricalCandles(options)` | Load candles from Yahoo or CSV |
24
- | `backtestHistorical({ data, backtestOptions })` | Load candles and immediately run `backtest()` |
25
- | `fetchHistorical(symbol, interval, period, options)` | Call the Yahoo layer directly |
26
- | `fetchLatestCandle(symbol, interval, options)` | Fetch the latest Yahoo candle |
27
- | `loadCandlesFromCSV(filePath, options)` | Parse and normalize a CSV file |
28
- | `normalizeCandles(candles)` | Normalize candle field names and sort/dedupe |
29
- | `mergeCandles(...arrays)` | Merge multiple candle arrays |
30
- | `candleStats(candles)` | Return summary stats for a candle array |
31
- | `saveCandlesToCache(candles, meta)` | Write normalized candles to the local cache |
32
- | `loadCandlesFromCache(symbol, interval, period, outDir)` | Read normalized candles from the local cache |
33
- | `cachedCandlesPath(symbol, interval, period, outDir)` | Return the expected cache path |
24
+ ## Main Module: `tradelab`
34
25
 
35
- ## Reporting
26
+ ```js
27
+ import { backtest, getHistoricalCandles, ema } from "tradelab";
28
+ ```
29
+
30
+ ### Backtesting
31
+
32
+ | Export | Summary |
33
+ | ------------------------------ | ------------------------------------------------------------------------------- |
34
+ | `backtest(options)` | Run one synchronous signal over one candle series |
35
+ | `backtestAsync(options)` | Run one async signal over one candle series |
36
+ | `backtestTicks(options)` | Run one signal on tick-like data with tick-level fill handling |
37
+ | `backtestPortfolio(options)` | Run multiple systems through shared capital |
38
+ | `walkForwardOptimize(options)` | Run rolling or anchored train/test validation |
39
+ | `grid(spec)` | Expand scalar/array parameter specs into parameter sets |
40
+ | `optimize(options)` | Run parameter sets in worker threads with a strategy module |
41
+ | `LlmSignal` | Async signal wrapper with timeout, one-decision-per-bar cache, and decision log |
42
+
43
+ `backtest()` returns:
44
+
45
+ | Field | Meaning |
46
+ | --------------- | ---------------------------------------------- |
47
+ | `trades` | Realized legs, including partial exits |
48
+ | `positions` | Completed positions |
49
+ | `openPositions` | Positions still open at the end of the data |
50
+ | `metrics` | Aggregate performance statistics |
51
+ | `eqSeries` | Realized equity points for charts and exports |
52
+ | `replay` | Lightweight chart frames and entry/exit events |
53
+
54
+ ### Metrics
55
+
56
+ | Export | Summary |
57
+ | ----------------------- | ----------------------------------------------------- |
58
+ | `buildMetrics(input)` | Compute aggregate metrics from trades/equity |
59
+ | `benchmarkStats(input)` | Compute benchmark comparison stats |
60
+ | `periodsPerYear(value)` | Convert interval/bar spacing to annualization periods |
61
+ | `clampFinite(value)` | Clamp non-finite numbers for report output |
62
+ | `BIG_NUMBER` | Large finite sentinel used by metrics |
63
+
64
+ ### Strategy Registry
65
+
66
+ | Export | Summary |
67
+ | ----------------------------- | ------------------------------------------- |
68
+ | `listStrategies()` | List built-in and registered strategy names |
69
+ | `getStrategy(name)` | Get a registered strategy factory |
70
+ | `registerStrategy(name, def)` | Register a named strategy at runtime |
71
+
72
+ Strategy definitions use:
73
+
74
+ ```js
75
+ registerStrategy("my-strategy", {
76
+ description: "Readable description",
77
+ params: {
78
+ lookback: { type: "number", default: 20 },
79
+ },
80
+ factory(params) {
81
+ return (context) => null;
82
+ },
83
+ });
84
+ ```
85
+
86
+ ### Data
87
+
88
+ | Export | Summary |
89
+ | -------------------------------------------------------- | ------------------------------------------ |
90
+ | `getHistoricalCandles(options)` | Load candles from Yahoo or CSV |
91
+ | `backtestHistorical({ data, backtestOptions })` | Load data and immediately run `backtest()` |
92
+ | `fetchHistorical(symbol, interval, period, options)` | Fetch Yahoo candles directly |
93
+ | `fetchLatestCandle(symbol, interval, options)` | Fetch the latest Yahoo candle |
94
+ | `loadCandlesFromCSV(filePath, options)` | Parse and normalize a CSV file |
95
+ | `normalizeCandles(candles)` | Normalize field names, sort, and dedupe |
96
+ | `mergeCandles(...arrays)` | Merge candle arrays, sort, and dedupe |
97
+ | `candleStats(candles)` | Summarize count, range, duration, interval |
98
+ | `saveCandlesToCache(candles, meta)` | Write candles to the local cache |
99
+ | `loadCandlesFromCache(symbol, interval, period, outDir)` | Read candles from the local cache |
100
+ | `cachedCandlesPath(symbol, interval, period, outDir)` | Return the expected cache path |
101
+
102
+ ### Reporting
103
+
104
+ | Export | Summary |
105
+ | ---------------------------------- | -------------------------------------------- |
106
+ | `renderHtmlReport(options)` | Return the HTML report as a string |
107
+ | `exportHtmlReport(options)` | Write an HTML report |
108
+ | `exportTradesCsv(trades, options)` | Write a trade or position CSV ledger |
109
+ | `exportMetricsJSON(options)` | Write machine-readable metrics JSON |
110
+ | `exportBacktestArtifacts(options)` | Write HTML, CSV, and JSON artifacts together |
111
+
112
+ ### Research
113
+
114
+ ```js
115
+ import { research } from "tradelab";
116
+ ```
36
117
 
37
- | Export | Summary |
38
- | ---------------------------------- | ------------------------------------------ |
39
- | `renderHtmlReport(options)` | Return the HTML report as a string |
40
- | `exportHtmlReport(options)` | Write the HTML report to disk |
41
- | `exportTradesCsv(trades, options)` | Write a CSV ledger of trades or positions |
42
- | `exportMetricsJSON(options)` | Write machine-readable metrics JSON |
43
- | `exportBacktestArtifacts(options)` | Write HTML, CSV, and metrics JSON together |
118
+ | Export | Summary |
119
+ | ------------------------------------------------------------ | ---------------------------------------------------------- |
120
+ | `research.monteCarlo(options)` | Bootstrap trade PnLs into alternate equity paths |
121
+ | `research.deflatedSharpe(options)` | Penalize Sharpe for sample size, non-normality, and trials |
122
+ | `research.sweepHaircut(options)` | Estimate the Sharpe hurdle from many trials |
123
+ | `research.probabilityOfBacktestOverfitting(matrix, options)` | Estimate PBO from a performance matrix |
124
+ | `research.combinatorialPurgedSplits(options)` | Build purged train/test splits |
125
+ | `research.combinations(n, k)` | Generate combinations |
126
+ | `research.normalCdf(x)` | Standard normal CDF |
127
+ | `research.normalPpf(p)` | Standard normal inverse CDF |
128
+ | `research.moments(values)` | Mean, standard deviation, skew, kurtosis |
129
+
130
+ ### Indicators And Helpers
131
+
132
+ | Export | Summary |
133
+ | ------------------------------------- | -------------------------------------------- |
134
+ | `ema(values, period)` | Exponential moving average |
135
+ | `atr(bars, period)` | Average True Range |
136
+ | `swingHigh(bars, index, left, right)` | Detect a swing high at an index |
137
+ | `swingLow(bars, index, left, right)` | Detect a swing low at an index |
138
+ | `detectFVG(bars, index)` | Detect a Fair Value Gap |
139
+ | `lastSwing(bars, index, direction)` | Find the last swing in a direction |
140
+ | `structureState(bars, index)` | Return latest swing high/low state |
141
+ | `bpsOf(price, bps)` | Convert basis points to price distance |
142
+ | `pct(a, b)` | Percent difference helper |
143
+ | `calculatePositionSize(input)` | Risk-based quantity calculation |
144
+ | `offsetET(timeMs)` | Eastern Time offset helper |
145
+ | `minutesET(timeMs)` | Minutes since midnight Eastern Time |
146
+ | `isSession(timeMs, session)` | Check known trading sessions |
147
+ | `parseWindowsCSV(csv)` | Parse windows like `09:30-11:30,13:00-15:30` |
148
+ | `inWindowsET(timeMs, windows)` | Check whether a timestamp is inside windows |
149
+
150
+ ## Data Module: `tradelab/data`
44
151
 
45
- ## Live module (`tradelab/live`)
152
+ ```js
153
+ import { getHistoricalCandles, loadCandlesFromCSV } from "tradelab/data";
154
+ ```
155
+
156
+ This entry point exports the data helpers from the main module:
46
157
 
47
- Live exports are under a separate entrypoint:
158
+ - `getHistoricalCandles`
159
+ - `backtestHistorical`
160
+ - `fetchHistorical`
161
+ - `fetchLatestCandle`
162
+ - `loadCandlesFromCSV`
163
+ - `normalizeCandles`
164
+ - `mergeCandles`
165
+ - `candleStats`
166
+ - `saveCandlesToCache`
167
+ - `loadCandlesFromCache`
168
+ - `cachedCandlesPath`
169
+
170
+ ## Live Module: `tradelab/live`
48
171
 
49
172
  ```js
50
- import { LiveEngine, PaperEngine } from "tradelab/live";
173
+ import { LiveEngine, PaperEngine, createDashboardServer } from "tradelab/live";
51
174
  ```
52
175
 
53
- ### Engine and orchestration
54
-
55
- - `LiveEngine`
56
- - `LiveOrchestrator`
57
- - `PaperEngine`
58
- - `CandleAggregator`
59
- - `RiskManager`
60
- - `StateManager`
61
-
62
- ### Broker and feed adapters
63
-
64
- - `BrokerAdapter`
65
- - `AlpacaBroker`
66
- - `BinanceBroker`
67
- - `CoinbaseBroker`
68
- - `InteractiveBrokersBroker`
69
- - `FeedProvider`
70
- - `BrokerFeed`
71
- - `PollingFeed`
72
-
73
- ### Storage and runtime utilities
74
-
75
- - `StorageProvider`
76
- - `JsonFileStorage`
77
- - `EventBus`
78
- - `LiveLogger`
79
- - `BrokerClock`
80
-
81
- ### Factories
82
-
83
- - `createLiveEngine(options)`
84
- - `createLiveOrchestrator(options)`
85
- - `createPaperEngine(options)`
86
- - `createAlpacaBroker(options)`
87
- - `createBinanceBroker(options)`
88
- - `createCoinbaseBroker(options)`
89
- - `createInteractiveBrokersBroker(options)`
90
- - `createBrokerFeed(options)`
91
- - `createPollingFeed(options)`
92
- - `createJsonFileStorage(options)`
93
- - `createCandleAggregator(options)`
94
- - `createRiskManager(options)`
95
- - `createStateManager(options)`
96
- - `createEventBus()`
97
- - `createLogger(options)`
98
- - `createClock(options)`
99
-
100
- ## Indicators and utilities
101
-
102
- ### Indicators
103
-
104
- - `ema(values, period)`
105
- - `atr(bars, period)`
106
- - `swingHigh(bars, index, left, right)`
107
- - `swingLow(bars, index, left, right)`
108
- - `detectFVG(bars, index)`
109
- - `lastSwing(bars, index, direction)`
110
- - `structureState(bars, index)`
111
- - `bpsOf(price, bps)`
112
- - `pct(a, b)`
113
-
114
- ### Position sizing
115
-
116
- - `calculatePositionSize(input)`
117
-
118
- ### Time helpers
119
-
120
- - `offsetET(timeMs)`
121
- - `minutesET(timeMs)`
122
- - `isSession(timeMs, session)`
123
- - `parseWindowsCSV(csv)`
124
- - `inWindowsET(timeMs, windows)`
125
-
126
- ## Technical analysis (`tradelab/ta`)
127
-
128
- TA exports are under a separate entrypoint:
176
+ ### Engines
177
+
178
+ | Export | Summary |
179
+ | --------------------------------- | -------------------------------------------- |
180
+ | `LiveEngine` | Single-system live or paper execution engine |
181
+ | `createLiveEngine(options)` | Factory for `LiveEngine` |
182
+ | `LiveOrchestrator` | Multi-system engine sharing one broker |
183
+ | `createLiveOrchestrator(options)` | Factory for `LiveOrchestrator` |
184
+ | `PaperEngine` | In-process broker simulator |
185
+ | `createPaperEngine(options)` | Factory for `PaperEngine` |
186
+
187
+ ### Broker Adapters
188
+
189
+ | Export | Summary |
190
+ | ------------------------------------------------------------- | --------------------------------------- |
191
+ | `BrokerAdapter` | Base broker interface |
192
+ | `AlpacaBroker` / `createAlpacaBroker` | Alpaca adapter and factory |
193
+ | `BinanceBroker` / `createBinanceBroker` | Binance adapter and factory |
194
+ | `CoinbaseBroker` / `createCoinbaseBroker` | Coinbase adapter and factory |
195
+ | `InteractiveBrokersBroker` / `createInteractiveBrokersBroker` | Interactive Brokers adapter and factory |
196
+
197
+ ### Feeds
198
+
199
+ | Export | Summary |
200
+ | --------------------------------- | ------------------------------------------- |
201
+ | `FeedProvider` | Base feed interface |
202
+ | `BrokerFeed` | Feed backed by broker subscriptions |
203
+ | `createBrokerFeed(options)` | Factory for `BrokerFeed` |
204
+ | `PollingFeed` | Polling feed backed by broker history calls |
205
+ | `createPollingFeed(options)` | Factory for `PollingFeed` |
206
+ | `CandleAggregator` | Aggregate ticks/polled bars into candles |
207
+ | `createCandleAggregator(options)` | Factory for `CandleAggregator` |
208
+
209
+ ### State, Risk, Events
210
+
211
+ | Export | Summary |
212
+ | -------------------------------- | ------------------------------------------------- |
213
+ | `StorageProvider` | Base persistence interface |
214
+ | `JsonFileStorage` | JSON/JSONL file storage |
215
+ | `createJsonFileStorage(options)` | Factory for `JsonFileStorage` |
216
+ | `StateManager` | Load, save, append, and reconcile state |
217
+ | `createStateManager(options)` | Factory for `StateManager` |
218
+ | `RiskManager` | Daily loss, drawdown, session, and position gates |
219
+ | `createRiskManager(options)` | Factory for `RiskManager` |
220
+ | `EventBus` | Event emitter with `emitEvent()` and `onAny()` |
221
+ | `LIVE_EVENTS` | Named live event constants |
222
+ | `createEventBus()` | Factory for `EventBus` |
223
+ | `LiveLogger` | Structured event logger |
224
+ | `createLogger(options)` | Factory for `LiveLogger` |
225
+ | `BrokerClock` | Broker/local clock offset helper |
226
+ | `createClock(options)` | Factory for `BrokerClock` |
227
+
228
+ ### Dashboard
229
+
230
+ | Export | Summary |
231
+ | -------------------------------- | ------------------------------------------------------ |
232
+ | `createDashboardServer(options)` | Local HTTP dashboard for an engine/orchestrator source |
233
+
234
+ The dashboard source must expose `eventBus` and may expose `getStatus()`.
235
+
236
+ ## Technical Analysis Module: `tradelab/ta`
129
237
 
130
238
  ```js
131
239
  import { rsi, macd, bollinger, vwap, supertrend } from "tradelab/ta";
132
240
  ```
133
241
 
134
- Every indicator returns a **full-length array aligned to the input** warmup positions are `undefined` so values index 1:1 with candles. Oscillators accept a `number[]` of closes; range-based indicators accept `{ high, low, close }` candle arrays.
242
+ TA functions return arrays aligned to the input. Warmup positions are `undefined` where a value cannot be computed yet.
243
+
244
+ ### Re-exported Core Indicators
245
+
246
+ | Export | Input | Returns |
247
+ | --------------------------------------- | ---------- | -------------------------- |
248
+ | `ema(values, period?)` | `number[]` | `number[]` |
249
+ | `atr(bars, period?)` | candles | `(number \| undefined)[]` |
250
+ | `swingHigh(bars, index, left?, right?)` | candles | `boolean` |
251
+ | `swingLow(bars, index, left?, right?)` | candles | `boolean` |
252
+ | `detectFVG(bars, index)` | candles | gap object or `null` |
253
+ | `lastSwing(bars, index, direction)` | candles | `{ idx, price }` or `null` |
254
+ | `structureState(bars, index)` | candles | latest swing state |
135
255
 
136
256
  ### Oscillators
137
257
 
138
- | Export | Input | Returns | Description |
139
- | ------------------------------------------- | ------------ | ----------------------------- | -------------------------------------------------------- |
140
- | `rsi(closes, period?)` | `number[]` | `(number \| undefined)[]` | Wilder's RSI; warmup positions are `undefined` |
141
- | `macd(closes, fast?, slow?, signalPeriod?)` | `number[]` | `{ macd, signal, histogram }` | MACD line, signal line, and histogram; all full-length |
142
- | `stochastic(bars, kPeriod?, dPeriod?)` | candle array | `{ k, d }` | Stochastic %K and %D; `k` and `d` are full-length arrays |
258
+ | Export | Input | Returns |
259
+ | ------------------------------------------- | ---------- | ----------------------------- |
260
+ | `rsi(closes, period?)` | `number[]` | `(number \| undefined)[]` |
261
+ | `macd(closes, fast?, slow?, signalPeriod?)` | `number[]` | `{ macd, signal, histogram }` |
262
+ | `stochastic(bars, kPeriod?, dPeriod?)` | candles | `{ k, d }` |
263
+
264
+ ### Bands And Channels
265
+
266
+ | Export | Input | Returns |
267
+ | ---------------------------------------------- | ---------- | -------------------------- |
268
+ | `bollinger(closes, period?, mult?)` | `number[]` | `{ middle, upper, lower }` |
269
+ | `donchian(bars, period?)` | candles | `{ upper, lower, middle }` |
270
+ | `keltner(bars, emaPeriod?, atrPeriod?, mult?)` | candles | `{ upper, lower, middle }` |
143
271
 
144
- ### Bands & channels
272
+ ### Trend And Volume
145
273
 
146
- | Export | Input | Returns | Description |
147
- | ---------------------------------------------- | ------------ | -------------------------- | ------------------------------------------------------------- |
148
- | `bollinger(closes, period?, mult?)` | `number[]` | `{ middle, upper, lower }` | Bollinger Bands with SMA middle and stddev-scaled outer bands |
149
- | `donchian(bars, period?)` | candle array | `{ upper, lower, middle }` | Donchian channel: rolling highest-high / lowest-low |
150
- | `keltner(bars, emaPeriod?, atrPeriod?, mult?)` | candle array | `{ upper, lower, middle }` | Keltner channel: EMA middle with ATR-scaled width |
274
+ | Export | Input | Returns |
275
+ | ---------------------------------- | ------- | ------------------------- |
276
+ | `supertrend(bars, period?, mult?)` | candles | `{ line, direction }` |
277
+ | `vwap(bars)` | candles | `(number \| undefined)[]` |
151
278
 
152
- ### Trend & volume
279
+ ## MCP Module: `tradelab/mcp`
153
280
 
154
- | Export | Input | Returns | Description |
155
- | ---------------------------------- | ------------------------------------- | ------------------------- | -------------------------------------------------------------------------- |
156
- | `supertrend(bars, period?, mult?)` | candle array | `{ line, direction }` | Supertrend support/resistance line; `direction` is `1` (up) or `-1` (down) |
157
- | `vwap(bars)` | candle array with `time` and `volume` | `(number \| undefined)[]` | Session VWAP, resets on each UTC calendar day |
281
+ ```js
282
+ import { createServer, startStdioServer } from "tradelab/mcp";
283
+ ```
158
284
 
159
- ### Re-exported from main module
285
+ | Export | Summary |
286
+ | -------------------- | --------------------------------------- |
287
+ | `createServer()` | Build an MCP server with tradelab tools |
288
+ | `startStdioServer()` | Start the MCP server on stdio |
160
289
 
161
- | Export | Description |
162
- | --------------------------------------- | ---------------------------------- |
163
- | `ema(values, period?)` | Exponential moving average |
164
- | `atr(bars, period?)` | Average True Range |
165
- | `swingHigh(bars, index, left?, right?)` | Detect swing high at index |
166
- | `swingLow(bars, index, left?, right?)` | Detect swing low at index |
167
- | `detectFVG(bars, index)` | Detect Fair Value Gap at index |
168
- | `lastSwing(bars, index, direction)` | Find the last swing in a direction |
169
- | `structureState(bars, index)` | Assess market structure state |
290
+ See [mcp.md](mcp.md) for client configuration and tool payload examples.
170
291
 
171
292
  ## Types
172
293
 
173
- The package ships declarations in:
294
+ The package ships TypeScript declarations:
174
295
 
175
- - [../types/index.d.ts](../types/index.d.ts) for the main module
176
- - [../types/live.d.ts](../types/live.d.ts) for `tradelab/live`
177
- - [../types/ta.d.ts](../types/ta.d.ts) for `tradelab/ta`
296
+ | File | Covers |
297
+ | ------------------ | --------------- |
298
+ | `types/index.d.ts` | `tradelab` |
299
+ | `types/data.d.ts` | `tradelab/data` |
300
+ | `types/live.d.ts` | `tradelab/live` |
301
+ | `types/ta.d.ts` | `tradelab/ta` |
302
+ | `types/mcp.d.ts` | `tradelab/mcp` |
178
303
 
179
- <small>[Back to main page](README.md)</small>
304
+ <small>[Back to docs](README.md)</small>