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/CHANGELOG.md CHANGED
@@ -5,6 +5,63 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.1] - 2026-06-27
9
+
10
+ ### Fixed
11
+
12
+ - `backtestPortfolio()` now reports aggregate `metrics.finalEquity` correctly when `collectEqSeries: false`.
13
+ - `PaperEngine` now rejects market orders that have no price reference instead of filling them at zero.
14
+ - `TradingSession` now clears staged brackets when an async entry is rejected or canceled, and staged brackets are matched by order id/client order id instead of a loose string check.
15
+ - MCP `attach_strategy` now evaluates built-in strategies with the normal backtest signal context and auto-places returned order intents from `feed_price`.
16
+ - `research.monteCarlo()` now rejects non-positive iteration counts instead of returning empty bands and `NaN` probability fields.
17
+ - Public live types now include `TradingSessionOptions.confirmLive` and optional dashboard `source.refresh()`.
18
+
19
+ ## [1.2.0] - 2026-06-26
20
+
21
+ ### Added
22
+
23
+ - **MCP agent trading (paper and live sessions)**
24
+ - New `TradingSession` class and `SessionManager` class exported from `tradelab/live`, enabling agents to manage real paper or live trading sessions programmatically.
25
+ - `SessionManager.create()` spins up a session backed by `PaperEngine` (default) or a credentialed live broker; `SessionManager.haltAll()` is the process-level kill-switch that flattens all positions and clears every session.
26
+ - `TradingSession.placeOrder()` supports risk-sized **bracket orders**: a single call with `stop` / `target` / `rr` fields submits the entry plus a protective stop and a profit target as OCO legs; a bar that straddles both stop and target no longer double-fills.
27
+ - Day-loss risk halts: `maxDailyLossPct` triggers an automatic halt via `RiskManager`; further `placeOrder()` calls throw until the session is stopped.
28
+ - Live-mode gating: live trading requires `TRADELAB_ALLOW_LIVE=true` (env var) **and** `confirmLive: true` passed to `create()`; paper is the default and needs no credentials or flags.
29
+
30
+ - **New MCP live-trading tools** (exposed via `tradelab-mcp`)
31
+ - `create_session` — create a paper or live session with equity, risk, and interval settings.
32
+ - `list_sessions` — list all active sessions and their current status.
33
+ - `session_status` — get a full refreshed snapshot (positions, open orders, equity, risk state).
34
+ - `feed_price` — push an OHLCV bar (or a single price) to advance paper simulation and trigger fills.
35
+ - `place_order` — place a market or limit order, optionally risk-sized with a bracket stop/target.
36
+ - `close_position` — close an open position via an opposite market order.
37
+ - `flatten` — flatten all positions and cancel all open orders in a session.
38
+ - `cancel_order` — cancel a specific open order.
39
+ - `account` — fetch broker account details (equity, cash, buying power).
40
+ - `positions` — list all open positions in a session.
41
+ - `recent_events` — retrieve recent session events (fills, risk changes, bars) for monitoring.
42
+ - `attach_strategy` — attach a named built-in strategy that auto-evaluates on each `feed_price` and places orders when flat.
43
+ - `halt_all` — emergency kill-switch: flattens all positions and stops every active session.
44
+
45
+ - **MCP research-plus tools** (exposed via `tradelab-mcp`)
46
+ - `analyze_robustness` — runs a backtest then Monte Carlo simulation and Deflated Sharpe ratio on the realized trade P&Ls; degrades gracefully with fewer than two trades.
47
+ - `optimize_strategy` — in-process grid sweep returning a leaderboard ranked by a chosen metric (default: `profitFactor`).
48
+ - `compare_strategies` — runs multiple named strategies on the same candle dataset and returns a ranked comparison.
49
+ - `candle_stats` — returns shape statistics (count, date range, price range, estimated interval) for a candle array or data spec; useful for sanity-checking data before backtesting.
50
+
51
+ - **Dashboard overhaul**
52
+ - Redesigned realtime cockpit with equity curve, KPI strip, positions/orders tables, severity-colored event feed, and a risk-halt banner.
53
+ - Live **Flatten / Stop / Cancel** controls in the dashboard UI via a new `POST /command` endpoint (whitelisted methods: `flatten`, `stop`, `closePosition`, `cancelOrder`).
54
+ - `GET /state` now calls `source.refresh()` before returning, so the state snapshot is always current.
55
+
56
+ ### Changed
57
+
58
+ - MCP server version is now read dynamically from `package.json` via `createRequire`; no separate version constant to update on release.
59
+
60
+ ### Fixed
61
+
62
+ - Paper-broker bracket orders: a price bar that straddled both the stop and the target could trigger a double-fill, flipping a position to the opposite side. The OCO cancel now runs before the sibling leg can fill.
63
+ - Dashboard equity curve color now reflects actual session P&L rather than a static value.
64
+
8
65
  ## [1.1.0] - 2026-06-26
9
66
 
10
67
  ### Added