binbot-charts 0.2.3 → 0.2.6

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.
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = TVChartContainer;
9
9
 
10
+ require("core-js/modules/es.promise.js");
11
+
10
12
  var _react = _interopRequireWildcard(require("react"));
11
13
 
12
14
  var _charting_library = require("../charting_library");
@@ -23,16 +25,17 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
23
25
 
24
26
  function TVChartContainer(_ref) {
25
27
  let {
26
- ohlcTick,
27
28
  symbol = "APEUSDT",
28
29
  interval = "1h",
29
30
  libraryPath = "/charting_library/",
30
31
  timescaleMarks = [],
31
32
  orderLines = [],
32
- height = "calc(100vh - 80px)"
33
+ height = "calc(100vh - 80px)",
34
+ onTick,
35
+ getLatestBar
33
36
  } = _ref;
34
37
  const containerRef = (0, _react.useRef)(null);
35
- (0, _react.useEffect)(() => {
38
+ (0, _react.useEffect)(async () => {
36
39
  const widgetOptions = {
37
40
  symbol: symbol,
38
41
  datafeed: new _datafeed.default(timescaleMarks),
@@ -53,11 +56,23 @@ function TVChartContainer(_ref) {
53
56
  tvWidget.onChartReady(() => {
54
57
  if (orderLines.length > 0) {
55
58
  orderLines.forEach(order => {
56
- tvWidget.chart().createPositionLine().setText(order.text).setTooltip(order.tooltip).setQuantity(order.quantity).setQuantityBackgroundColor(order.color).setQuantityBorderColor(order.color).setLineStyle(0).setLineLength(25).setLineColor(order.color).setBodyBorderColor(order.color).setBodyTextColor(order.color).setPrice(order.price);
59
+ const lineStyle = order.lineStyle || 0;
60
+ tvWidget.chart().createPositionLine().setText(order.text).setTooltip(order.tooltip).setQuantity(order.quantity).setQuantityFont("bold 12pt Verdana").setQuantityBackgroundColor(order.color).setQuantityBorderColor(order.color).setLineStyle(lineStyle).setLineLength(25).setLineColor(order.color).setBodyFont("bold 12pt Verdana").setBodyBorderColor(order.color).setBodyTextColor(order.color).setPrice(order.price);
57
61
  });
58
62
  }
59
63
 
60
- tvWidget.subscribe("onTick", event => ohlcTick(event));
64
+ tvWidget.subscribe("onTick", event => onTick(event)); // get latest bar for last price
65
+
66
+ const prices = async () => {
67
+ const data = await tvWidget.activeChart().exportData({
68
+ includeTime: false,
69
+ includeSeries: true,
70
+ includedStudies: []
71
+ });
72
+ getLatestBar(data.data[data.data.length - 1]);
73
+ };
74
+
75
+ prices();
61
76
  }); // returned function will be called on component unmount
62
77
 
63
78
  return () => {
@@ -83,5 +98,6 @@ TVChartContainer.propTypes = {
83
98
  timescaleMarks: _propTypes.default.array,
84
99
  orderLines: _propTypes.default.array,
85
100
  height: _propTypes.default.string,
86
- ohlcTick: _propTypes.default.func.isRequired
101
+ onTick: _propTypes.default.func,
102
+ getLatestBar: _propTypes.default.func
87
103
  };
@@ -49,7 +49,7 @@ class Datafeed {
49
49
  onResultReadyCallback(symbols);
50
50
  });
51
51
 
52
- _defineProperty(this, "resolveSymbol", async (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) => {
52
+ _defineProperty(this, "resolveSymbol", (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) => {
53
53
  if (!symbolName) {
54
54
  onResolveErrorCallback("cannot resolve symbol");
55
55
  return;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.3",
2
+ "version": "0.2.6",
3
3
  "name": "binbot-charts",
4
4
  "dependencies": {
5
5
  "react": "^17.0.1",