binbot-charts 0.2.18 → 0.2.19
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/dist/components/streaming.js +53 -47
- package/package.json +1 -1
|
@@ -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