@tradecanvas/chart 0.4.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.
- package/README.md +120 -9
- package/dist/Chart-CrrTKx3r.js +1027 -0
- package/dist/Chart-CrrTKx3r.js.map +1 -0
- package/dist/Chart-DoR8L8Uk.cjs +2 -0
- package/dist/Chart-DoR8L8Uk.cjs.map +1 -0
- package/dist/Chart.d.ts +22 -8
- package/dist/Chart.d.ts.map +1 -1
- package/dist/charts/ChartTypeStrategy.d.ts +18 -0
- package/dist/charts/ChartTypeStrategy.d.ts.map +1 -0
- package/dist/charts/IndicatorPriceRange.d.ts +16 -0
- package/dist/charts/IndicatorPriceRange.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1010
- package/dist/index.js.map +1 -1
- package/dist/state/AutoSaveScheduler.d.ts +26 -0
- package/dist/state/AutoSaveScheduler.d.ts.map +1 -0
- package/dist/widget/ChartWidget.d.ts +43 -0
- package/dist/widget/ChartWidget.d.ts.map +1 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts +19 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts.map +1 -0
- package/dist/widget/WidgetDropdown.d.ts +18 -0
- package/dist/widget/WidgetDropdown.d.ts.map +1 -0
- package/dist/widget/WidgetSettings.d.ts +25 -0
- package/dist/widget/WidgetSettings.d.ts.map +1 -0
- package/dist/widget/WidgetStatusBar.d.ts +15 -0
- package/dist/widget/WidgetStatusBar.d.ts.map +1 -0
- package/dist/widget/WidgetStyles.d.ts +9 -0
- package/dist/widget/WidgetStyles.d.ts.map +1 -0
- package/dist/widget/WidgetToolbar.d.ts +22 -0
- package/dist/widget/WidgetToolbar.d.ts.map +1 -0
- package/dist/widget/icons.d.ts +2 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/widget/index.cjs +740 -0
- package/dist/widget/index.cjs.map +1 -0
- package/dist/widget/index.d.ts +3 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +1058 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/types.d.ts +105 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/dist/widget/widgetConfig.d.ts +16 -0
- package/dist/widget/widgetConfig.d.ts.map +1 -0
- 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
|
-
- **
|
|
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
|
|
@@ -206,8 +308,12 @@ await chart.loadStateFromFile()
|
|
|
206
308
|
### Themes
|
|
207
309
|
|
|
208
310
|
```typescript
|
|
209
|
-
import { DARK_THEME, LIGHT_THEME } from '@tradecanvas/chart'
|
|
311
|
+
import { DARK_THEME, LIGHT_THEME, DARK_TERMINAL } from '@tradecanvas/chart'
|
|
312
|
+
|
|
313
|
+
// Built-in presets: DARK_THEME, LIGHT_THEME, DARK_TERMINAL
|
|
314
|
+
chart.setTheme(DARK_TERMINAL) // fintech terminal: #0E0E0E bg, #00FF87/#FF3B4D candles, monospace
|
|
210
315
|
|
|
316
|
+
// Or customize any preset
|
|
211
317
|
chart.setTheme({
|
|
212
318
|
...DARK_THEME,
|
|
213
319
|
candleUp: '#26A69A',
|
|
@@ -241,9 +347,9 @@ const { current, total, percent } = chart.getReplayProgress()
|
|
|
241
347
|
|
|
242
348
|
| Feature | @tradecanvas/chart | lightweight-charts | chart.js | Highcharts Stock |
|
|
243
349
|
|---|---|---|---|---|
|
|
244
|
-
| Chart types |
|
|
245
|
-
| Finance charts | Sparkline, Depth, Equity, Heatmap | None | None | Some |
|
|
246
|
-
| Built-in indicators |
|
|
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 |
|
|
247
353
|
| Drawing tools | 23 | 0 | 0 | Some |
|
|
248
354
|
| Trading overlay | Full (pos + orders + drag) | None | None | None |
|
|
249
355
|
| Real-time streaming | Built-in (Binance) | Manual | Manual | Built-in |
|
|
@@ -252,6 +358,7 @@ const { current, total, percent } = chart.getReplayProgress()
|
|
|
252
358
|
| Multi-panel | Yes | No | No | Yes |
|
|
253
359
|
| Bundle (gzip) | ~50 KB | ~45 KB | ~70 KB | ~200 KB |
|
|
254
360
|
| Dependencies | 0 | 1 | 0 | 0 |
|
|
361
|
+
| Widget (complete UI) | Yes (`ChartWidget`) | No | No | No |
|
|
255
362
|
| License | MIT | Apache 2.0 | MIT | Commercial |
|
|
256
363
|
|
|
257
364
|
## API Overview
|
|
@@ -279,11 +386,15 @@ chart.setNumberLocale('de-DE') // 65.234,00
|
|
|
279
386
|
|---|---|
|
|
280
387
|
| `setData(bars)` | Load historical OHLCV data |
|
|
281
388
|
| `appendBar(bar)` | Append a new candle |
|
|
389
|
+
| `appendBars(bars)` | Bulk append (reconnect catch-up) |
|
|
282
390
|
| `updateLastBar(bar)` | Update the in-progress candle |
|
|
283
|
-
| `setCurrentPrice(price)` | Show a live price line |
|
|
391
|
+
| `setCurrentPrice(price, pulseColor?)` | Show a live price line |
|
|
284
392
|
| `connect(config)` | Connect to a real-time data source |
|
|
393
|
+
| `setTimeframe(tf)` | Switch timeframe on active stream |
|
|
285
394
|
| `setChartType(type)` | Switch chart type |
|
|
286
|
-
| `setTheme(theme)` | Apply a theme |
|
|
395
|
+
| `setTheme(theme)` | Apply a theme (DARK_THEME, LIGHT_THEME, DARK_TERMINAL) |
|
|
396
|
+
| `setNumberLocale(locale)` | Set number format locale (en-US, de-DE, vi-VN) |
|
|
397
|
+
| `setStatusText(text)` | Show status in legend area ("LIVE · 8ms") |
|
|
287
398
|
| `addIndicator(id, params?)` | Add a technical indicator |
|
|
288
399
|
| `removeIndicator(instanceId)` | Remove an indicator |
|
|
289
400
|
| `setDrawingTool(tool)` | Activate a drawing tool |
|