Skip to content

Commit 5544817

Browse files
authored
Merge pull request #250 from Mathieu2301/hotfix/inexistent-or-unsupported-indicator-undefined-error
fix(getIndicator): use of an authenticated request
2 parents d059938 + e892911 commit 5544817

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mathieuc/tradingview",
3-
"version": "3.4.3",
3+
"version": "3.4.4",
44
"description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !",
55
"main": "main.js",
66
"scripts": {

src/miscRequests.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,21 @@ module.exports = {
243243
* @function getIndicator
244244
* @param {string} id Indicator ID (Like: PUB;XXXXXXXXXXXXXXXXXXXXX)
245245
* @param {'last' | string} [version] Wanted version of the indicator
246+
* @param {string} [session] User 'sessionid' cookie
247+
* @param {string} [signature] User 'sessionid_sign' cookie
246248
* @returns {Promise<PineIndicator>} Indicator
247249
*/
248-
async getIndicator(id, version = 'last') {
250+
async getIndicator(id, version = 'last', session = '', signature = '') {
249251
const indicID = id.replace(/ |%/g, '%25');
250252

251253
const { data } = await axios.get(
252254
`https://pine-facade.tradingview.com/pine-facade/translate/${indicID}/${version}`,
253-
{ validateStatus },
255+
{
256+
validateStatus,
257+
headers: {
258+
cookie: `${session ? `sessionid=${session};` : ''}${signature ? `sessionid_sign=${signature};` : ''}`,
259+
},
260+
},
254261
);
255262

256263
if (!data.success || !data.result.metaInfo || !data.result.metaInfo.inputs) {
@@ -455,7 +462,12 @@ module.exports = {
455462
source: ind.scriptSource,
456463
type: (ind.extra && ind.extra.kind) ? ind.extra.kind : 'study',
457464
get() {
458-
return module.exports.getIndicator(ind.scriptIdPart, ind.version);
465+
return module.exports.getIndicator(
466+
ind.scriptIdPart,
467+
ind.version,
468+
session,
469+
signature,
470+
);
459471
},
460472
}));
461473
},

0 commit comments

Comments
 (0)