@iccandle/widget-web-trading 0.0.1 → 0.0.2

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 CHANGED
@@ -50,16 +50,55 @@ function TradingPage() {
50
50
 
51
51
  ### Embed mode (host-owned chart)
52
52
 
53
- Pass an existing TradingView `chartWidget` to render trading panels around your chart instead of the built-in chart:
53
+ 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
54
 
55
55
  ```tsx
56
- <WebTradingWidget
57
- baseUrl="https://your-api.example.com"
58
- token={token}
59
- chartWidget={existingTvWidget}
60
- />
56
+ import { useEffect, useRef, useState } from "react";
57
+ import { WebTradingWidget } from "@iccandle/widget-web-trading";
58
+ import "@iccandle/widget-web-trading/style.css";
59
+
60
+ function TradingPageWithHostChart() {
61
+ const containerRef = useRef<HTMLDivElement>(null);
62
+ const [chartWidget, setChartWidget] = useState<object | null>(null);
63
+
64
+ useEffect(() => {
65
+ const container = containerRef.current;
66
+ if (!container || !window.TradingView) {
67
+ return;
68
+ }
69
+
70
+ const widget = new window.TradingView.widget({
71
+ container,
72
+ library_path: "/charting_library/",
73
+ // datafeed, symbol, interval, etc.
74
+ });
75
+
76
+ widget.onChartReady(() => {
77
+ setChartWidget(widget);
78
+ });
79
+
80
+ return () => {
81
+ setChartWidget(null);
82
+ widget.remove();
83
+ };
84
+ }, []);
85
+
86
+ return (
87
+ <div style={{ height: "100vh", width: "100%" }}>
88
+ <WebTradingWidget
89
+ baseUrl="https://your-api.example.com"
90
+ token={token}
91
+ chartWidget={chartWidget}
92
+ >
93
+ <div ref={containerRef} style={{ height: "100%", width: "100%" }} />
94
+ </WebTradingWidget>
95
+ </div>
96
+ );
97
+ }
61
98
  ```
62
99
 
100
+ `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.
101
+
63
102
  ### `ChartNewsOrdersOverlay`
64
103
 
65
104
  A lighter overlay for news-style layouts: