market-data-tradingview-ws 2.1.1 → 2.1.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/lib/client.js CHANGED
@@ -77,7 +77,6 @@ module.exports = class Client {
77
77
  },
78
78
  getBySymbolPeriod({ symbol, period }) {
79
79
  for (let key of Object.keys(this.values)) {
80
- // console.warn(symbol, period, key, this.values[key], this.values[key].symbol === symbol, this.values[key].period === period);
81
80
  if (this.values[key].symbol === symbol && parseInt(this.values[key].period) === parseInt(period) && !this.values[key].deleted) {
82
81
  return key;
83
82
  }
@@ -319,19 +318,13 @@ module.exports = class Client {
319
318
  if (!socket || socket.readyState !== WebSocket.OPEN) return false;
320
319
 
321
320
  if (socket.bufferedAmount > this.#maxBufferedAmount) {
322
- this.#emit('error', {
323
- type: 'ws_backpressure',
324
- bufferedAmount: socket.bufferedAmount,
325
- });
321
+ this.#emit('error', { type: 'ws_backpressure', bufferedAmount: socket.bufferedAmount });
326
322
  return false;
327
323
  }
328
324
 
329
325
  socket.send(data, (error) => {
330
326
  if (!error) return;
331
- this.#emit('error', {
332
- type: 'ws_send_error',
333
- message: error.message,
334
- });
327
+ this.#emit('error', { type: 'ws_send_error', message: error.message });
335
328
  });
336
329
 
337
330
  return true;
@@ -770,9 +763,12 @@ module.exports = class Client {
770
763
  const normalized = symbol.trim();
771
764
  const key = this.#quotes.getBySymbol({ symbol: normalized });
772
765
  if (!key) return 'unlisted';
773
- this.#quotes.delete({ key, symbol: normalized });
766
+
774
767
  const sent = this.#send(tv.quoteRemoveSymbols({ session: key, symbol: normalized }));
775
- return sent ? 'delete' : 'not_connected';
768
+ if (!sent) return 'not_connected';
769
+
770
+ this.#quotes.delete({ key, symbol: normalized });
771
+ return 'delete';
776
772
  }
777
773
 
778
774
  #reuseDeletedChartSession({ key, symbol, period, limit }) {
@@ -256,18 +256,16 @@ class TradingView {
256
256
  });
257
257
  }
258
258
 
259
+ quoteSymbol({ symbol }) {
260
+ return symbol.split(':')[0] === 'BINANCE' ? symbol : '={"adjustment":"splits","currency-id":"USD","symbol":"' + symbol + '"}';
261
+ }
262
+
259
263
  quoteAddSymbol({ session, symbol }) {
260
- const symbolString =
261
- symbol.split(':')[0] === 'BINANCE' ? symbol : '={"adjustment":"splits","currency-id":"USD","symbol":"' + symbol + '"}';
262
- // console.log('quoteAddSymbol', session, symbol, symbolString);
263
- // return this.formatWSPacket({ packet: { m: 'quote_add_symbols', p: [session, symbol] } });
264
- return this.formatWSPacket({
265
- packet: { m: 'quote_add_symbols', p: [session, symbolString] },
266
- });
264
+ return this.formatWSPacket({ packet: { m: 'quote_add_symbols', p: [session, this.quoteSymbol({ symbol })] }});
267
265
  }
268
266
 
269
267
  quoteRemoveSymbols({ session, symbol }) {
270
- return this.formatWSPacket({ packet: { m: 'quote_remove_symbols', p: [session, symbol] } });
268
+ return this.formatWSPacket({ packet: { m: 'quote_remove_symbols', p: [session, this.quoteSymbol({ symbol })] }});
271
269
  }
272
270
 
273
271
  quoteRemoveSeries({ session }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "market-data-tradingview-ws",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "marketData from Tradingview ws",
5
5
  "main": "index.js",
6
6
  "scripts": {