market-data-tradingview-ws 0.0.13 → 0.0.15
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 +10 -6
- package/lib/tradingView.js +7 -6
- package/package.json +1 -1
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
|
|
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 });
|
|
@@ -255,7 +260,7 @@ module.exports = class Client {
|
|
|
255
260
|
frame: data.frame,
|
|
256
261
|
increment: data.i,
|
|
257
262
|
symbolKey: data.symbolKey,
|
|
258
|
-
|
|
263
|
+
period: periods[period],
|
|
259
264
|
limit,
|
|
260
265
|
}),
|
|
261
266
|
);
|
|
@@ -288,7 +293,7 @@ module.exports = class Client {
|
|
|
288
293
|
frame: data.frame,
|
|
289
294
|
increment: data.i,
|
|
290
295
|
symbolKey: data.symbolKey,
|
|
291
|
-
|
|
296
|
+
period: periods[period],
|
|
292
297
|
}),
|
|
293
298
|
);
|
|
294
299
|
this.#charts.set({ key, data });
|
|
@@ -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.
|
|
328
|
-
|
|
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] });
|
package/lib/tradingView.js
CHANGED
|
@@ -226,10 +226,11 @@ class TradingView {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
quoteAddSymbol({ session, symbol }) {
|
|
229
|
-
|
|
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,
|
|
233
|
+
packet: { m: 'quote_add_symbols', p: [session, symbolString] }
|
|
233
234
|
});
|
|
234
235
|
}
|
|
235
236
|
|
|
@@ -267,7 +268,7 @@ class TradingView {
|
|
|
267
268
|
// frame - рамка или окно для данной серии
|
|
268
269
|
// increment - инкрементируемый номер изменений запрашиваемого графика в данном frame (таймефрейм)
|
|
269
270
|
createSeries({ chartSession, frame = 'sds_1', increment = 's1', symbolKey, period = '60', limit = 1000 }) {
|
|
270
|
-
// console.warn('createSeries', chartSession, frame, increment, symbolKey,
|
|
271
|
+
// console.warn('createSeries', chartSession, frame, increment, symbolKey, period, limit);
|
|
271
272
|
return this.formatWSPacket({
|
|
272
273
|
packet: { m: 'create_series', p: [chartSession, frame, increment, symbolKey, period, limit] },
|
|
273
274
|
});
|
|
@@ -284,10 +285,10 @@ class TradingView {
|
|
|
284
285
|
return this.formatWSPacket({ packet: { m: 'remove_study', p: [ session, st ] } });
|
|
285
286
|
}
|
|
286
287
|
|
|
287
|
-
modifySeries({ chartSession, frame = 'sds_1', increment = 's1', symbolKey,
|
|
288
|
-
// console.warn('modify_series', chartSession, frame, increment, symbolKey,
|
|
288
|
+
modifySeries({ chartSession, frame = 'sds_1', increment = 's1', symbolKey, period = '60' }) {
|
|
289
|
+
// console.warn('modify_series', chartSession, frame, increment, symbolKey, pariod, limit);
|
|
289
290
|
return this.formatWSPacket({
|
|
290
|
-
packet: { m: 'modify_series', p: [chartSession, frame, increment, symbolKey,
|
|
291
|
+
packet: { m: 'modify_series', p: [chartSession, frame, increment, symbolKey, period] },
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
|