market-data-tradingview-ws 0.0.13 → 0.0.14

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/lib/client.js CHANGED
@@ -17,6 +17,11 @@ const periods = {
17
17
  2592000: '1M',
18
18
  };
19
19
 
20
+ const extractJSON = (str) => {
21
+ const match = str.match(/\{.*?\}/s);
22
+ return match ? JSON.parse(match[0]) : null;
23
+ }
24
+
20
25
  let ws = null;
21
26
 
22
27
  module.exports = class Client {
@@ -237,7 +242,7 @@ module.exports = class Client {
237
242
  }
238
243
  // console.warn('modules addChartSymbol1', symbol, period, limit, key);
239
244
  const deleted = this.#charts.getDeleted();
240
- if (deleted !== null && deleted.limit >= limit) return this.updateChartSymbol({ symbol, period, limit, last: { symbol: deleted.symbol, period: parseInt(deleted.period) }});
245
+ if (deleted !== null && deleted.limit === limit) return this.updateChartSymbol({ symbol, period, limit, last: { symbol: deleted.symbol, period: parseInt(deleted.period) }});
241
246
 
242
247
  key = this.createChartSession();
243
248
  const data = this.#charts.get({ key });
@@ -324,9 +329,8 @@ module.exports = class Client {
324
329
  } else if (packet.type === 'qsd') {
325
330
  send = packet.data[1].v;
326
331
  name = send.bid === undefined && send.ask === undefined ? 'data' : 'levelI';
327
- // console.warn(packet.data[1]);
328
- // console.log(JSON.parse(packet.data[1].n.substring(1)).symbol);
329
- send.symbol = JSON.parse(packet.data[1].n.substring(1)).symbol;
332
+ // console.log(packet.data[1].n);
333
+ send.symbol =(extractJSON(packet.data[1].n) || {symbol: packet.data[1].n}).symbol;
330
334
  result(name, send);
331
335
  } else if (['du', 'timescale_update'].includes(packet.type)) {
332
336
  session = this.#charts.get({ key: packet.data[0] });
@@ -226,10 +226,11 @@ class TradingView {
226
226
  }
227
227
 
228
228
  quoteAddSymbol({ session, symbol }) {
229
- // console.log('quoteAddSymbol', session, symbol);
229
+ const symbolString = symbol.split(':')[0] === 'BINANCE' ? symbol : '={"adjustment":"splits","currency-id":"USD","symbol":"' + symbol + '"}';
230
+ // console.log('quoteAddSymbol', session, symbol, symbolString);
230
231
  // return this.formatWSPacket({ packet: { m: 'quote_add_symbols', p: [session, symbol] } });
231
232
  return this.formatWSPacket({
232
- packet: { m: 'quote_add_symbols', p: [session, '={"adjustment":"splits","currency-id":"USD","symbol":"' + symbol + '"}'] }
233
+ packet: { m: 'quote_add_symbols', p: [session, symbolString] }
233
234
  });
234
235
  }
235
236
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "market-data-tradingview-ws",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "marketData from Tradingview ws",
5
5
  "main": "index.js",
6
6
  "scripts": {