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 +7 -11
- package/lib/tradingView.js +6 -8
- package/package.json +1 -1
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
|
-
|
|
766
|
+
|
|
774
767
|
const sent = this.#send(tv.quoteRemoveSymbols({ session: key, symbol: normalized }));
|
|
775
|
-
|
|
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 }) {
|
package/lib/tradingView.js
CHANGED
|
@@ -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
|
-
|
|
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 }) {
|