@mathieuc/tradingview 3.0.0-pre → 3.0.0

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.
@@ -13,8 +13,8 @@ chart.setMarket('BINANCE:BTCEUR', {
13
13
  timeframe: 'W',
14
14
  });
15
15
 
16
- // TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
17
- TradingView.getIndicator('USER;8bbd8017fd3e4881bf91f4fea5e3d538').then((indic) => {
16
+ // TradingView.getIndicator('USER;01efac32df544348810bc843a7515f36').then((indic) => {
17
+ TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
18
18
  const STD = new chart.Study(indic);
19
19
 
20
20
  STD.onError((...err) => {
@@ -25,20 +25,10 @@ TradingView.getIndicator('USER;8bbd8017fd3e4881bf91f4fea5e3d538').then((indic) =
25
25
  console.log('STD Loaded !');
26
26
  });
27
27
 
28
- STD.onUpdate((changes) => {
29
- // STD.graphic;
30
- console.log('Update:', changes, STD.graphic);
31
- // client.end();
28
+ STD.onUpdate(() => {
29
+ console.log(STD.graphic);
30
+ // console.log('Tables:', changes, STD.graphic.tables);
31
+ // console.log('Cells', STD.graphic.tables[0].cells());
32
+ client.end();
32
33
  });
33
34
  });
34
-
35
- // setInterval(() => {
36
- // chart.fetchMore(100);
37
- // }, 2000);
38
-
39
- // setTimeout(() => {
40
- // console.log('Setting timeframe to: \'D\'');
41
- // chart.setSeries('D');
42
- // }, 5000);
43
-
44
- chart.onUpdate(() => console.log(chart.periods.length));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mathieuc/tradingview",
3
- "version": "3.0.0-pre",
3
+ "version": "3.0.0",
4
4
  "description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -1,21 +1,159 @@
1
+ const TRANSLATOR = {
2
+ /** @typedef {'right' | 'left' | 'both' | 'none'} ExtendValue */
3
+ extend: {
4
+ r: 'right',
5
+ l: 'left',
6
+ b: 'both',
7
+ n: 'none',
8
+ },
9
+
10
+ /** @typedef {'price' | 'abovebar' | 'belowbar'} yLocValue */
11
+ yLoc: {
12
+ pr: 'price',
13
+ ab: 'abovebar',
14
+ bl: 'belowbar',
15
+ },
16
+
17
+ /**
18
+ * @typedef {'none' | 'xcross' | 'cross' | 'triangleup'
19
+ * | 'triangledown' | 'flag' | 'circle' | 'arrowup'
20
+ * | 'arrowdown' | 'label_up' | 'label_down' | 'label_left'
21
+ * | 'label_right' | 'label_lower_left' | 'label_lower_right'
22
+ * | 'label_upper_left' | 'label_upper_right' | 'label_center'
23
+ * | 'square' | 'diamond'
24
+ * } LabelStyleValue
25
+ * */
26
+ labelStyle: {
27
+ n: 'none',
28
+ xcr: 'xcross',
29
+ cr: 'cross',
30
+ tup: 'triangleup',
31
+ tdn: 'triangledown',
32
+ flg: 'flag',
33
+ cir: 'circle',
34
+ aup: 'arrowup',
35
+ adn: 'arrowdown',
36
+ lup: 'label_up',
37
+ ldn: 'label_down',
38
+ llf: 'label_left',
39
+ lrg: 'label_right',
40
+ llwlf: 'label_lower_left',
41
+ llwrg: 'label_lower_right',
42
+ luplf: 'label_upper_left',
43
+ luprg: 'label_upper_right',
44
+ lcn: 'label_center',
45
+ sq: 'square',
46
+ dia: 'diamond',
47
+ },
48
+
49
+ /**
50
+ * @typedef {'solid' | 'dotted' | 'dashed'| 'arrow_left'
51
+ * | 'arrow_right' | 'arrow_both'} LineStyleValue
52
+ */
53
+ lineStyle: {
54
+ sol: 'solid',
55
+ dot: 'dotted',
56
+ dsh: 'dashed',
57
+ al: 'arrow_left',
58
+ ar: 'arrow_right',
59
+ ab: 'arrow_both',
60
+ },
61
+
62
+ /** @typedef {'solid' | 'dotted' | 'dashed'} BoxStyleValue */
63
+ boxStyle: {
64
+ sol: 'solid',
65
+ dot: 'dotted',
66
+ dsh: 'dashed',
67
+ },
68
+ };
69
+
70
+ /**
71
+ * @typedef {'auto' | 'huge' | 'large'
72
+ * | 'normal' | 'small' | 'tiny'} SizeValue
73
+ */
74
+ /** @typedef {'top' | 'center' | 'bottom'} VAlignValue */
75
+ /** @typedef {'left' | 'center' | 'right'} HAlignValue */
76
+ /** @typedef {'none' | 'auto'} TextWrapValue */
77
+ /**
78
+ * @typedef {'top_left' | 'top_center' | 'top_right'
79
+ * | 'middle_left' | 'middle_center' | 'middle_right'
80
+ * | 'bottom_left' | 'bottom_center' | 'bottom_right'
81
+ * } TablePositionValue
82
+ */
83
+
1
84
  /**
2
85
  * @typedef {Object} GraphicLabel
3
86
  * @prop {number} id Drawing ID
87
+ * @prop {number} x Label x position
88
+ * @prop {number} y Label y position
89
+ * @prop {yLocValue} yLoc yLoc mode
90
+ * @prop {string} text Label text
91
+ * @prop {LabelStyleValue} style Label style
92
+ * @prop {number} color
93
+ * @prop {number} textColor
94
+ * @prop {SizeValue} size Label size
95
+ * @prop {HAlignValue} textAlign Text horizontal align
96
+ * @prop {string} toolTip Tooltip text
4
97
  */
5
98
 
6
99
  /**
7
100
  * @typedef {Object} GraphicLine
8
101
  * @prop {number} id Drawing ID
102
+ * @prop {number} x1 First x position
103
+ * @prop {number} y1 First y position
104
+ * @prop {number} x2 Second x position
105
+ * @prop {number} y2 Second y position
106
+ * @prop {ExtendValue} extend Horizontal extend
107
+ * @prop {LineStyleValue} style Line style
108
+ * @prop {number} color Line color
109
+ * @prop {number} width Line width
9
110
  */
10
111
 
11
112
  /**
12
113
  * @typedef {Object} GraphicBox
13
114
  * @prop {number} id Drawing ID
115
+ * @prop {number} x1 First x position
116
+ * @prop {number} y1 First y position
117
+ * @prop {number} x2 Second x position
118
+ * @prop {number} y2 Second y position
119
+ * @prop {number} color Box color
120
+ * @prop {number} bgColor Background color
121
+ * @prop {ExtendValue} extend Horizontal extend
122
+ * @prop {BoxStyleValue} style Box style
123
+ * @prop {number} width Box width
124
+ * @prop {string} text Text
125
+ * @prop {SizeValue} textSize Text size
126
+ * @prop {number} textColor Text color
127
+ * @prop {VAlignValue} textVAlign Text vertical align
128
+ * @prop {HAlignValue} textHAlign Text horizontal align
129
+ * @prop {TextWrapValue} textWrap Text wrap
130
+ */
131
+
132
+ /**
133
+ * @typedef {Object} TableCell
134
+ * @prop {number} id Drawing ID
135
+ * @prop {string} text Cell text
136
+ * @prop {number} width Cell width
137
+ * @prop {number} height Cell height
138
+ * @prop {number} textColor Text color
139
+ * @prop {HAlignValue} textHAlign Text horizontal align
140
+ * @prop {VAlignValue} textVAlign Text Vertical align
141
+ * @prop {SizeValue} textSize Text size
142
+ * @prop {number} bgColor Background color
14
143
  */
15
144
 
16
145
  /**
17
146
  * @typedef {Object} GraphicTable
18
147
  * @prop {number} id Drawing ID
148
+ * @prop {TablePositionValue} position Table position
149
+ * @prop {number} rows Number of rows
150
+ * @prop {number} columns Number of columns
151
+ * @prop {number} bgColor Background color
152
+ * @prop {number} frameColor Frame color
153
+ * @prop {number} frameWidth Frame width
154
+ * @prop {number} borderColor Border color
155
+ * @prop {number} borderWidth Border width
156
+ * @prop {() => TableCell[][]} cells Table cells matrix
19
157
  */
20
158
 
21
159
  /**
@@ -70,19 +208,79 @@ module.exports = function graphicParse(rawGraphic = {}, indexes = []) {
70
208
  // console.log('indexes', indexes);
71
209
  return {
72
210
  labels: Object.values(rawGraphic.dwglabels ?? {}).map((l) => ({
73
- ...l,
211
+ id: l.id,
212
+ x: indexes[l.x],
213
+ y: l.y,
214
+ yLoc: TRANSLATOR.yLoc[l.yl] ?? l.yl,
215
+ text: l.t,
216
+ style: TRANSLATOR.labelStyle[l.st] ?? l.st,
217
+ color: l.ci,
218
+ textColor: l.tci,
219
+ size: l.sz,
220
+ textAlign: l.ta,
221
+ toolTip: l.tt,
74
222
  })),
75
223
 
76
224
  lines: Object.values(rawGraphic.dwglines ?? {}).map((l) => ({
77
- ...l,
225
+ id: l.id,
226
+ x1: indexes[l.x1],
227
+ y1: l.y1,
228
+ x2: indexes[l.x2],
229
+ y2: l.y2,
230
+ extend: TRANSLATOR.extend[l.ex] ?? l.ex,
231
+ style: TRANSLATOR.lineStyle[l.st] ?? l.st,
232
+ color: l.ci,
233
+ width: l.w,
78
234
  })),
79
235
 
80
236
  boxes: Object.values(rawGraphic.dwgboxes ?? {}).map((b) => ({
81
- ...b,
237
+ id: b.id,
238
+ x1: indexes[b.x1],
239
+ y1: b.y1,
240
+ x2: indexes[b.x2],
241
+ y2: b.y2,
242
+ color: b.c,
243
+ bgColor: b.bc,
244
+ extend: TRANSLATOR.extend[b.ex] ?? b.ex,
245
+ style: TRANSLATOR.boxStyle[b.st] ?? b.st,
246
+ width: b.w,
247
+ text: b.t,
248
+ textSize: b.ts,
249
+ textColor: b.tc,
250
+ textVAlign: b.tva,
251
+ textHAlign: b.tha,
252
+ textWrap: b.tw,
82
253
  })),
83
254
 
84
255
  tables: Object.values(rawGraphic.dwgtables ?? {}).map((t) => ({
85
- ...t,
256
+ id: t.id,
257
+ position: t.pos,
258
+ rows: t.rows,
259
+ columns: t.cols,
260
+ bgColor: t.bgc,
261
+ frameColor: t.frmc,
262
+ frameWidth: t.frmw,
263
+ borderColor: t.brdc,
264
+ borderWidth: t.brdw,
265
+ cells: () => {
266
+ const matrix = [];
267
+ Object.values(rawGraphic.dwgtablecells ?? {}).forEach((cell) => {
268
+ if (cell.tid !== t.id) return;
269
+ if (!matrix[cell.row]) matrix[cell.row] = [];
270
+ matrix[cell.row][cell.col] = {
271
+ id: cell.id,
272
+ text: cell.t,
273
+ width: cell.w,
274
+ height: cell.h,
275
+ textColor: cell.tc,
276
+ textHAlign: cell.tha,
277
+ textVAlign: cell.tva,
278
+ textSize: cell.ts,
279
+ bgColor: cell.bgc,
280
+ };
281
+ });
282
+ return matrix;
283
+ },
86
284
  })),
87
285
 
88
286
  horizLines: Object.values(rawGraphic.horizlines ?? {}).map((h) => ({