@mathieuc/tradingview 3.0.0 → 3.0.1
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/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Get realtime market prices and indicator values from Tradingview !
|
|
|
9
9
|
- [x] Unlimited simultaneous indicators
|
|
10
10
|
- [x] Realtime
|
|
11
11
|
- [x] Get TradingView's technical analysis
|
|
12
|
-
- [
|
|
12
|
+
- [x] Get values from a specific date range
|
|
13
13
|
- [ ] TradingView socket server emulation
|
|
14
14
|
- [ ] Interract with public chats
|
|
15
15
|
- [ ] Get Screener top values
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const TradingView = require('../main');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This example tests an indicator that sends
|
|
5
|
+
graphic data such as 'lines', 'labels',
|
|
6
|
+
'boxes', 'tables', 'polygons', etc...
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const client = new TradingView.Client();
|
|
10
|
+
|
|
11
|
+
const chart = new client.Session.Chart();
|
|
12
|
+
|
|
13
|
+
let wantedTimeframe = '5';
|
|
14
|
+
let timeframe = null;
|
|
15
|
+
|
|
16
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
17
|
+
timeframe: wantedTimeframe,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
chart.onSymbolLoaded(() => {
|
|
21
|
+
timeframe = wantedTimeframe;
|
|
22
|
+
console.log(`Timeframe is now '${timeframe}'`);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
chart.onUpdate(() => {
|
|
26
|
+
console.log(`Received data on '${timeframe}' timeframe`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
wantedTimeframe = '240';
|
|
31
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
32
|
+
timeframe: wantedTimeframe,
|
|
33
|
+
});
|
|
34
|
+
}, 3000);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const TradingView = require('../main');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This example tests fetching chart
|
|
5
|
+
data of a number of candles before
|
|
6
|
+
or after a timestamp
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const client = new TradingView.Client();
|
|
10
|
+
|
|
11
|
+
const chart = new client.Session.Chart();
|
|
12
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
13
|
+
timeframe: '240',
|
|
14
|
+
range: 2, // Can be positive to get before or negative to get after
|
|
15
|
+
to: 1600000000,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// This works with indicators
|
|
19
|
+
|
|
20
|
+
TradingView.getIndicator('STD;Supertrend').then(async (indic) => {
|
|
21
|
+
console.log(`Loading '${indic.description}' study...`);
|
|
22
|
+
const SUPERTREND = new chart.Study(indic);
|
|
23
|
+
|
|
24
|
+
SUPERTREND.onUpdate(() => {
|
|
25
|
+
console.log('Prices periods:', chart.periods);
|
|
26
|
+
console.log('Study periods:', SUPERTREND.periods);
|
|
27
|
+
client.end();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -10,23 +10,25 @@ const client = new TradingView.Client();
|
|
|
10
10
|
|
|
11
11
|
const chart = new client.Session.Chart();
|
|
12
12
|
chart.setMarket('BINANCE:BTCEUR', {
|
|
13
|
-
timeframe: '
|
|
13
|
+
timeframe: '5',
|
|
14
|
+
range: 10000,
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
// TradingView.getIndicator('USER;01efac32df544348810bc843a7515f36').then((indic) => {
|
|
17
|
-
TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
|
|
18
|
+
// TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
|
|
19
|
+
TradingView.getIndicator('STD;Zig_Zag').then((indic) => {
|
|
18
20
|
const STD = new chart.Study(indic);
|
|
19
21
|
|
|
20
22
|
STD.onError((...err) => {
|
|
21
|
-
console.log('
|
|
23
|
+
console.log('Study error:', ...err);
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
STD.onReady(() => {
|
|
25
|
-
console.log('STD Loaded
|
|
27
|
+
console.log(`STD '${STD.instance.description}' Loaded !`);
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
STD.onUpdate(() => {
|
|
29
|
-
console.log(STD.graphic);
|
|
31
|
+
console.log('Graphic data:', STD.graphic);
|
|
30
32
|
// console.log('Tables:', changes, STD.graphic.tables);
|
|
31
33
|
// console.log('Cells', STD.graphic.tables[0].cells());
|
|
32
34
|
client.end();
|
package/package.json
CHANGED
package/src/chart/session.js
CHANGED
|
@@ -53,15 +53,16 @@ const ChartTypes = {
|
|
|
53
53
|
* @prop {number} close Period close value
|
|
54
54
|
* @prop {number} max Period max value
|
|
55
55
|
* @prop {number} min Period min value
|
|
56
|
-
* @prop {number}
|
|
56
|
+
* @prop {number} volume Period volume value
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @typedef {Object} Subsession
|
|
61
61
|
* @prop {string} id Subsession ID (ex: 'regular')
|
|
62
62
|
* @prop {string} description Subsession description (ex: 'Regular')
|
|
63
|
-
* @prop {
|
|
63
|
+
* @prop {boolean} private If private
|
|
64
64
|
* @prop {string} session Session (ex: '24x7')
|
|
65
|
+
* @prop {string} session-correction Session correction
|
|
65
66
|
* @prop {string} session-display Session display (ex: '24x7')
|
|
66
67
|
*
|
|
67
68
|
* @typedef {Object} MarketInfos
|
|
@@ -91,7 +92,7 @@ const ChartTypes = {
|
|
|
91
92
|
* @prop {number} minmove2 Minimum move value 2
|
|
92
93
|
* @prop {string} timezone Used timezone
|
|
93
94
|
* @prop {boolean} is_replayable If the replay mode is available
|
|
94
|
-
* @prop {boolean} has_adjustment If the adjustment mode is enabled
|
|
95
|
+
* @prop {boolean} has_adjustment If the adjustment mode is enabled
|
|
95
96
|
* @prop {boolean} has_extended_hours Has extended hours
|
|
96
97
|
* @prop {string} bar_source Bar source
|
|
97
98
|
* @prop {string} bar_transform Bar transform
|
|
@@ -200,7 +201,7 @@ module.exports = (client) => class ChartSession {
|
|
|
200
201
|
close: p.v[4],
|
|
201
202
|
max: p.v[2],
|
|
202
203
|
min: p.v[3],
|
|
203
|
-
|
|
204
|
+
volume: Math.round(p.v[5] * 100) / 100,
|
|
204
205
|
};
|
|
205
206
|
});
|
|
206
207
|
|
|
@@ -241,13 +242,16 @@ module.exports = (client) => class ChartSession {
|
|
|
241
242
|
/**
|
|
242
243
|
* @param {import('../types').TimeFrame} timeframe Chart period timeframe
|
|
243
244
|
* @param {number} [range] Number of loaded periods/candles (Default: 100)
|
|
245
|
+
* @param {number} [reference] Reference candle timestamp (Default is now)
|
|
244
246
|
*/
|
|
245
|
-
setSeries(timeframe = '240', range = 100) {
|
|
247
|
+
setSeries(timeframe = '240', range = 100, reference = null) {
|
|
246
248
|
if (!this.#currentSeries) {
|
|
247
249
|
this.#handleError('Please set the market before setting series');
|
|
248
250
|
return;
|
|
249
251
|
}
|
|
250
252
|
|
|
253
|
+
const calcRange = !reference ? range : ['bar_count', reference, range];
|
|
254
|
+
|
|
251
255
|
this.#periods = {};
|
|
252
256
|
|
|
253
257
|
this.#client.send(`${this.#seriesCreated ? 'modify' : 'create'}_series`, [
|
|
@@ -256,7 +260,7 @@ module.exports = (client) => class ChartSession {
|
|
|
256
260
|
's1',
|
|
257
261
|
`ser_${this.#currentSeries}`,
|
|
258
262
|
timeframe,
|
|
259
|
-
this.#seriesCreated ? '' :
|
|
263
|
+
this.#seriesCreated ? '' : calcRange,
|
|
260
264
|
]);
|
|
261
265
|
|
|
262
266
|
this.#seriesCreated = true;
|
|
@@ -268,6 +272,7 @@ module.exports = (client) => class ChartSession {
|
|
|
268
272
|
* @param {Object} [options] Chart options
|
|
269
273
|
* @param {import('../types').TimeFrame} [options.timeframe] Chart period timeframe
|
|
270
274
|
* @param {number} [options.range] Number of loaded periods/candles (Default: 100)
|
|
275
|
+
* @param {number} [options.to] Last candle timestamp (Default is now)
|
|
271
276
|
* @param {'splits' | 'dividends'} [options.adjustment] Market adjustment
|
|
272
277
|
* @param {'regular' | 'extended'} [options.session] Chart session
|
|
273
278
|
* @param {'EUR' | 'USD' | string} [options.currency] Chart currency
|
|
@@ -302,7 +307,7 @@ module.exports = (client) => class ChartSession {
|
|
|
302
307
|
`=${JSON.stringify(chartInit)}`,
|
|
303
308
|
]);
|
|
304
309
|
|
|
305
|
-
this.setSeries(options.timeframe, options.range);
|
|
310
|
+
this.setSeries(options.timeframe, options.range, options.to);
|
|
306
311
|
}
|
|
307
312
|
|
|
308
313
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {'
|
|
2
|
+
* @typedef {'Volume@tv-basicstudies-144'
|
|
3
|
+
* | 'VbPFixed@tv-basicstudies-139!'
|
|
3
4
|
* | 'VbPFixed@tv-volumebyprice-53!'
|
|
4
5
|
* | 'VbPSessions@tv-volumebyprice-53'
|
|
5
6
|
* | 'VbPSessionsRough@tv-volumebyprice-53!'
|
|
@@ -16,6 +17,10 @@
|
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
const defaultValues = {
|
|
20
|
+
'Volume@tv-basicstudies-144': {
|
|
21
|
+
length: 20,
|
|
22
|
+
col_prev_close: false,
|
|
23
|
+
},
|
|
19
24
|
'VbPFixed@tv-basicstudies-139!': {
|
|
20
25
|
rowsLayout: 'Number Of Rows',
|
|
21
26
|
rows: 24,
|