@mathieuc/tradingview 2.0.91 → 3.2.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.
Files changed (56) hide show
  1. package/.eslintrc.js +18 -16
  2. package/README.md +19 -98
  3. package/examples/AllPrivateIndicators.js +35 -0
  4. package/examples/BuiltInIndicator.js +41 -0
  5. package/examples/CurrentTimeframe.js +34 -0
  6. package/examples/CustomChartType.js +122 -0
  7. package/examples/CustomTimeframe.js +29 -0
  8. package/examples/Errors.js +147 -0
  9. package/examples/FakeReplayMode.js +41 -0
  10. package/examples/FromToData.js +29 -0
  11. package/examples/GraphicIndicator.js +36 -0
  12. package/examples/MultipleSyncFetch.js +38 -0
  13. package/examples/PinePermManage.js +57 -0
  14. package/examples/ReplayMode.js +97 -0
  15. package/examples/Search.js +15 -0
  16. package/examples/SimpleChart.js +63 -0
  17. package/examples/_RenkoIndicator.js +41 -0
  18. package/main.js +11 -504
  19. package/package.json +9 -8
  20. package/src/FormData.js +35 -0
  21. package/src/chart/graphicParser.js +308 -0
  22. package/src/chart/session.js +546 -0
  23. package/src/chart/study.js +403 -0
  24. package/src/classes/BuiltInIndicator.js +124 -0
  25. package/src/classes/PineIndicator.js +132 -0
  26. package/src/classes/PinePermManager.js +142 -0
  27. package/src/client.js +280 -0
  28. package/{miscRequests.js → src/miscRequests.js} +102 -89
  29. package/src/protocol.js +54 -0
  30. package/src/quote/market.js +123 -0
  31. package/src/quote/session.js +125 -0
  32. package/src/request.js +37 -0
  33. package/src/types.js +32 -0
  34. package/src/utils.js +8 -0
  35. package/test.js +64 -0
  36. package/tests/1. Search.js +18 -0
  37. package/tests/2. QuoteSession.js +54 -0
  38. package/tests/3. SimpleChart.js +61 -0
  39. package/tests/4. Indicators.js +99 -0
  40. package/tests/5. BuiltInIndicator.js +41 -0
  41. package/tests/6. FakeReplayMode.js +59 -0
  42. package/tests/7. ReplayMode.js +51 -0
  43. package/tests/8. CustomChartTypes.js +115 -0
  44. package/tests/9. AllErrors.js +146 -0
  45. package/tests/disabled/x. Template.js +24 -0
  46. package/.github/FUNDING.yml +0 -1
  47. package/tests/alerts/discordWH.js +0 -76
  48. package/tests/alerts/drawings.js +0 -41
  49. package/tests/alerts/envLoader.js +0 -11
  50. package/tests/alerts/manualAlert.js +0 -77
  51. package/tests/alerts/sentNotifs.js +0 -16
  52. package/tests/alerts/strategyAlert.js +0 -94
  53. package/tests/analysis.js +0 -13
  54. package/tests/indicator.js +0 -42
  55. package/tests/prices.js +0 -33
  56. package/tests/strategy.js +0 -56
package/.eslintrc.js CHANGED
@@ -1,16 +1,18 @@
1
- module.exports = {
2
- env: {
3
- commonjs: true,
4
- es2021: true,
5
- node: true,
6
- },
7
- extends: [
8
- 'airbnb-base',
9
- ],
10
- parserOptions: {
11
- ecmaVersion: 12,
12
- },
13
- rules: {
14
- 'no-console': 'off',
15
- },
16
- };
1
+ module.exports = {
2
+ env: {
3
+ commonjs: true,
4
+ es2021: true,
5
+ node: true,
6
+ },
7
+ extends: [
8
+ 'airbnb-base',
9
+ ],
10
+ parser: '@babel/eslint-parser',
11
+ parserOptions: {
12
+ ecmaVersion: 12,
13
+ requireConfigFile: false,
14
+ },
15
+ rules: {
16
+ 'no-console': 'off',
17
+ },
18
+ };
package/README.md CHANGED
@@ -1,20 +1,29 @@
1
- # Tradingview API
1
+ # TradingView API [![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/Mathieu2301/TradingView-API) [![GitHub stars](https://img.shields.io/github/stars/Mathieu2301/TradingView-API.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/Mathieu2301/TradingView-API/stargazers/)
2
+
3
+ [![Tests](https://github.com/Mathieu2301/TradingView-API/actions/workflows/node.js.yml/badge.svg)](https://github.com/Mathieu2301/TradingView-API/actions/workflows/node.js.yml)
4
+ [![Minimum node.js version](https://badgen.net/npm/node/@mathieuc/tradingview)](https://npmjs.com/@mathieuc/tradingview)
5
+ [![Npm package yearly downloads](https://badgen.net/npm/dt/@mathieuc/tradingview)](https://npmjs.com/@mathieuc/tradingview)
6
+ [![GitHub latest commit](https://img.shields.io/github/last-commit/Mathieu2301/TradingView-API)](https://GitHub.com/Mathieu2301/TradingView-API/commit/)
7
+ [![Npm package version](https://badgen.net/npm/v/@mathieuc/tradingview)](https://npmjs.com/package/@mathieuc/tradingview)
8
+
2
9
  Get realtime market prices and indicator values from Tradingview !
3
10
 
4
11
  ## Features
12
+ - [x] Premium features
5
13
  - [x] Automatically backtest many strategies and try many settings in a very little time
6
14
  - [x] Get drawings you made on your chart
7
15
  - [x] Works with invite-only indicators
8
16
  - [x] Unlimited simultaneous indicators
9
17
  - [x] Realtime
10
18
  - [x] Get TradingView's technical analysis
11
- - [ ] Get values from a specific date range
19
+ - [x] Replay mode + Fake Replay mode (for free plan)
20
+ - [x] Get values from a specific date range
12
21
  - [ ] TradingView socket server emulation
13
22
  - [ ] Interract with public chats
14
23
  - [ ] Get Screener top values
15
24
  - [ ] Get Hotlists
16
25
  - [ ] Get Calendar
17
- - IF YOU WANT A FEATURE, ASK ME !!
26
+ - IF YOU WANT A FEATURE, ASK ME !
18
27
 
19
28
  ## Possibilities
20
29
  - Trading bot
@@ -26,106 +35,18 @@ Get realtime market prices and indicator values from Tradingview !
26
35
  ___
27
36
  ## Installation
28
37
 
29
- ```
38
+ Stable version:
39
+ ```ruby
30
40
  npm i @mathieuc/tradingview
31
41
  ```
32
-
33
- ## Examples (./tests/)
34
-
35
- ```javascript
36
- /*
37
- ./tests/prices.js
38
- Search for Bitcoin and Ethereum and get real time prices
39
- */
40
-
41
- const marketAPI = require('tradingview');
42
-
43
- (async () => {
44
- const market = marketAPI();
45
-
46
- market.on('logged', async () => {
47
- console.log('API LOGGED');
48
-
49
- const searchBTC = (await market.search('bitcoin euro', 'crypto'))[0];
50
- console.log('Found Bitcoin / Euro:', searchBTC);
51
- market.subscribe(searchBTC.id);
52
- });
53
-
54
- market.on('price', (data) => {
55
- console.log(data.symbol, '=>', data.price);
56
- });
57
-
58
- const searchETH = (await market.search('ethereum euro', 'crypto'))[0];
59
- console.log('Found Ethereum / Euro:', searchETH);
60
-
61
- setTimeout(() => {
62
- console.log('Subscribe to', searchETH.id);
63
- market.subscribe(searchETH.id);
64
- }, 10000);
65
-
66
- setTimeout(() => {
67
- console.log('Unsubscribe from', searchETH.id);
68
- market.unsubscribe(searchETH.id);
69
- }, 20000);
70
- })();
71
- ```
72
-
73
- ```javascript
74
- /*
75
- ./tests/analysis.js
76
- Search for Bitcoin and get the Technical Analysis in all timeframes
77
- */
78
-
79
- const marketAPI = require('tradingview');
80
-
81
- (async () => {
82
- const market = marketAPI(false);
83
-
84
- const searchBTC = (await market.search('bitcoin euro', 'crypto'))[0];
85
- console.log('Found Bitcoin / Euro:', searchBTC);
86
-
87
- const TA = await searchBTC.getTA();
88
- console.log('Full technical analysis for Bitcoin:', TA);
89
-
90
- // You can also use this way: await market.getTA('crypto', 'BINANCE:BTCEUR');
91
- })();
42
+ Last version:
43
+ ```ruby
44
+ npm i github:Mathieu2301/TradingView-API
92
45
  ```
93
46
 
94
- ```javascript
95
- /*
96
- ./tests/indicator.js
97
- Get indicator values
98
- */
99
-
100
- const marketAPI = require('tradingview');
47
+ ## Examples
48
+ You can find all the examples and snippets in `./examples` folder.
101
49
 
102
- const market = marketAPI(false); // 'false' for chart-only mode
103
-
104
- market.on('logged', () => {
105
- market.initChart({
106
- symbol: 'COINBASE:BTCEUR',
107
- period: '240',
108
- range: 50,
109
- indicators: [
110
- { name: 'ACCU_DISTRIB', id: 'STD;Accumulation_Distribution', version: '25' },
111
- { name: 'CIPHER_A', id: 'PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT', version: '1.0' },
112
- { name: 'CIPHER_B', id: 'PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp', version: '15.0' },
113
- // Color Changing moving average
114
- { name: 'CCMA', id: 'PUB;5nawr3gCESvSHQfOhrLPqQqT4zM23w3X', version: '6.0' },
115
- ],
116
- }, (periods) => {
117
- if (!periods[0].CIPHER_B) return;
118
- if (!periods[0].CCMA) return;
119
-
120
- console.log('Last period:', {
121
- price: periods[0].$prices.close,
122
- moneyFlow: (periods[0].CIPHER_B.RSIMFIArea >= 0) ? 'POSITIVE' : 'NEGATIVE',
123
- VWAP: periods[0].CIPHER_B.VWAP,
124
- MA: (periods[0].CCMA.Plot <= periods[0].$prices.close) ? 'ABOVE' : 'UNDER',
125
- });
126
- });
127
- });
128
- ```
129
50
  ___
130
51
  ## Problems
131
52
  If you have errors in console or unwanted behavior,
@@ -0,0 +1,35 @@
1
+ const TradingView = require('../main');
2
+
3
+ /*
4
+ This example creates a chart with
5
+ all user's private indicators
6
+ */
7
+
8
+ if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
9
+
10
+ const client = new TradingView.Client({
11
+ token: process.argv[2],
12
+ });
13
+
14
+ const chart = new client.Session.Chart();
15
+ chart.setMarket('BINANCE:BTCEUR', {
16
+ timeframe: 'D',
17
+ });
18
+
19
+ TradingView.getPrivateIndicators(process.argv[2]).then((indicList) => {
20
+ indicList.forEach(async (indic) => {
21
+ const privateIndic = await indic.get();
22
+ console.log('Loading indicator', indic.name, '...');
23
+
24
+ const indicator = new chart.Study(privateIndic);
25
+
26
+ indicator.onReady(() => {
27
+ console.log('Indicator', indic.name, 'loaded !');
28
+ });
29
+
30
+ indicator.onUpdate(() => {
31
+ console.log('Plot values', indicator.periods);
32
+ console.log('Strategy report', indicator.strategyReport);
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,41 @@
1
+ const TradingView = require('../main');
2
+
3
+ /*
4
+ This example tests built-in indicators
5
+ like volume-based indicators
6
+ */
7
+
8
+ const volumeProfile = new TradingView.BuiltInIndicator('VbPFixed@tv-basicstudies-139!');
9
+
10
+ if (!process.argv[2] && volumeProfile.type !== 'VbPFixed@tv-basicstudies-139!') {
11
+ throw Error('Please specify your \'sessionid\' cookie');
12
+ }
13
+
14
+ const client = new TradingView.Client({
15
+ token: process.argv[2],
16
+ });
17
+
18
+ const chart = new client.Session.Chart();
19
+ chart.setMarket('BINANCE:BTCEUR', {
20
+ timeframe: '60',
21
+ range: 1,
22
+ });
23
+
24
+ /* Required or not, depending on the indicator */
25
+ volumeProfile.setOption('first_bar_time', Date.now() - 10 ** 8);
26
+ // volumeProfile.setOption('first_visible_bar_time', Date.now() - 10 ** 8);
27
+
28
+ const VOL = new chart.Study(volumeProfile);
29
+ VOL.onUpdate(() => {
30
+ VOL.graphic.horizHists
31
+ .filter((h) => h.lastBarTime === 0) // We only keep recent volume infos
32
+ .sort((a, b) => b.priceHigh - a.priceHigh)
33
+ .forEach((h) => {
34
+ console.log(
35
+ `~ ${Math.round((h.priceHigh + h.priceLow) / 2)} € :`,
36
+ `${'_'.repeat(h.rate[0] / 3)}${'_'.repeat(h.rate[1] / 3)}`,
37
+ );
38
+ });
39
+
40
+ client.end();
41
+ });
@@ -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,122 @@
1
+ const TradingView = require('../main');
2
+
3
+ /*
4
+ This example creates charts of custom
5
+ types such as 'HeikinAshi', 'Renko',
6
+ 'LineBreak', 'Kagi', 'PointAndFigure',
7
+ and 'Range' with default settings
8
+ */
9
+
10
+ const client = new TradingView.Client({
11
+ /* Token is only required if you want to use intraday
12
+ timeframes (if you have a paid TradingView account) */
13
+ token: process.argv[2],
14
+ });
15
+
16
+ const chart = new client.Session.Chart();
17
+
18
+ chart.onError((...err) => {
19
+ console.log('Chart error:', ...err);
20
+ process.exit(1);
21
+ });
22
+
23
+ chart.onUpdate(() => {
24
+ if (!chart.periods[0]) return;
25
+ console.log('Last period', chart.periods[0]);
26
+ });
27
+
28
+ /* (0s) Heikin Ashi chart */
29
+ setTimeout(() => {
30
+ console.log('\nSetting chart type to: HeikinAshi');
31
+
32
+ chart.setMarket('BINANCE:BTCEUR', {
33
+ type: 'HeikinAshi',
34
+ timeframe: 'D',
35
+ });
36
+ }, 0);
37
+
38
+ /* (5s) Renko chart */
39
+ setTimeout(() => {
40
+ console.log('\nSetting chart type to: Renko');
41
+
42
+ chart.setMarket('BINANCE:BTCEUR', {
43
+ type: 'Renko',
44
+ timeframe: 'D',
45
+ inputs: {
46
+ source: 'close',
47
+ sources: 'Close',
48
+ boxSize: 3,
49
+ style: 'ATR',
50
+ atrLength: 14,
51
+ wicks: true,
52
+ },
53
+ });
54
+ }, 5000);
55
+
56
+ /* (10s) Line Break chart */
57
+ setTimeout(() => {
58
+ console.log('\nSetting chart type to: LineBreak');
59
+
60
+ chart.setMarket('BINANCE:BTCEUR', {
61
+ type: 'LineBreak',
62
+ timeframe: 'D',
63
+ inputs: {
64
+ source: 'close',
65
+ lb: 3,
66
+ },
67
+ });
68
+ }, 10000);
69
+
70
+ /* (15s) Kagi chart */
71
+ setTimeout(() => {
72
+ console.log('\nSetting chart type to: Kagi');
73
+
74
+ chart.setMarket('BINANCE:BTCEUR', {
75
+ type: 'Kagi',
76
+ timeframe: 'D',
77
+ inputs: {
78
+ source: 'close',
79
+ style: 'ATR',
80
+ atrLength: 14,
81
+ reversalAmount: 1,
82
+ },
83
+ });
84
+ }, 15000);
85
+
86
+ /* (20s) Point & Figure chart */
87
+ setTimeout(() => {
88
+ console.log('\nSetting chart type to: PointAndFigure');
89
+
90
+ chart.setMarket('BINANCE:BTCEUR', {
91
+ type: 'PointAndFigure',
92
+ timeframe: 'D',
93
+ inputs: {
94
+ sources: 'Close',
95
+ reversalAmount: 3,
96
+ boxSize: 1,
97
+ style: 'ATR',
98
+ atrLength: 14,
99
+ oneStepBackBuilding: false,
100
+ },
101
+ });
102
+ }, 20000);
103
+
104
+ /* (25s) Range chart */
105
+ setTimeout(() => {
106
+ console.log('\nSetting chart type to: Range');
107
+
108
+ chart.setMarket('BINANCE:BTCEUR', {
109
+ type: 'Range',
110
+ timeframe: 'D',
111
+ inputs: {
112
+ range: 1,
113
+ phantomBars: false,
114
+ },
115
+ });
116
+ }, 25000);
117
+
118
+ /* (30s) Delete chart, close client */
119
+ setTimeout(() => {
120
+ console.log('\nClosing client...');
121
+ client.end();
122
+ }, 30000);
@@ -0,0 +1,29 @@
1
+ const TradingView = require('../main');
2
+
3
+ /*
4
+ This example tests custom
5
+ timeframes like 1 second
6
+ */
7
+
8
+ if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
9
+
10
+ const client = new TradingView.Client({
11
+ token: process.argv[2],
12
+ });
13
+
14
+ const chart = new client.Session.Chart();
15
+ chart.setTimezone('Europe/Paris');
16
+
17
+ chart.setMarket('CAPITALCOM:US100', {
18
+ timeframe: '1S',
19
+ range: 10,
20
+ });
21
+
22
+ chart.onSymbolLoaded(() => {
23
+ console.log(chart.infos.name, 'loaded !');
24
+ });
25
+
26
+ chart.onUpdate(() => {
27
+ console.log('OK', chart.periods);
28
+ client.end();
29
+ });
@@ -0,0 +1,147 @@
1
+ const TradingView = require('../main');
2
+
3
+ /*
4
+ This example tests many types of errors
5
+ */
6
+
7
+ const client = new TradingView.Client(); // Creates a websocket client
8
+
9
+ const tests = [
10
+ (next) => { /* Testing "Credentials error" */
11
+ console.info('\nTesting "Credentials error" error:');
12
+
13
+ const client2 = new TradingView.Client({
14
+ token: 'FAKE_CREDENTIALS', // Set wrong credentials
15
+ });
16
+
17
+ client2.onError((...err) => {
18
+ console.error(' => Client error:', err);
19
+ client2.end();
20
+ next();
21
+ });
22
+ },
23
+
24
+ (next) => { /* Testing "Invalid symbol" */
25
+ console.info('\nTesting "Invalid symbol" error:');
26
+
27
+ const chart = new client.Session.Chart();
28
+ chart.onError((...err) => { // Listen for errors
29
+ console.error(' => Chart error:', err);
30
+ chart.delete();
31
+ next();
32
+ });
33
+
34
+ chart.setMarket('XXXXX'); // Set a wrong market
35
+ },
36
+
37
+ (next) => { /* Testing "Invalid timezone" */
38
+ console.info('\nTesting "Invalid timezone" error:');
39
+
40
+ const chart = new client.Session.Chart();
41
+ chart.onError((...err) => { // Listen for errors
42
+ console.error(' => Chart error:', err);
43
+ next();
44
+ });
45
+
46
+ chart.setMarket('BINANCE:BTCEUR'); // Set a market
47
+ chart.setTimezone('Nowhere/Nowhere'); // Set a fake timezone
48
+ },
49
+
50
+ (next) => { /* Testing "Custom timeframe" */
51
+ console.info('\nTesting "Custom timeframe" error:');
52
+
53
+ const chart = new client.Session.Chart();
54
+ chart.onError((...err) => { // Listen for errors
55
+ console.error(' => Chart error:', err);
56
+ chart.delete();
57
+ next();
58
+ });
59
+
60
+ chart.setMarket('BINANCE:BTCEUR', { // Set a market
61
+ timeframe: '20', // Set a custom timeframe
62
+ /*
63
+ Timeframe '20' isn't available because we are
64
+ not logged in as a premium TradingView account
65
+ */
66
+ });
67
+ },
68
+
69
+ (next) => { /* Testing "Invalid timeframe" */
70
+ console.info('\nTesting "Invalid timeframe" error:');
71
+
72
+ const chart = new client.Session.Chart();
73
+ chart.onError((...err) => { // Listen for errors
74
+ console.error(' => Chart error:', err);
75
+ next();
76
+ });
77
+
78
+ chart.setMarket('BINANCE:BTCEUR', { // Set a market
79
+ timeframe: 'XX', // Set a wrong timeframe
80
+ });
81
+ },
82
+
83
+ (next) => { /* Testing "Study not auth" */
84
+ console.info('\nTesting "Study not auth" error:');
85
+
86
+ const chart = new client.Session.Chart();
87
+ chart.onError((...err) => { // Listen for errors
88
+ console.error(' => Chart error:', err);
89
+ next();
90
+ });
91
+
92
+ chart.setMarket('BINANCE:BTCEUR', { // Set a market
93
+ timeframe: '15',
94
+ type: 'Renko',
95
+ });
96
+
97
+ chart.onUpdate(() => {
98
+ console.log('DATA', chart.periods[0]);
99
+ });
100
+ },
101
+
102
+ (next) => { /* Testing "Set the market before" */
103
+ console.info('\nTesting "Set the market before..." error:');
104
+
105
+ const chart = new client.Session.Chart();
106
+ chart.onError((...err) => { // Listen for errors
107
+ console.error(' => Chart error:', err);
108
+ chart.delete();
109
+ next();
110
+ });
111
+
112
+ chart.setSeries('15'); // Set series before setting the market
113
+ },
114
+
115
+ (next) => { /* Testing "Inexistent indicator" */
116
+ console.info('\nTesting "Inexistent indicator" error:');
117
+
118
+ TradingView.getIndicator('STD;XXXXXXX')
119
+ .catch((err) => {
120
+ console.error(' => API error:', [err.message]);
121
+ next();
122
+ });
123
+ },
124
+
125
+ async (next) => { /* Testing "Invalid value" */
126
+ console.info('\nTesting "Invalid value" error:');
127
+
128
+ const chart = new client.Session.Chart();
129
+ chart.setMarket('BINANCE:BTCEUR'); // Set a market
130
+
131
+ const ST = await TradingView.getIndicator('STD;Supertrend');
132
+ ST.setOption('Factor', -1); // This will cause an error
133
+
134
+ const Supertrend = new chart.Study(ST);
135
+ Supertrend.onError((...err) => {
136
+ console.error(' => Study error:', err);
137
+ chart.delete();
138
+ next();
139
+ });
140
+ },
141
+ ];
142
+
143
+ (async () => {
144
+ // eslint-disable-next-line no-restricted-syntax, no-await-in-loop
145
+ for (const t of tests) await new Promise(t);
146
+ console.log(`\nTests ${tests.length}/${tests.length} done !`);
147
+ })();
@@ -0,0 +1,41 @@
1
+ const { Client } = require('../main');
2
+
3
+ /*
4
+ This example tests the fake
5
+ replay mode which works in
6
+ intraday even with free plan
7
+ */
8
+
9
+ console.log('----- Testing FakeReplayMode: -----');
10
+
11
+ const client = new Client();
12
+ const chart = new client.Session.Chart();
13
+
14
+ chart.setMarket('BINANCE:BTCEUR', {
15
+ timeframe: 'D',
16
+ range: -1, // Range is negative, so 'to' means 'from'
17
+ to: Math.round(Date.now() / 1000) - 86400 * 7, // Seven days before now
18
+ // to: 1600000000,
19
+ });
20
+
21
+ let interval = NaN;
22
+
23
+ chart.onUpdate(async () => {
24
+ const times = chart.periods.map((p) => p.time);
25
+
26
+ const intrval = times[0] - times[1];
27
+ if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
28
+
29
+ if (!Number.isNaN(interval) && interval !== intrval) {
30
+ throw new Error(`Wrong interval: ${intrval} (should be ${interval})`);
31
+ }
32
+
33
+ console.log('Next ->', times[0]);
34
+
35
+ if ((times[0] + 86400) * 1000 > Date.now()) {
36
+ await client.end();
37
+ console.log('Done !', times.length);
38
+ }
39
+
40
+ chart.fetchMore(-1);
41
+ });
@@ -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
+ });