Skip to content

Commit

Permalink
Merge pull request #250 from Mathieu2301/hotfix/inexistent-or-unsuppo…
Browse files Browse the repository at this point in the history
…rted-indicator-undefined-error

fix(getIndicator): use of an authenticated request
  • Loading branch information
Mathieu2301 authored Aug 8, 2024
2 parents d059938 + e892911 commit 5544817
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
18 changes: 15 additions & 3 deletions src/miscRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<PineIndicator>} 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) {
Expand Down Expand Up @@ -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,
);
},
}));
},
Expand Down

0 comments on commit 5544817

Please sign in to comment.