@tradecanvas/chart 0.5.0 → 0.6.0

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 (46) hide show
  1. package/README.md +109 -6
  2. package/dist/Chart-CrrTKx3r.js +1027 -0
  3. package/dist/Chart-CrrTKx3r.js.map +1 -0
  4. package/dist/Chart-DoR8L8Uk.cjs +2 -0
  5. package/dist/Chart-DoR8L8Uk.cjs.map +1 -0
  6. package/dist/Chart.d.ts +1 -4
  7. package/dist/Chart.d.ts.map +1 -1
  8. package/dist/charts/ChartTypeStrategy.d.ts +18 -0
  9. package/dist/charts/ChartTypeStrategy.d.ts.map +1 -0
  10. package/dist/charts/IndicatorPriceRange.d.ts +16 -0
  11. package/dist/charts/IndicatorPriceRange.d.ts.map +1 -0
  12. package/dist/index.cjs +1 -1
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +31 -1024
  17. package/dist/index.js.map +1 -1
  18. package/dist/state/AutoSaveScheduler.d.ts +26 -0
  19. package/dist/state/AutoSaveScheduler.d.ts.map +1 -0
  20. package/dist/widget/ChartWidget.d.ts +43 -0
  21. package/dist/widget/ChartWidget.d.ts.map +1 -0
  22. package/dist/widget/WidgetDrawingSidebar.d.ts +19 -0
  23. package/dist/widget/WidgetDrawingSidebar.d.ts.map +1 -0
  24. package/dist/widget/WidgetDropdown.d.ts +18 -0
  25. package/dist/widget/WidgetDropdown.d.ts.map +1 -0
  26. package/dist/widget/WidgetSettings.d.ts +25 -0
  27. package/dist/widget/WidgetSettings.d.ts.map +1 -0
  28. package/dist/widget/WidgetStatusBar.d.ts +15 -0
  29. package/dist/widget/WidgetStatusBar.d.ts.map +1 -0
  30. package/dist/widget/WidgetStyles.d.ts +9 -0
  31. package/dist/widget/WidgetStyles.d.ts.map +1 -0
  32. package/dist/widget/WidgetToolbar.d.ts +22 -0
  33. package/dist/widget/WidgetToolbar.d.ts.map +1 -0
  34. package/dist/widget/icons.d.ts +2 -0
  35. package/dist/widget/icons.d.ts.map +1 -0
  36. package/dist/widget/index.cjs +740 -0
  37. package/dist/widget/index.cjs.map +1 -0
  38. package/dist/widget/index.d.ts +3 -0
  39. package/dist/widget/index.d.ts.map +1 -0
  40. package/dist/widget/index.js +1058 -0
  41. package/dist/widget/index.js.map +1 -0
  42. package/dist/widget/types.d.ts +105 -0
  43. package/dist/widget/types.d.ts.map +1 -0
  44. package/dist/widget/widgetConfig.d.ts +16 -0
  45. package/dist/widget/widgetConfig.d.ts.map +1 -0
  46. package/package.json +14 -4
package/README.md CHANGED
@@ -8,7 +8,7 @@ High-performance canvas trading chart with built-in indicators, drawing tools, a
8
8
 
9
9
  Most chart libraries make you choose: pretty charts with no trading features, or trading features with an ugly API. TradeCanvas gives you both.
10
10
 
11
- - **20+ built-in indicators** — MA, EMA, RSI, MACD, Bollinger, Ichimoku, and more. No separate calculation library needed.
11
+ - **33+ built-in indicators** — MA, EMA, Hull MA, RSI, MACD, Bollinger, Ichimoku, Pivot Points, Anchored VWAP, ZigZag, Linear Regression Channel, Awesome / Chaikin Oscillator, and more. No separate calculation library needed.
12
12
  - **10+ drawing tools** — Trendlines, Fibonacci retracement, horizontal/vertical lines, rectangles, channels, Elliott waves, Gann fans. With undo/redo.
13
13
  - **Trading overlay** — Render open positions with entry line, P&L zone, and SL/TP markers. Orders as dashed lines. Users can drag SL/TP to modify.
14
14
  - **Real-time streaming** — Built-in Binance adapter. Plug in your own data source with the adapter interface.
@@ -55,6 +55,55 @@ chart.connect({
55
55
 
56
56
  That's it. A full-featured trading chart with live data in 15 lines.
57
57
 
58
+ ## Widget (Complete UI)
59
+
60
+ For a complete TradingView-like experience with built-in toolbar, drawing tools, and settings — no UI code needed:
61
+
62
+ ```typescript
63
+ import { ChartWidget } from '@tradecanvas/chart/widget'
64
+ import { BinanceAdapter } from '@tradecanvas/chart'
65
+
66
+ const widget = new ChartWidget(document.getElementById('chart')!, {
67
+ symbol: 'BTCUSDT',
68
+ timeframe: '5m',
69
+ adapter: new BinanceAdapter(),
70
+ theme: 'dark',
71
+ })
72
+ ```
73
+
74
+ That's it. Full toolbar, drawing sidebar, settings modal, and status bar — all included.
75
+
76
+ ### Widget Options
77
+
78
+ | Option | Type | Default | Description |
79
+ |---|---|---|---|
80
+ | `symbol` | `string` | `'BTCUSDT'` | Initial trading symbol |
81
+ | `timeframe` | `TimeFrame` | `'5m'` | Initial timeframe |
82
+ | `theme` | `'dark' \| 'light' \| Theme` | `'dark'` | Chart theme |
83
+ | `adapter` | `DataAdapter` | — | Data source adapter |
84
+ | `toolbar` | `boolean` | `true` | Show top toolbar |
85
+ | `drawingTools` | `boolean` | `true` | Show left drawing sidebar |
86
+ | `settings` | `boolean` | `true` | Show settings button |
87
+ | `trading` | `boolean` | `true` | Enable trading overlay |
88
+ | `statusBar` | `boolean` | `true` | Show bottom status bar |
89
+ | `symbols` | `string[]` | BTC/ETH/SOL/BNB | Available symbols |
90
+ | `timeframes` | `TimeFrame[]` | 1m to 1d | Available timeframes |
91
+ | `chartTypes` | `ChartType[]` | 7 types | Available chart types |
92
+ | `onSymbolChange` | `(symbol) => void` | — | Symbol change callback |
93
+ | `onTimeframeChange` | `(tf) => void` | — | Timeframe change callback |
94
+ | `onReady` | `(chart) => void` | — | Fired when chart is ready |
95
+
96
+ ### Widget vs Headless
97
+
98
+ | | `Chart` (headless) | `ChartWidget` |
99
+ |---|---|---|
100
+ | Import | `@tradecanvas/chart` | `@tradecanvas/chart/widget` |
101
+ | UI included | None — build your own | Complete toolbar, sidebar, settings |
102
+ | Bundle impact | ~50 KB gzip | ~65 KB gzip (includes UI) |
103
+ | Framework | Any (React, Vue, Svelte, vanilla) | Vanilla JS DOM (works everywhere) |
104
+ | Customization | Full control | Toggle sections on/off |
105
+ | Advanced access | Direct API | `widget.getChart()` for direct API |
106
+
58
107
  ## Features
59
108
 
60
109
  ### Chart Types
@@ -72,6 +121,7 @@ That's it. A full-featured trading chart with live data in 15 lines.
72
121
  | Kagi | Reversal-based line chart |
73
122
  | Point & Figure | X/O columns for supply/demand analysis |
74
123
  | Line Break | Three-line break charts |
124
+ | Range Bars | Fixed price-range bars — each bar's high − low equals a configured range |
75
125
 
76
126
  ### Finance Charts
77
127
 
@@ -126,10 +176,12 @@ gauge.setValue(85) // animates smoothly
126
176
  ### Indicators (built-in)
127
177
 
128
178
  **Overlay** (drawn on the price chart):
129
- SMA, EMA, Bollinger Bands, Keltner Channel, Donchian Channel, Ichimoku Cloud, Parabolic SAR, Supertrend, VWAP
179
+ SMA, EMA, Hull MA, Bollinger Bands, Keltner Channel, Donchian Channel, Ichimoku Cloud, Parabolic SAR, Supertrend, VWAP, Anchored VWAP, Pivot Points (Classic), ZigZag, Linear Regression Channel
130
180
 
131
181
  **Panel** (separate sub-chart):
132
- RSI, MACD, Stochastic, ATR, ADX, CCI, CMF, MFI, OBV, ROC, TSI, Williams %R, Volume Profile, VROC, Standard Deviation, Accumulation/Distribution, Aroon
182
+ RSI, MACD, Stochastic, ATR, ADX, CCI, CMF, MFI, OBV, ROC, TSI, Williams %R, Awesome Oscillator, Chaikin Oscillator, Volume Profile, VROC, Standard Deviation, Accumulation/Distribution, Aroon
183
+
184
+ All indicator parameters are validated at runtime — invalid values (NaN, Infinity, non-numeric strings, missing keys) fall back to documented defaults instead of silently propagating to calculations.
133
185
 
134
186
  ### Drawing Tools
135
187
 
@@ -153,6 +205,7 @@ chart.setPositions([{
153
205
  side: 'buy',
154
206
  entryPrice: 3500,
155
207
  quantity: 1.5,
208
+ closedQuantity: 0.5, // partial close — visualized as a left-edge dim band
156
209
  stopLoss: 3400,
157
210
  takeProfit: 3700,
158
211
  }])
@@ -167,6 +220,18 @@ chart.setOrders([{
167
220
  draggable: true,
168
221
  }])
169
222
 
223
+ // Customize the position zone color via P&L thresholds
224
+ chart.setTradingConfig({
225
+ pnlThresholds: [
226
+ { pnl: -Infinity, color: '#b91c1c' },
227
+ { pnl: 0, color: '#94a3b8' },
228
+ { pnl: 50, color: '#16a34a' },
229
+ { pnl: 200, color: '#15803d' },
230
+ ],
231
+ // Custom label template — tokens: {side} {qty} {openQty} {closedQty} {entry} {price} {pnl} {pnlPct} {pnlSign}
232
+ positionLabel: '{side} {openQty}/{qty} @ {entry} | {pnlSign}{pnl} ({pnlPct})',
233
+ })
234
+
170
235
  // Listen for user drag-to-modify
171
236
  chart.on('positionModify', (e) => console.log('SL/TP moved:', e.payload))
172
237
  chart.on('orderModify', (e) => console.log('Order moved:', e.payload))
@@ -190,6 +255,43 @@ chart.updateLastBar(updatedBar)
190
255
  chart.setCurrentPrice(3500.42)
191
256
  ```
192
257
 
258
+ ### Web Worker indicator pipeline
259
+
260
+ Heavy charts (1,000+ bars × 10+ indicators) can stutter when `calculate()` runs on the main thread. `IndicatorWorkerHost` offloads calculation to a worker so the render loop stays smooth.
261
+
262
+ ```typescript
263
+ import { IndicatorWorkerHost } from '@tradecanvas/core'
264
+
265
+ // Bundler-supported worker URL (Vite, webpack 5, esbuild, etc.)
266
+ const worker = new Worker(
267
+ new URL('@tradecanvas/core/dist/indicator.worker.js', import.meta.url),
268
+ { type: 'module' },
269
+ )
270
+ const host = new IndicatorWorkerHost(worker, { timeoutMs: 30_000 })
271
+
272
+ const output = await host.calculate(
273
+ 'rsi',
274
+ { id: 'rsi', instanceId: 'rsi-1', params: { period: 14 } },
275
+ bars,
276
+ )
277
+
278
+ // Health check / cleanup
279
+ await host.ping()
280
+ host.terminate()
281
+ ```
282
+
283
+ No worker available (SSR, tests, or as a safety net)? Pass `null` and register fallback plugins for synchronous calculation:
284
+
285
+ ```typescript
286
+ import { IndicatorWorkerHost, RSIIndicator } from '@tradecanvas/core'
287
+
288
+ const host = new IndicatorWorkerHost(null)
289
+ host.registerFallbackPlugin(new RSIIndicator())
290
+ const output = await host.calculate('rsi', config, bars) // runs synchronously
291
+ ```
292
+
293
+ Render still happens on the main thread (it needs `CanvasRenderingContext2D`). Only the heavy compute moves off-thread.
294
+
193
295
  ### Save / Load
194
296
 
195
297
  ```typescript
@@ -245,9 +347,9 @@ const { current, total, percent } = chart.getReplayProgress()
245
347
 
246
348
  | Feature | @tradecanvas/chart | lightweight-charts | chart.js | Highcharts Stock |
247
349
  |---|---|---|---|---|
248
- | Chart types | 11 + 4 finance | 4 | 8 (non-financial) | 10+ |
249
- | Finance charts | Sparkline, Depth, Equity, Heatmap | None | None | Some |
250
- | Built-in indicators | 20+ | 0 | 0 | ~30 |
350
+ | Chart types | 12 + 6 finance | 4 | 8 (non-financial) | 10+ |
351
+ | Finance charts | Sparkline, Depth, Equity, Heatmap, Waterfall, Gauge | None | None | Some |
352
+ | Built-in indicators | 33+ | 0 | 0 | ~30 |
251
353
  | Drawing tools | 23 | 0 | 0 | Some |
252
354
  | Trading overlay | Full (pos + orders + drag) | None | None | None |
253
355
  | Real-time streaming | Built-in (Binance) | Manual | Manual | Built-in |
@@ -256,6 +358,7 @@ const { current, total, percent } = chart.getReplayProgress()
256
358
  | Multi-panel | Yes | No | No | Yes |
257
359
  | Bundle (gzip) | ~50 KB | ~45 KB | ~70 KB | ~200 KB |
258
360
  | Dependencies | 0 | 1 | 0 | 0 |
361
+ | Widget (complete UI) | Yes (`ChartWidget`) | No | No | No |
259
362
  | License | MIT | Apache 2.0 | MIT | Commercial |
260
363
 
261
364
  ## API Overview