Skip to content

Commit 1dd0535

Browse files
authored
Fix 'max number of studies per chart...' error (#272)
2 parents 7e5694f + 9ab3045 commit 1dd0535

21 files changed

+212
-120
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SESSION=... # Your sessionid cookie
2+
SIGNATURE=... # Your signature cookie

examples/AllPrivateIndicators.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ const TradingView = require('../main');
44
* This example creates a chart with all user's private indicators
55
*/
66

7-
if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
8-
if (!process.argv[3]) throw Error('Please specify your \'signature\' cookie');
7+
if (!process.env.SESSION || !process.env.SIGNATURE) {
8+
throw Error('Please set your sessionid and signature cookies');
9+
}
910

1011
const client = new TradingView.Client({
11-
token: process.argv[2],
12-
signature: process.argv[3],
12+
token: process.env.SESSION,
13+
signature: process.env.SIGNATURE,
1314
});
1415

1516
const chart = new client.Session.Chart();
1617
chart.setMarket('BINANCE:BTCEUR', {
1718
timeframe: 'D',
1819
});
1920

20-
TradingView.getPrivateIndicators(process.argv[2]).then((indicList) => {
21-
indicList.forEach(async (indic) => {
21+
(async () => {
22+
const indicList = await TradingView.getPrivateIndicators(process.argv[2]);
23+
24+
if (!indicList.length) {
25+
console.error('Your account has no private indicators');
26+
process.exit(0);
27+
}
28+
29+
for (const indic of indicList) {
2230
const privateIndic = await indic.get();
2331
console.log('Loading indicator', indic.name, '...');
2432

@@ -32,5 +40,5 @@ TradingView.getPrivateIndicators(process.argv[2]).then((indicList) => {
3240
console.log('Plot values', indicator.periods);
3341
console.log('Strategy report', indicator.strategyReport);
3442
});
35-
});
36-
});
43+
}
44+
})();

examples/BuiltInIndicator.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ const TradingView = require('../main');
66

77
const volumeProfile = new TradingView.BuiltInIndicator('VbPFixed@tv-basicstudies-241!');
88

9-
const AUTHENTICATED_INDICATORS = [
9+
const needAuth = ![
1010
'VbPFixed@tv-basicstudies-241',
1111
'VbPFixed@tv-basicstudies-241!',
1212
'Volume@tv-basicstudies-241',
13-
];
13+
].includes(volumeProfile.type);
1414

15-
if (!process.argv[2] && !AUTHENTICATED_INDICATORS.includes(volumeProfile.type)) {
16-
throw Error('Please specify your \'sessionid\' cookie');
15+
if (needAuth && (!process.env.SESSION || !process.env.SIGNATURE)) {
16+
throw Error('Please set your sessionid and signature cookies');
1717
}
1818

19-
const client = new TradingView.Client({
20-
token: process.argv[2],
21-
});
19+
const client = new TradingView.Client(
20+
needAuth
21+
? {
22+
token: process.env.SESSION,
23+
signature: process.env.SIGNATURE,
24+
}
25+
: {},
26+
);
2227

2328
const chart = new client.Session.Chart();
2429
chart.setMarket('BINANCE:BTCEUR', {

examples/CustomChartType.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ const TradingView = require('../main');
66
*/
77

88
const client = new TradingView.Client({
9-
/* Token is only required if you want to use intraday
10-
timeframes (if you have a paid TradingView account) */
11-
token: process.argv[2],
9+
/*
10+
Token and signature are only required if you want to use
11+
intraday timeframes (if you have a paid TradingView account)
12+
*/
13+
token: process.env.SESSION,
14+
signature: process.env.SIGNATURE,
1215
});
1316

1417
const chart = new client.Session.Chart();

examples/CustomTimeframe.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ const TradingView = require('../main');
44
* This example tests custom timeframes like 1 second
55
*/
66

7-
if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
7+
if (!process.env.SESSION || !process.env.SIGNATURE) {
8+
throw Error('Please set your sessionid and signature cookies');
9+
}
810

911
const client = new TradingView.Client({
10-
token: process.argv[2],
12+
token: process.env.SESSION,
13+
signature: process.env.SIGNATURE,
1114
});
1215

1316
const chart = new client.Session.Chart();

examples/Errors.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ const TradingView = require('../main');
44
* This example tests many types of errors
55
*/
66

7-
const client = new TradingView.Client(); // Creates a websocket client
7+
if (!process.env.SESSION || !process.env.SIGNATURE) {
8+
throw Error('Please set your sessionid and signature cookies');
9+
}
10+
11+
// Creates a websocket client
12+
const client = new TradingView.Client({
13+
token: process.env.SESSION,
14+
signature: process.env.SIGNATURE,
15+
});
816

917
const tests = [
1018
(next) => { /* Testing "Credentials error" */

examples/FakeReplayMode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const client = new Client();
1111
const chart = new client.Session.Chart();
1212

1313
chart.setMarket('BINANCE:BTCEUR', {
14-
timeframe: 'D',
14+
timeframe: '240',
1515
range: -1, // Range is negative, so 'to' means 'from'
1616
to: Math.round(Date.now() / 1000) - 86400 * 7, // Seven days before now
1717
// to: 1600000000,
@@ -31,10 +31,10 @@ chart.onUpdate(async () => {
3131

3232
console.log('Next ->', times[0]);
3333

34-
if ((times[0] + 86400) * 1000 > Date.now()) {
34+
if (times[0] > ((Date.now() / 1000) - 86400 * 1)) {
3535
await client.end();
3636
console.log('Done !', times.length);
3737
}
3838

39-
chart.fetchMore(-1);
39+
chart.fetchMore(-2);
4040
});

examples/FromToData.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ const TradingView = require('../main');
55
* of candles before or after a timestamp
66
*/
77

8-
const client = new TradingView.Client();
8+
if (!process.env.SESSION || !process.env.SIGNATURE) {
9+
throw Error('Please set your sessionid and signature cookies');
10+
}
11+
12+
const client = new TradingView.Client({
13+
token: process.env.SESSION,
14+
signature: process.env.SIGNATURE,
15+
});
916

1017
const chart = new client.Session.Chart();
1118
chart.setMarket('BINANCE:BTCEUR', {
1219
timeframe: '240',
1320
range: 2, // Can be positive to get before or negative to get after
14-
to: 1600000000,
21+
to: 1700000000,
1522
});
1623

1724
// This works with indicators

examples/GetDrawings.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ const TradingView = require('../main');
55
*/
66

77
// First parameter must be the layoutID
8-
// (if the layout is private) Second parameter must be the sessionid cookie
9-
// (if the layout is private) Third parameter must be the userid (you can use getUser function)
8+
// If the layout is private:
9+
// - Second parameter must be the userid (you can use getUser function)
10+
// - You should provide your sessionid and signature cookies in .env file
1011

1112
if (!process.argv[2]) throw Error('Please specify a layoutID');
1213

1314
TradingView.getDrawings(process.argv[2], null, {
14-
session: process.argv[3],
15-
id: process.argv[4],
15+
session: process.env.SESSION,
16+
signature: process.env.SIGNATURE,
17+
id: process.argv[3],
1618
}).then((drawings) => {
1719
console.log(`Found ${drawings.length} drawings:`, drawings.map((d) => ({
1820
id: d.id,

examples/GraphicIndicator.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ const TradingView = require('../main');
55
* as 'lines', 'labels', 'boxes', 'tables', 'polygons', etc...
66
*/
77

8-
const client = new TradingView.Client();
8+
if (!process.env.SESSION || !process.env.SIGNATURE) {
9+
throw Error('Please set your sessionid and signature cookies');
10+
}
11+
12+
const client = new TradingView.Client({
13+
token: process.env.SESSION,
14+
signature: process.env.SIGNATURE,
15+
});
916

1017
const chart = new client.Session.Chart();
1118
chart.setMarket('BINANCE:BTCEUR', {
@@ -29,7 +36,7 @@ TradingView.getIndicator('STD;Zig_Zag').then((indic) => {
2936
STD.onUpdate(() => {
3037
console.log('Graphic data:', STD.graphic);
3138
// console.log('Tables:', changes, STD.graphic.tables);
32-
// console.log('Cells', STD.graphic.tables[0].cells());
39+
// console.log('Cells:', STD.graphic.tables[0].cells());
3340
client.end();
3441
});
3542
});

0 commit comments

Comments
 (0)