@mathieuc/tradingview 2.0.91 → 3.0.0-pre
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/.eslintrc.js +18 -16
- package/README.md +5 -97
- package/examples/AllPrivateIndicators.js +35 -0
- package/examples/BuiltInIndicator.js +41 -0
- package/examples/CustomChartType.js +121 -0
- package/examples/CustomTimeframe.js +29 -0
- package/examples/Errors.js +153 -0
- package/examples/GraphicIndicator.js +44 -0
- package/examples/MultipleSyncFetch.js +38 -0
- package/examples/Search.js +15 -0
- package/examples/SimpleChart.js +63 -0
- package/examples/_RenkoIndicator.js +41 -0
- package/main.js +9 -504
- package/package.json +5 -2
- package/src/chart/graphicParser.js +110 -0
- package/src/chart/session.js +367 -0
- package/src/chart/study.js +403 -0
- package/src/classes/BuiltInIndicator.js +119 -0
- package/src/classes/PineIndicator.js +132 -0
- package/src/client.js +280 -0
- package/{miscRequests.js → src/miscRequests.js} +97 -56
- package/src/protocol.js +54 -0
- package/src/quote/market.js +123 -0
- package/src/quote/session.js +124 -0
- package/src/types.js +32 -0
- package/src/utils.js +8 -0
- package/test.js +155 -0
- package/tests/alerts/discordWH.js +76 -76
- package/tests/alerts/envLoader.js +11 -11
- package/tests/alerts/manualAlert.js +77 -77
- package/tests/alerts/sentNotifs.js +16 -16
- package/tests/alerts/strategyAlert.js +94 -94
- package/tests/indicator.js +42 -42
- package/tests/strategy.js +56 -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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,7 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TradingView API
|
|
2
2
|
Get realtime market prices and indicator values from Tradingview !
|
|
3
3
|
|
|
4
4
|
## Features
|
|
5
|
+
- [x] Premium features
|
|
5
6
|
- [x] Automatically backtest many strategies and try many settings in a very little time
|
|
6
7
|
- [x] Get drawings you made on your chart
|
|
7
8
|
- [x] Works with invite-only indicators
|
|
@@ -14,7 +15,7 @@ Get realtime market prices and indicator values from Tradingview !
|
|
|
14
15
|
- [ ] Get Screener top values
|
|
15
16
|
- [ ] Get Hotlists
|
|
16
17
|
- [ ] Get Calendar
|
|
17
|
-
- IF YOU WANT A FEATURE, ASK ME
|
|
18
|
+
- IF YOU WANT A FEATURE, ASK ME !
|
|
18
19
|
|
|
19
20
|
## Possibilities
|
|
20
21
|
- Trading bot
|
|
@@ -30,102 +31,9 @@ ___
|
|
|
30
31
|
npm i @mathieuc/tradingview
|
|
31
32
|
```
|
|
32
33
|
|
|
33
|
-
## Examples
|
|
34
|
+
## Examples
|
|
35
|
+
You can find all the examples and snippets in `./examples` folder.
|
|
34
36
|
|
|
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
|
-
})();
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
```javascript
|
|
95
|
-
/*
|
|
96
|
-
./tests/indicator.js
|
|
97
|
-
Get indicator values
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
const marketAPI = require('tradingview');
|
|
101
|
-
|
|
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
37
|
___
|
|
130
38
|
## Problems
|
|
131
39
|
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
|
+
const client = new TradingView.Client({
|
|
9
|
+
/* Token is only needed if at least one indicator is
|
|
10
|
+
PRIVATE (if you have a paid TradingView account) */
|
|
11
|
+
token: 'YOUR_SESSION_ID_COOKIE',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const chart = new client.Session.Chart();
|
|
15
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
16
|
+
timeframe: 'D',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
TradingView.getPrivateIndicators('YOUR_SESSION_ID_COOKIE').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,121 @@
|
|
|
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
|
+
});
|
|
21
|
+
|
|
22
|
+
chart.onUpdate(() => {
|
|
23
|
+
if (!chart.periods[0]) return;
|
|
24
|
+
console.log('Last period', chart.periods[0]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/* (0s) Heikin Ashi chart */
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
console.log('\nSetting chart type to: HeikinAshi');
|
|
30
|
+
|
|
31
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
32
|
+
type: 'HeikinAshi',
|
|
33
|
+
timeframe: 'D',
|
|
34
|
+
});
|
|
35
|
+
}, 0);
|
|
36
|
+
|
|
37
|
+
/* (5s) Renko chart */
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
console.log('\nSetting chart type to: Renko');
|
|
40
|
+
|
|
41
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
42
|
+
type: 'Renko',
|
|
43
|
+
timeframe: 'D',
|
|
44
|
+
inputs: {
|
|
45
|
+
source: 'close',
|
|
46
|
+
sources: 'Close',
|
|
47
|
+
boxSize: 3,
|
|
48
|
+
style: 'ATR',
|
|
49
|
+
atrLength: 14,
|
|
50
|
+
wicks: true,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}, 5000);
|
|
54
|
+
|
|
55
|
+
/* (10s) Line Break chart */
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
console.log('\nSetting chart type to: LineBreak');
|
|
58
|
+
|
|
59
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
60
|
+
type: 'LineBreak',
|
|
61
|
+
timeframe: 'D',
|
|
62
|
+
inputs: {
|
|
63
|
+
source: 'close',
|
|
64
|
+
lb: 3,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}, 10000);
|
|
68
|
+
|
|
69
|
+
/* (15s) Kagi chart */
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
console.log('\nSetting chart type to: Kagi');
|
|
72
|
+
|
|
73
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
74
|
+
type: 'Kagi',
|
|
75
|
+
timeframe: 'D',
|
|
76
|
+
inputs: {
|
|
77
|
+
source: 'close',
|
|
78
|
+
style: 'ATR',
|
|
79
|
+
atrLength: 14,
|
|
80
|
+
reversalAmount: 1,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}, 15000);
|
|
84
|
+
|
|
85
|
+
/* (20s) Point & Figure chart */
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
console.log('\nSetting chart type to: PointAndFigure');
|
|
88
|
+
|
|
89
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
90
|
+
type: 'PointAndFigure',
|
|
91
|
+
timeframe: 'D',
|
|
92
|
+
inputs: {
|
|
93
|
+
sources: 'Close',
|
|
94
|
+
reversalAmount: 3,
|
|
95
|
+
boxSize: 1,
|
|
96
|
+
style: 'ATR',
|
|
97
|
+
atrLength: 14,
|
|
98
|
+
oneStepBackBuilding: false,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}, 20000);
|
|
102
|
+
|
|
103
|
+
/* (25s) Range chart */
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
console.log('\nSetting chart type to: Range');
|
|
106
|
+
|
|
107
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
108
|
+
type: 'Range',
|
|
109
|
+
timeframe: 'D',
|
|
110
|
+
inputs: {
|
|
111
|
+
range: 1,
|
|
112
|
+
phantomBars: false,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}, 25000);
|
|
116
|
+
|
|
117
|
+
/* (30s) Delete chart, close client */
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
console.log('\nClosing client...');
|
|
120
|
+
client.end();
|
|
121
|
+
}, 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,153 @@
|
|
|
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 user
|
|
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
|
+
let i = 0;
|
|
144
|
+
const execTest = () => {
|
|
145
|
+
if (tests[i + 1]) {
|
|
146
|
+
tests[(i += 1) - 1](execTest);
|
|
147
|
+
} else {
|
|
148
|
+
tests[(i += 1) - 1](() => {
|
|
149
|
+
console.log(`\nTests ${i}/${i} done !`);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
execTest();
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
chart.setMarket('BINANCE:BTCEUR', {
|
|
13
|
+
timeframe: 'W',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
|
|
17
|
+
TradingView.getIndicator('USER;8bbd8017fd3e4881bf91f4fea5e3d538').then((indic) => {
|
|
18
|
+
const STD = new chart.Study(indic);
|
|
19
|
+
|
|
20
|
+
STD.onError((...err) => {
|
|
21
|
+
console.log('Chart error:', ...err);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
STD.onReady(() => {
|
|
25
|
+
console.log('STD Loaded !');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
STD.onUpdate((changes) => {
|
|
29
|
+
// STD.graphic;
|
|
30
|
+
console.log('Update:', changes, STD.graphic);
|
|
31
|
+
// client.end();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
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));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const TradingView = require('../main');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This examples synchronously
|
|
5
|
+
fetches data from 3 indicators
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const client = new TradingView.Client();
|
|
9
|
+
const chart = new client.Session.Chart();
|
|
10
|
+
chart.setMarket('BINANCE:DOTUSDT');
|
|
11
|
+
|
|
12
|
+
function getIndicData(indicator) {
|
|
13
|
+
return new Promise((res) => {
|
|
14
|
+
const STD = new chart.Study(indicator);
|
|
15
|
+
|
|
16
|
+
console.log(`Getting "${indicator.description}"...`);
|
|
17
|
+
|
|
18
|
+
STD.onUpdate(() => {
|
|
19
|
+
res(STD.periods);
|
|
20
|
+
console.log(`"${indicator.description}" done !`);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
(async () => {
|
|
26
|
+
console.log('Getting all indicators...');
|
|
27
|
+
|
|
28
|
+
const indicData = await Promise.all([
|
|
29
|
+
await TradingView.getIndicator('PUB;3lEKXjKWycY5fFZRYYujEy8fxzRRUyF3'),
|
|
30
|
+
await TradingView.getIndicator('PUB;5nawr3gCESvSHQfOhrLPqQqT4zM23w3X'),
|
|
31
|
+
await TradingView.getIndicator('PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT'),
|
|
32
|
+
].map(getIndicData));
|
|
33
|
+
|
|
34
|
+
console.log(indicData);
|
|
35
|
+
console.log('All done !');
|
|
36
|
+
|
|
37
|
+
client.end();
|
|
38
|
+
})();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const TradingView = require('../main');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This example tests the searching
|
|
5
|
+
functions such as 'searchMarket'
|
|
6
|
+
and 'searchIndicator'
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
TradingView.searchMarket('BINANCE:').then((rs) => {
|
|
10
|
+
console.log('Found Markets:', rs);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
TradingView.searchIndicator('RSI').then((rs) => {
|
|
14
|
+
console.log('Found Indicators:', rs);
|
|
15
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const TradingView = require('../main');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This example creates a BTCEUR daily chart
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const client = new TradingView.Client(); // Creates a websocket client
|
|
8
|
+
|
|
9
|
+
const chart = new client.Session.Chart(); // Init a Chart session
|
|
10
|
+
|
|
11
|
+
chart.setMarket('BINANCE:BTCEUR', { // Set the market
|
|
12
|
+
timeframe: 'D',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
chart.onError((...err) => { // Listen for errors (can avoid crash)
|
|
16
|
+
console.error('Chart error:', ...err);
|
|
17
|
+
// Do something...
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
chart.onSymbolLoaded(() => { // When the symbol is successfully loaded
|
|
21
|
+
console.log(`Market "${chart.infos.description}" loaded !`);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
chart.onUpdate(() => { // When price changes
|
|
25
|
+
if (!chart.periods[0]) return;
|
|
26
|
+
console.log(`[${chart.infos.description}]: ${chart.periods[0].close} ${chart.infos.currency_id}`);
|
|
27
|
+
// Do something...
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Wait 5 seconds and set the market to BINANCE:ETHEUR
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
console.log('\nSetting market to BINANCE:ETHEUR...');
|
|
33
|
+
chart.setMarket('BINANCE:ETHEUR', {
|
|
34
|
+
timeframe: 'D',
|
|
35
|
+
});
|
|
36
|
+
}, 5000);
|
|
37
|
+
|
|
38
|
+
// Wait 10 seconds and set the timeframe to 15 minutes
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
console.log('\nSetting timeframe to 15 minutes...');
|
|
41
|
+
chart.setSeries('15');
|
|
42
|
+
}, 10000);
|
|
43
|
+
|
|
44
|
+
// Wait 15 seconds and set the chart type to "Heikin Ashi"
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
console.log('\nSetting the chart type to "Heikin Ashi"s...');
|
|
47
|
+
chart.setMarket('BINANCE:ETHEUR', {
|
|
48
|
+
timeframe: 'D',
|
|
49
|
+
type: 'HeikinAshi',
|
|
50
|
+
});
|
|
51
|
+
}, 15000);
|
|
52
|
+
|
|
53
|
+
// Wait 20 seconds and close the chart
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
console.log('\nClosing the chart...');
|
|
56
|
+
chart.delete();
|
|
57
|
+
}, 20000);
|
|
58
|
+
|
|
59
|
+
// Wait 25 seconds and close the client
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
console.log('\nClosing the client...');
|
|
62
|
+
client.end();
|
|
63
|
+
}, 25000);
|