@mathieuc/tradingview 3.5.0 → 3.5.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mathieuc/tradingview",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
4
4
  "description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !",
5
5
  "main": "main.js",
6
6
  "scripts": {
package/src/client.js CHANGED
@@ -266,6 +266,10 @@ module.exports = class Client {
266
266
  this.#handleEvent('disconnected');
267
267
  });
268
268
 
269
+ this.#ws.on('error', (err) => {
270
+ this.#handleError('WebSocket error:', err.message);
271
+ });
272
+
269
273
  this.#ws.on('message', (data) => this.#parsePacket(data));
270
274
  }
271
275
 
@@ -133,9 +133,10 @@ module.exports = {
133
133
  * | 'futures' | 'forex' | 'cfd'
134
134
  * | 'crypto' | 'index' | 'economic'
135
135
  * } [filter] Caterogy filter
136
+ * @param {number} offset Pagination offset
136
137
  * @returns {Promise<SearchMarketResult[]>} Search results
137
138
  */
138
- async searchMarketV3(search, filter = '') {
139
+ async searchMarketV3(search, filter = '', offset = 0) {
139
140
  const splittedSearch = search.toUpperCase().replace(/ /g, '+').split(':');
140
141
 
141
142
  const request = await axios.get(
@@ -148,6 +149,7 @@ module.exports = {
148
149
  ),
149
150
  text: splittedSearch.pop(),
150
151
  search_type: filter,
152
+ start: offset,
151
153
  },
152
154
  headers: {
153
155
  origin: 'https://www.tradingview.com',
@@ -160,7 +162,7 @@ module.exports = {
160
162
 
161
163
  return data.symbols.map((s) => {
162
164
  const exchange = s.exchange.split(' ')[0];
163
- const id = `${exchange.toUpperCase()}:${s.symbol}`;
165
+ const id = s.prefix ? `${s.prefix}:${s.symbol}` : `${exchange.toUpperCase()}:${s.symbol}`;
164
166
 
165
167
  return {
166
168
  id,
@@ -428,10 +430,11 @@ module.exports = {
428
430
  * @returns {Promise<User>} Token
429
431
  */
430
432
  async getUser(session, signature = '', location = 'https://www.tradingview.com/') {
431
- const { data } = await axios.get(location, {
433
+ const { data, headers } = await axios.get(location, {
432
434
  headers: {
433
435
  cookie: genAuthCookies(session, signature),
434
436
  },
437
+ maxRedirects: 0,
435
438
  validateStatus,
436
439
  });
437
440
 
@@ -457,6 +460,10 @@ module.exports = {
457
460
  };
458
461
  }
459
462
 
463
+ if (headers.location !== location) {
464
+ return this.getUser(session, signature, headers.location);
465
+ }
466
+
460
467
  throw new Error('Wrong or expired sessionid/signature');
461
468
  },
462
469