From 144479b89cefbabc838aac02d449be7c4ce2c828 Mon Sep 17 00:00:00 2001 From: Oguzhan Date: Mon, 27 Oct 2025 02:17:45 +0300 Subject: [PATCH 1/3] add: max redirect 5 limit for infinity loops --- src/miscRequests.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/miscRequests.js b/src/miscRequests.js index cfb83340..147ecd9d 100644 --- a/src/miscRequests.js +++ b/src/miscRequests.js @@ -427,7 +427,11 @@ module.exports = { * @param {string} [location] Auth page location (For france: https://fr.tradingview.com/) * @returns {Promise} Token */ - async getUser(session, signature = '', location = 'https://www.tradingview.com/') { + async getUser(session, signature = '', location = 'https://www.tradingview.com/', redirectCount = 0) { + if (redirectCount > 5) { + throw new Error('Too many redirects - invalid session/signature'); + } + const { data, headers } = await axios.get(location, { headers: { cookie: genAuthCookies(session, signature), @@ -459,7 +463,7 @@ module.exports = { } if (headers.location !== location) { - return this.getUser(session, signature, headers.location); + return this.getUser(session, signature, headers.location, redirectCount + 1); } throw new Error('Wrong or expired sessionid/signature'); From 8215fb90c9e764a4d8f9e29a1cdf740bd45ef994 Mon Sep 17 00:00:00 2001 From: Oguzhan Date: Mon, 27 Oct 2025 02:18:39 +0300 Subject: [PATCH 2/3] add: more headers for waf bypass --- src/client.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index c38aa6a3..d32ccee8 100644 --- a/src/client.js +++ b/src/client.js @@ -158,6 +158,7 @@ module.exports = class Client { if (!this.isOpen) return; protocol.parseWSPacket(str).forEach((packet) => { + console.dir(packet, { depth: null }); if (global.TW_DEBUG) console.log('§90§30§107 CLIENT §0 PACKET', packet); if (typeof packet === 'number') { // Ping this.#ws.send(protocol.formatWSPacket(`~h~${packet}`)); @@ -228,8 +229,14 @@ module.exports = class Client { if (clientOptions.DEBUG) global.TW_DEBUG = clientOptions.DEBUG; const server = clientOptions.server || 'data'; - this.#ws = new WebSocket(`wss://${server}.tradingview.com/socket.io/websocket?type=chart`, { + this.#ws = new WebSocket(`wss://${server}.tradingview.com/socket.io/websocket?from=chart&type=chart`, { origin: 'https://www.tradingview.com', + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', + 'Accept-Language': 'en-US,en;q=0.9', + 'Cache-Control': 'no-cache', + Pragma: 'no-cache', + }, }); if (clientOptions.token) { From 9205c6548fbc293874786aeac15ebc3f41357a89 Mon Sep 17 00:00:00 2001 From: Oguzhan Date: Mon, 27 Oct 2025 02:20:58 +0300 Subject: [PATCH 3/3] remove: console dir --- src/client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.js b/src/client.js index d32ccee8..feb41e20 100644 --- a/src/client.js +++ b/src/client.js @@ -158,7 +158,6 @@ module.exports = class Client { if (!this.isOpen) return; protocol.parseWSPacket(str).forEach((packet) => { - console.dir(packet, { depth: null }); if (global.TW_DEBUG) console.log('§90§30§107 CLIENT §0 PACKET', packet); if (typeof packet === 'number') { // Ping this.#ws.send(protocol.formatWSPacket(`~h~${packet}`));