From b74e45e9f789976f253bfe0ad7829e25c6e35740 Mon Sep 17 00:00:00 2001 From: Mathieu Colmon Date: Mon, 18 Jul 2022 00:39:48 +0200 Subject: [PATCH] Add server selection feature --- package.json | 2 +- src/client.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bd32d5c..7d987b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mathieuc/tradingview", - "version": "3.3.0", + "version": "3.3.1", "description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !", "main": "main.js", "scripts": { diff --git a/src/client.js b/src/client.js index 7a0a3e4..56eece2 100644 --- a/src/client.js +++ b/src/client.js @@ -215,6 +215,7 @@ module.exports = class Client { * @typedef {Object} ClientOptions * @prop {string} [token] User auth token (in 'sessionid' cookie) * @prop {boolean} [DEBUG] Enable debug mode + * @prop {'data' | 'prodata' | 'widgetdata'} [server] Server type */ /** Client object @@ -223,7 +224,8 @@ module.exports = class Client { constructor(clientOptions = {}) { if (clientOptions.DEBUG) global.TW_DEBUG = clientOptions.DEBUG; - this.#ws = new WebSocket('wss://data.tradingview.com/socket.io/websocket', { + const server = clientOptions.server || 'data'; + this.#ws = new WebSocket(`wss://${server}.tradingview.com/socket.io/websocket`, { origin: 'https://s.tradingview.com', });