market-data-tradingview-ws 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/client.js +12 -6
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -545,7 +545,7 @@ module.exports = class Client {
545
545
  });
546
546
  }
547
547
 
548
- async connect({ url, options = {}, result, sessionid, sessionidsign, tvecuid, imageurl, proxy }) {
548
+ async connect({ url, options = {}, result, sessionid, sessionidsign, tvecuid, imageurl, proxy, token }) {
549
549
  if (this.#isOpen()) return 'open';
550
550
  if (this.#connectPromise) return this.#connectPromise;
551
551
  if (typeof result !== 'function') throw new TypeError('result callback must be a function');
@@ -555,7 +555,7 @@ module.exports = class Client {
555
555
  const controller = new AbortController();
556
556
  this.#connectAbortController = controller;
557
557
 
558
- this.#connectPromise = this.#connectInternal({ url, options, result, sessionid, sessionidsign, tvecuid, imageurl, proxy, generation, signal: controller.signal });
558
+ this.#connectPromise = this.#connectInternal({ url, options, result, sessionid, sessionidsign, tvecuid, imageurl, proxy, token, generation, signal: controller.signal });
559
559
 
560
560
  try {
561
561
  return await this.#connectPromise;
@@ -565,18 +565,24 @@ module.exports = class Client {
565
565
  }
566
566
  }
567
567
 
568
- async #connectInternal({ url, options, result, sessionid, sessionidsign, tvecuid, imageurl, proxy, generation, signal }) {
568
+ async #connectInternal({ url, options, result, sessionid, sessionidsign, tvecuid, imageurl, proxy, token, generation, signal }) {
569
569
  this.#result = result;
570
570
  this.#proxy = proxy || null;
571
571
 
572
- this.#token = await this.getToken({ sessionId: sessionid, sessionIdSign: sessionidsign, tvEcuid: tvecuid, imageUrl: imageurl, proxy, signal });
573
-
572
+ if (typeof token === 'string' && token.length > 10) {
573
+ this.#token = token;
574
+ } else {
575
+ this.#token = await this.getToken({ sessionId: sessionid, sessionIdSign: sessionidsign, tvEcuid: tvecuid, imageUrl: imageurl, proxy, signal });
576
+ }
577
+
574
578
  this.#assertConnectGeneration(generation);
575
579
 
576
580
  this.#sessionid = sessionid;
577
581
  this.#sessionidsign = sessionidsign;
578
582
 
579
- if (!this.#token || this.#token.length <= 10) throw new Error('Invalid TradingView auth token');
583
+ if (!this.#token || this.#token.length <= 10) {
584
+ throw new Error('Invalid TradingView auth token');
585
+ }
580
586
 
581
587
  this.#resetRemoteState();
582
588
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "market-data-tradingview-ws",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "marketData from Tradingview ws",
5
5
  "main": "index.js",
6
6
  "scripts": {