Mathieu2301 / TradingView-API

📈 Get real-time stocks from TradingView
1.61k stars 354 forks source link

invite-only indicator says study_not_auth #162

Closed damian123 closed 1 year ago

damian123 commented 1 year ago

The code throws an exception when I create a study object with a invite-only indicator The error says: study_not_auth:Script@tv-scripting-417 undefined

I installed the tradingview-api npm i github:Mathieu2301/TradingView-API

Here is my code:

var TradingView = require("@mathieuc/tradingview")
console.log(TradingView.version);

TradingView.loginUser("<USERNAME>", "<PASSWORD>", false).then((user) => {
    const client = new TradingView.Client();

  // Find indicators
  TradingView.searchIndicator('-- UCTS').then((rs) => {
    for(let i in rs) {
      console.log('Found Indicators:', rs[i]);
  }    
  });

  const chart = new client.Session.Chart();
    chart.setMarket('BINANCE:BTCUSDT', {
    timeframe: '60',
    currency: 'USD',
  });

  TradingView.getIndicator('PUB;ryMeUolWwdyo9F3MNleMvPPmoSDpGY4n').then(async (indic) => {

    console.log(`Loading '${indic.description}' study...`);

    const study = new chart.Study(indic);
  });
}).catch((err) => {
  console.error('Login error:', err.message);
});

The output says:

C:\Program Files\nodejs\node.exe .\StrategyReport.js
undefined
StrategyReport.js:4
Found Indicators: {id: 'PUB;dAR918iTVflO921cnt23su55t5M6AhXm', version: '129', name: '-- Ultimate Crypto Trading Strategy -- By @CryptoNTez -- ', author: {…}, image: 'F9aop8za', …}
Found Indicators: {id: 'PUB;sy0X3Q6QeQxv8dbyzlEzHKUiNSMxBAW8', version: '23', name: 'UCTS Trend Finder -- By @CryptoNTez', author: {…}, image: 'OpdpCaWX', …}
Found Indicators: {id: 'PUB;ryMeUolWwdyo9F3MNleMvPPmoSDpGY4n', version: '148', name: '-- Ultimate Crypto Trading Strategy -- Backtesting version', author: {…}, image: 'P9mXRgNX', …}
Loading '-- UCTS -- By @CryptoNTez -- v4 -- Strategy' study...
StrategyReport.js:37
study_not_auth:Script@tv-scripting-417 undefined

Environment:

Additional context: I am authorized for this script and it works in the Browser. I tried to load but public IDs but they both fail.

Mathieu2301 commented 1 year ago
const client = new TradingView.Client({
  token: user.session,
});
damian123 commented 1 year ago

@Mathieu2301 this works! Thank you.