π Get real-time stocks from TradingView
TypeScript backtestingbacktesting-trading-strategiesbitcoinchartscryptocryptocurrencyethereumrealtime-stocksstocksstocks-apistocks-pricestradingtradingviewtradingview-apitradingview-indicatortradingview-replaytradingview-scraper
Fixes
Mathieu Colmonfb7fd104d3f3
diff --git a/examples/AllPrivateIndicators.js b/examples/AllPrivateIndicators.jsindex a7cca85..811b09d 100644--- a/examples/AllPrivateIndicators.js+++ b/examples/AllPrivateIndicators.js@@ -5,10 +5,10 @@ const TradingView = require('../main');all user's private indicators*/+if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');+const client = new TradingView.Client({- /* Token is only needed if at least one indicator is- PRIVATE (if you have a paid TradingView account) */- token: 'YOUR_SESSION_ID_COOKIE',+ token: process.argv[2],});const chart = new client.Session.Chart();@@ -16,7 +16,7 @@ chart.setMarket('BINANCE:BTCEUR', {timeframe: 'D',});-TradingView.getPrivateIndicators('YOUR_SESSION_ID_COOKIE').then((indicList) => {+TradingView.getPrivateIndicators(process.argv[2]).then((indicList) => {indicList.forEach(async (indic) => {const privateIndic = await indic.get();console.log('Loading indicator', indic.name, '...');diff --git a/examples/CustomChartType.js b/examples/CustomChartType.jsindex 9385c6b..ab88355 100644--- a/examples/CustomChartType.js+++ b/examples/CustomChartType.js@@ -17,6 +17,7 @@ const chart = new client.Session.Chart();chart.onError((...err) => {console.log('Chart error:', ...err);+ process.exit(1);});chart.onUpdate(() => {diff --git a/examples/Errors.js b/examples/Errors.jsindex 9b9bdd2..fed05cb 100644--- a/examples/Errors.js+++ b/examples/Errors.js@@ -61,7 +61,7 @@ const tests = [timeframe: '20', // Set a custom timeframe/*Timeframe '20' isn't available because we are- not logged in as a premium TradingView user+ not logged in as a premium TradingView account*/});},@@ -140,14 +140,8 @@ const tests = [},];-let i = 0;-const execTest = () => {- if (tests[i + 1]) {- tests[(i += 1) - 1](execTest);- } else {- tests[(i += 1) - 1](() => {- console.log(`\nTests ${i}/${i} done !`);- });- }-};-execTest();+(async () => {+ // eslint-disable-next-line no-restricted-syntax, no-await-in-loop+ for (const t of tests) await new Promise(t);+ console.log(`\nTests ${tests.length}/${tests.length} done !`);+})();diff --git a/src/chart/session.js b/src/chart/session.jsindex 155c1c1..fb35ace 100644--- a/src/chart/session.js+++ b/src/chart/session.js@@ -369,14 +369,14 @@ module.exports = (client) => class ChartSession {]);}- const complex = (options.type && ChartTypes[options.type]) || options.replay;+ const complex = options.type || options.replay;const chartInit = complex ? {} : symbolInit;if (complex) {if (options.replay) chartInit.replay = this.#replaySessionID;chartInit.symbol = symbolInit;- if (options.type) chartInit.type = ChartTypes[options.type];- if (options.inputs) chartInit.inputs = { ...options.inputs };+ chartInit.type = ChartTypes[options.type];+ if (options.type) chartInit.inputs = { ...options.inputs };}this.#currentSeries += 1;diff --git a/src/client.js b/src/client.jsindex 10853eb..0204001 100644--- a/src/client.js+++ b/src/client.js@@ -273,7 +273,7 @@ module.exports = class Client {*/end() {return new Promise((cb) => {- this.#ws.close();+ if (this.#ws.readyState) this.#ws.close();cb();});}