@iccandle/widget-web-trading 0.0.1 → 0.0.3
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 +46 -6
- package/dist/web-trading-widget.cjs +23 -28
- package/dist/web-trading-widget.css +1 -1
- package/dist/web-trading-widget.d.ts +14 -18
- package/dist/web-trading-widget.js +6414 -6066
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,20 +46,60 @@ function TradingPage() {
|
|
|
46
46
|
| `chartWidget` | `object \| null` | no | Host-owned TradingView widget instance (embed mode) |
|
|
47
47
|
| `scanResultUrl` | `string \| null` | no | Opens the side panel Scan Result tab with this URL |
|
|
48
48
|
| `onScanResultUrlChange` | `(url: string \| null) => void` | no | Called when scan result URL changes |
|
|
49
|
+
| `onScanResultLoad` | `() => void` | no | Called when the scan result iframe finishes loading |
|
|
49
50
|
| `children` | `ReactNode` | no | Custom chart slot content (see embed mode below) |
|
|
50
51
|
|
|
51
52
|
### Embed mode (host-owned chart)
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
When your app already owns the TradingView widget instance, pass it via `chartWidget` and render your chart mount point as `children`. The widget will wire up order lines, symbol sync, and trading panels around your chart instead of creating its own.
|
|
54
55
|
|
|
55
56
|
```tsx
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
import { useEffect, useRef, useState } from "react";
|
|
58
|
+
import { WebTradingWidget } from "@iccandle/widget-web-trading";
|
|
59
|
+
import "@iccandle/widget-web-trading/style.css";
|
|
60
|
+
|
|
61
|
+
function TradingPageWithHostChart() {
|
|
62
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
63
|
+
const [chartWidget, setChartWidget] = useState<object | null>(null);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const container = containerRef.current;
|
|
67
|
+
if (!container || !window.TradingView) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const widget = new window.TradingView.widget({
|
|
72
|
+
container,
|
|
73
|
+
library_path: "/charting_library/",
|
|
74
|
+
// datafeed, symbol, interval, etc.
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
widget.onChartReady(() => {
|
|
78
|
+
setChartWidget(widget);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return () => {
|
|
82
|
+
setChartWidget(null);
|
|
83
|
+
widget.remove();
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div style={{ height: "100vh", width: "100%" }}>
|
|
89
|
+
<WebTradingWidget
|
|
90
|
+
baseUrl="https://your-api.example.com"
|
|
91
|
+
token={token}
|
|
92
|
+
chartWidget={chartWidget}
|
|
93
|
+
>
|
|
94
|
+
<div ref={containerRef} style={{ height: "100%", width: "100%" }} />
|
|
95
|
+
</WebTradingWidget>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
61
99
|
```
|
|
62
100
|
|
|
101
|
+
`chartWidget` must be the TradingView Charting Library widget instance from your host app. Pass `children` with the DOM element the chart is mounted into — omitting `children` leaves the chart slot empty.
|
|
102
|
+
|
|
63
103
|
### `ChartNewsOrdersOverlay`
|
|
64
104
|
|
|
65
105
|
A lighter overlay for news-style layouts:
|