binbot-charts 0.2.7 → 0.2.10
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.
|
@@ -38,7 +38,30 @@ function TVChartContainer(_ref) {
|
|
|
38
38
|
} = _ref;
|
|
39
39
|
const containerRef = (0, _react.useRef)(null);
|
|
40
40
|
const [chartOrderLines, setChartOrderLines] = (0, _useImmer.useImmer)([]);
|
|
41
|
+
const [widgetState, setWidgetState] = (0, _react.useState)(null);
|
|
41
42
|
(0, _react.useEffect)(() => {
|
|
43
|
+
if (!widgetState) {
|
|
44
|
+
initializeChart();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (orderLines && orderLines.length > 0) {
|
|
48
|
+
updateOrderLines(orderLines);
|
|
49
|
+
} // returned function will be called on component unmount
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
componentUnMount();
|
|
54
|
+
};
|
|
55
|
+
}, [orderLines]);
|
|
56
|
+
|
|
57
|
+
const componentUnMount = () => {
|
|
58
|
+
if (widgetState !== null) {
|
|
59
|
+
widgetState.remove();
|
|
60
|
+
setWidgetState(null);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const initializeChart = () => {
|
|
42
65
|
const widgetOptions = {
|
|
43
66
|
symbol: symbol,
|
|
44
67
|
datafeed: new _datafeed.default(timescaleMarks),
|
|
@@ -57,17 +80,8 @@ function TVChartContainer(_ref) {
|
|
|
57
80
|
};
|
|
58
81
|
const tvWidget = new _charting_library.widget(widgetOptions);
|
|
59
82
|
tvWidget.onChartReady(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const orderLine = updateOrderLines(tvWidget, order);
|
|
63
|
-
setChartOrderLines(draft => {
|
|
64
|
-
draft.push(orderLine);
|
|
65
|
-
return draft;
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
tvWidget.subscribe("onTick", event => onTick(event)); // get latest bar for last price
|
|
83
|
+
tvWidget.subscribe("onTick", event => onTick(event));
|
|
84
|
+
setWidgetState(tvWidget); // get latest bar for last price
|
|
71
85
|
|
|
72
86
|
const prices = async () => {
|
|
73
87
|
const data = await tvWidget.activeChart().exportData({
|
|
@@ -79,28 +93,34 @@ function TVChartContainer(_ref) {
|
|
|
79
93
|
};
|
|
80
94
|
|
|
81
95
|
prices();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return () => {
|
|
85
|
-
if (!tvWidget) {
|
|
86
|
-
tvWidget.remove();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}, [orderLines, timescaleMarks]);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
90
98
|
|
|
91
|
-
const updateOrderLines =
|
|
99
|
+
const updateOrderLines = orderLines => {
|
|
92
100
|
if (chartOrderLines && chartOrderLines.length > 0) {
|
|
93
101
|
chartOrderLines.forEach(item => {
|
|
94
|
-
|
|
102
|
+
orderLines.forEach(order => {
|
|
103
|
+
if (item._data.bodyText == order.text) {
|
|
104
|
+
item.setText(order.text).setTooltip(order.tooltip).setQuantity(order.quantity).setPrice(order.price);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
95
107
|
});
|
|
108
|
+
} else {
|
|
109
|
+
if (orderLines && orderLines.length > 0) {
|
|
110
|
+
orderLines.forEach(order => {
|
|
111
|
+
// const lineStyle = order.lineStyle || 0;
|
|
112
|
+
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)
|
|
113
|
+
.setLineLength(25).setLineColor(order.color).setBodyFont("inherit 14px Arial").setBodyBorderColor(order.color).setBodyTextColor(order.color).setPrice(order.price);
|
|
114
|
+
setChartOrderLines(draft => {
|
|
115
|
+
draft.push(chartOrderLine);
|
|
116
|
+
return draft;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
96
120
|
}
|
|
97
|
-
|
|
98
|
-
const lineStyle = order.lineStyle || 0;
|
|
99
|
-
const chartOrderLine = tvWidget.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);
|
|
100
|
-
return chartOrderLine;
|
|
101
121
|
};
|
|
102
122
|
|
|
103
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null,
|
|
123
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
104
124
|
ref: containerRef,
|
|
105
125
|
style: {
|
|
106
126
|
height: height
|
|
File without changes
|
|
@@ -49,32 +49,36 @@ class Datafeed {
|
|
|
49
49
|
onResultReadyCallback(symbols);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
_defineProperty(this, "resolveSymbol", (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) => {
|
|
52
|
+
_defineProperty(this, "resolveSymbol", async (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) => {
|
|
53
53
|
if (!symbolName) {
|
|
54
|
-
onResolveErrorCallback("cannot resolve symbol");
|
|
54
|
+
await onResolveErrorCallback("cannot resolve symbol");
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const symbolInfo = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
const symbolInfo = () => {
|
|
59
|
+
return {
|
|
60
|
+
ticker: symbolName,
|
|
61
|
+
name: symbolName,
|
|
62
|
+
ticker: symbolName,
|
|
63
|
+
description: symbolName,
|
|
64
|
+
type: "crypto",
|
|
65
|
+
session: "24x7",
|
|
66
|
+
timezone: "Etc/UTC",
|
|
67
|
+
exchange: "Binance",
|
|
68
|
+
minmov: 100,
|
|
69
|
+
pricescale: 100000,
|
|
70
|
+
has_intraday: true,
|
|
71
|
+
has_no_volume: false,
|
|
72
|
+
volume: "hundreds",
|
|
73
|
+
has_weekly_and_monthly: true,
|
|
74
|
+
volume_precision: 9,
|
|
75
|
+
data_status: "streaming",
|
|
76
|
+
resolution: "1h"
|
|
77
|
+
};
|
|
76
78
|
};
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
const symbol = await symbolInfo();
|
|
81
|
+
onSymbolResolvedCallback(symbol);
|
|
78
82
|
});
|
|
79
83
|
|
|
80
84
|
_defineProperty(this, "getBars", async (symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) => {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = getNextDailyBarTime;
|
|
7
6
|
exports.generateSymbol = generateSymbol;
|
|
8
7
|
exports.getAllSymbols = getAllSymbols;
|
|
9
8
|
exports.makeApiRequest = makeApiRequest;
|
|
@@ -70,10 +69,4 @@ async function getAllSymbols(symbol) {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
return newSymbols;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getNextDailyBarTime(barTime) {
|
|
76
|
-
const date = new Date(barTime * 1000);
|
|
77
|
-
date.setDate(date.getDate() + 1);
|
|
78
|
-
return date.getTime() / 1000;
|
|
79
72
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.10",
|
|
3
3
|
"name": "binbot-charts",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"react": "^17.0.1",
|
|
6
6
|
"react-dom": "^17.0.1",
|
|
7
|
-
"react-scripts": "^5.0.1",
|
|
8
7
|
"use-immer": "^0.7.0"
|
|
9
8
|
},
|
|
10
9
|
"devDependencies": {
|
|
@@ -12,7 +11,8 @@
|
|
|
12
11
|
"@babel/core": "^7.18.13",
|
|
13
12
|
"@babel/polyfill": "^7.12.1",
|
|
14
13
|
"@babel/preset-env": "^7.18.10",
|
|
15
|
-
"@babel/preset-typescript": "^7.18.6"
|
|
14
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
15
|
+
"react-scripts": "^5.0.1"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "react-scripts start",
|