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, setSymbolState] = (0, _react.useState)(null);
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.bodyText == order.text) {
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
- const 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);
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
- socket.onopen = event => {
12
- console.log("[socket] Connected", event);
13
- };
10
+ function setupSockets(subRequest) {
11
+ const socket = new WebSocket("wss://stream.binance.com:9443/ws");
12
+ window.socket = socket;
14
13
 
15
- socket.onclose = reason => {
16
- console.log("[socket] Disconnected:", reason);
17
- };
14
+ socket.onopen = event => {
15
+ console.log("[socket] Connected");
16
+ socket.send(JSON.stringify(subRequest));
17
+ };
18
18
 
19
- socket.onerror = error => {
20
- console.log("[socket] Error:", error);
21
- };
19
+ socket.onclose = reason => {
20
+ console.log("[socket] Disconnected:", reason);
21
+ };
22
22
 
23
- socket.onmessage = e => {
24
- const data = JSON.parse(e.data);
23
+ socket.onerror = error => {
24
+ console.log("[socket] Error:", error);
25
+ };
25
26
 
26
- if (data.e == undefined) {
27
- // skip all non-TRADE events
28
- return;
29
- }
27
+ socket.onmessage = e => {
28
+ const data = JSON.parse(e.data);
30
29
 
31
- const {
32
- s: symbol,
33
- t: startTime,
34
- T: closeTime,
35
- i: interval,
36
- o: open,
37
- c: close,
38
- h: high,
39
- l: low,
40
- v: volume,
41
- n: trades,
42
- q: quoteVolume
43
- } = data.k;
44
- const channelString = `${symbol.toLowerCase()}@kline_${interval}`;
45
- const subscriptionItem = channelToSubscription.get(channelString);
46
-
47
- if (subscriptionItem === undefined) {
48
- return;
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
- const bar = {
52
- time: startTime,
53
- open: open,
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
- subscriptionItem.handlers.forEach(handler => handler.callback(bar));
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
- socket.send(JSON.stringify(subRequest));
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.18",
2
+ "version": "0.2.21",
3
3
  "name": "binbot-charts",
4
4
  "dependencies": {
5
5
  "react": "^17.0.1",