binbot-charts 0.2.18 → 0.2.21
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.
|
@@ -35,7 +35,7 @@ function TVChartContainer(_ref) {
|
|
|
35
35
|
const containerRef = (0, _react.useRef)(null);
|
|
36
36
|
const [chartOrderLines, setChartOrderLines] = (0, _useImmer.useImmer)([]);
|
|
37
37
|
const [widgetState, setWidgetState] = (0, _react.useState)(null);
|
|
38
|
-
const [symbolState
|
|
38
|
+
const [symbolState] = (0, _react.useState)(null);
|
|
39
39
|
(0, _react.useEffect)(() => {
|
|
40
40
|
if (!widgetState) {
|
|
41
41
|
initializeChart();
|
|
@@ -89,7 +89,7 @@ function TVChartContainer(_ref) {
|
|
|
89
89
|
if (chartOrderLines && chartOrderLines.length > 0) {
|
|
90
90
|
chartOrderLines.forEach(item => {
|
|
91
91
|
orderLines.forEach(order => {
|
|
92
|
-
if (item._data.
|
|
92
|
+
if (item._data.id == order.id) {
|
|
93
93
|
item.setText(order.text).setTooltip(order.tooltip).setQuantity(order.quantity).setPrice(order.price);
|
|
94
94
|
}
|
|
95
95
|
});
|
|
@@ -98,7 +98,9 @@ function TVChartContainer(_ref) {
|
|
|
98
98
|
if (orderLines && orderLines.length > 0) {
|
|
99
99
|
orderLines.forEach(order => {
|
|
100
100
|
const lineStyle = order.lineStyle || 0;
|
|
101
|
-
|
|
101
|
+
let chartOrderLine = widgetState.chart().createOrderLine().setText(order.text).setTooltip(order.tooltip).setQuantity(order.quantity).setQuantityFont("inherit 14px Arial").setQuantityBackgroundColor(order.color).setQuantityBorderColor(order.color).setLineStyle(lineStyle).setLineLength(25).setLineColor(order.color).setBodyFont("inherit 14px Arial").setBodyBorderColor(order.color).setBodyTextColor(order.color).setPrice(order.price); // set custom id easier search
|
|
102
|
+
|
|
103
|
+
chartOrderLine.id = order.id;
|
|
102
104
|
setChartOrderLines(draft => {
|
|
103
105
|
draft.push(chartOrderLine);
|
|
104
106
|
return draft;
|
|
@@ -6,59 +6,64 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.subscribeOnStream = subscribeOnStream;
|
|
7
7
|
exports.unsubscribeFromStream = unsubscribeFromStream;
|
|
8
8
|
const channelToSubscription = new Map();
|
|
9
|
-
const socket = new WebSocket("wss://stream.binance.com:9443/ws");
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
function setupSockets(subRequest) {
|
|
11
|
+
const socket = new WebSocket("wss://stream.binance.com:9443/ws");
|
|
12
|
+
window.socket = socket;
|
|
14
13
|
|
|
15
|
-
socket.
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
socket.onopen = event => {
|
|
15
|
+
console.log("[socket] Connected");
|
|
16
|
+
socket.send(JSON.stringify(subRequest));
|
|
17
|
+
};
|
|
18
18
|
|
|
19
|
-
socket.
|
|
20
|
-
|
|
21
|
-
};
|
|
19
|
+
socket.onclose = reason => {
|
|
20
|
+
console.log("[socket] Disconnected:", reason);
|
|
21
|
+
};
|
|
22
22
|
|
|
23
|
-
socket.
|
|
24
|
-
|
|
23
|
+
socket.onerror = error => {
|
|
24
|
+
console.log("[socket] Error:", error);
|
|
25
|
+
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
27
|
+
socket.onmessage = e => {
|
|
28
|
+
const data = JSON.parse(e.data);
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
if (data.e == undefined) {
|
|
31
|
+
// skip all non-TRADE events
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
s: symbol,
|
|
37
|
+
t: startTime,
|
|
38
|
+
T: closeTime,
|
|
39
|
+
i: interval,
|
|
40
|
+
o: open,
|
|
41
|
+
c: close,
|
|
42
|
+
h: high,
|
|
43
|
+
l: low,
|
|
44
|
+
v: volume,
|
|
45
|
+
n: trades,
|
|
46
|
+
q: quoteVolume
|
|
47
|
+
} = data.k;
|
|
48
|
+
const channelString = `${symbol.toLowerCase()}@kline_${interval}`;
|
|
49
|
+
const subscriptionItem = channelToSubscription.get(channelString);
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
high: high,
|
|
55
|
-
low: low,
|
|
56
|
-
close: close,
|
|
57
|
-
volume: volume
|
|
58
|
-
}; // send data to every subscriber of that symbol
|
|
51
|
+
if (subscriptionItem === undefined) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
const bar = {
|
|
56
|
+
time: startTime,
|
|
57
|
+
open: open,
|
|
58
|
+
high: high,
|
|
59
|
+
low: low,
|
|
60
|
+
close: close,
|
|
61
|
+
volume: volume
|
|
62
|
+
}; // send data to every subscriber of that symbol
|
|
63
|
+
|
|
64
|
+
subscriptionItem.handlers.forEach(handler => handler.callback(bar));
|
|
65
|
+
};
|
|
66
|
+
}
|
|
62
67
|
|
|
63
68
|
function subscribeOnStream(symbolInfo, resolution, onRealtimeCallback, subscribeUID, onResetCacheNeededCallback, interval) {
|
|
64
69
|
const channelString = `${symbolInfo.name.toLowerCase()}@kline_${interval}`;
|
|
@@ -85,7 +90,7 @@ function subscribeOnStream(symbolInfo, resolution, onRealtimeCallback, subscribe
|
|
|
85
90
|
id: 1
|
|
86
91
|
};
|
|
87
92
|
channelToSubscription.set(channelString, subscriptionItem);
|
|
88
|
-
|
|
93
|
+
setupSockets(subRequest);
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
function unsubscribeFromStream(subscriberUID) {
|
|
@@ -106,8 +111,9 @@ function unsubscribeFromStream(subscriberUID) {
|
|
|
106
111
|
params: [channelString],
|
|
107
112
|
id: 1
|
|
108
113
|
};
|
|
109
|
-
socket.send(JSON.stringify(subRequest));
|
|
114
|
+
window.socket.send(JSON.stringify(subRequest));
|
|
110
115
|
channelToSubscription.delete(channelString);
|
|
116
|
+
window.socket = undefined;
|
|
111
117
|
break;
|
|
112
118
|
}
|
|
113
119
|
}
|
package/package.json
CHANGED