From ec4431ffbc0772dccf5800ba4596884726edb202 Mon Sep 17 00:00:00 2001 From: Mathieu Colmon Date: Thu, 8 Aug 2024 14:12:59 +0200 Subject: [PATCH 1/2] Handle authentication in getIndicator function --- src/miscRequests.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/miscRequests.js b/src/miscRequests.js index b1af288..d358616 100644 --- a/src/miscRequests.js +++ b/src/miscRequests.js @@ -243,14 +243,21 @@ module.exports = { * @function getIndicator * @param {string} id Indicator ID (Like: PUB;XXXXXXXXXXXXXXXXXXXXX) * @param {'last' | string} [version] Wanted version of the indicator + * @param {string} [session] User 'sessionid' cookie + * @param {string} [signature] User 'sessionid_sign' cookie * @returns {Promise} Indicator */ - async getIndicator(id, version = 'last') { + async getIndicator(id, version = 'last', session = '', signature = '') { const indicID = id.replace(/ |%/g, '%25'); const { data } = await axios.get( `https://pine-facade.tradingview.com/pine-facade/translate/${indicID}/${version}`, - { validateStatus }, + { + validateStatus, + headers: { + cookie: `${session ? `sessionid=${session};` : ''}${signature ? `sessionid_sign=${signature};` : ''}`, + }, + }, ); if (!data.success || !data.result.metaInfo || !data.result.metaInfo.inputs) { @@ -455,7 +462,12 @@ module.exports = { source: ind.scriptSource, type: (ind.extra && ind.extra.kind) ? ind.extra.kind : 'study', get() { - return module.exports.getIndicator(ind.scriptIdPart, ind.version); + return module.exports.getIndicator( + ind.scriptIdPart, + ind.version, + session, + signature, + ); }, })); }, From e892911f91037d13ea9de1aeded47fbc06b158d9 Mon Sep 17 00:00:00 2001 From: Mathieu Colmon Date: Thu, 8 Aug 2024 14:13:10 +0200 Subject: [PATCH 2/2] Bump to 3.4.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d068bb0..0f24960 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mathieuc/tradingview", - "version": "3.4.3", + "version": "3.4.4", "description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !", "main": "main.js", "scripts": {