market-data-tradingview-ws 0.1.0 → 0.1.1
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 +5 -4
- package/lib/tradingView.js +16 -14
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -148,6 +148,7 @@ module.exports = class Client {
|
|
|
148
148
|
async connect({ url, options, result, sessionid, sessionidsign, tvecuid, imageurl }) {
|
|
149
149
|
try {
|
|
150
150
|
this.#token = await this.getToken({ sessionid, sessionidsign, tvecuid, imageurl });
|
|
151
|
+
// console.info('Token:', this.#token);
|
|
151
152
|
this.#sessionid = sessionid;
|
|
152
153
|
this.#sessionidsign = sessionidsign;
|
|
153
154
|
|
|
@@ -244,10 +245,10 @@ module.exports = class Client {
|
|
|
244
245
|
return 'delete';
|
|
245
246
|
}
|
|
246
247
|
|
|
247
|
-
addChartSymbol({ symbol, period, limit }) {
|
|
248
|
-
if (!symbol || typeof symbol !== 'string') throw new Error('Invalid symbol parameter');
|
|
249
|
-
if (!period || typeof period !== 'number') throw new Error('Invalid period parameter');
|
|
250
|
-
if (!limit || typeof limit !== 'number') throw new Error('Invalid limit parameter');
|
|
248
|
+
addChartSymbol({ symbol, period, limit = 1500 }) {
|
|
249
|
+
if (!symbol || typeof symbol !== 'string') console.debug('Invalid symbol parameter', symbol); // throw new Error('Invalid symbol parameter', symbol);
|
|
250
|
+
if (!period || typeof period !== 'number') console.debug('Invalid period parameter', period); // throw new Error('Invalid period parameter', period);
|
|
251
|
+
if (!limit || typeof limit !== 'number') console.debug('Invalid limit parameter', limit); // throw new Error('Invalid limit parameter', limit);
|
|
251
252
|
|
|
252
253
|
let key = this.#charts.getBySymbolPeriod({ symbol, period });
|
|
253
254
|
if (key) {
|
package/lib/tradingView.js
CHANGED
|
@@ -46,22 +46,24 @@ class TradingView {
|
|
|
46
46
|
|
|
47
47
|
async getToken({ sessionid, sessionidsign, tvecuid, imageurl }) {
|
|
48
48
|
const url = urlRuTV + '/chart/' + imageurl;
|
|
49
|
+
const cookie = 'tv_ecuid=' + tvecuid + '; sessionid=' + sessionid + '; sessionid_sign=' + sessionidsign;
|
|
49
50
|
const headers = {
|
|
50
|
-
'accept': 'text/html
|
|
51
|
-
'
|
|
52
|
-
'cache-control': 'max-age=0',
|
|
53
|
-
'upgrade-insecure-requests': '1',
|
|
54
|
-
'cookie': 'tv_ecuid=' + tvecuid + '; sessionid=' + sessionid + '; sessionid_sign=' + sessionidsign + ';cookiesSettings={\"analytics\":true,\"advertising\":true};backend=test_backend',
|
|
55
|
-
'Referer': urlRuTV + '/u/PartnerFinance/',
|
|
56
|
-
'Referrer-Policy': 'origin-when-cross-origin',
|
|
51
|
+
'accept': 'text/html',
|
|
52
|
+
'cookie': cookie,
|
|
57
53
|
};
|
|
58
|
-
|
|
54
|
+
|
|
59
55
|
try {
|
|
60
56
|
const res = await fetch(url, { method: 'GET', headers });
|
|
61
|
-
|
|
57
|
+
console.warn('Response status:', res.status);
|
|
62
58
|
const html = await res.text();
|
|
59
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
63
60
|
const match = html.match(/"auth_token"\s*:\s*"([^"]+)"/);
|
|
64
|
-
|
|
61
|
+
const token = match ? match[1] : null;
|
|
62
|
+
console.warn('✅ Auth token found');
|
|
63
|
+
if (!token) {
|
|
64
|
+
throw new Error('❌ Auth token not found in HTML');
|
|
65
|
+
}
|
|
66
|
+
return token;
|
|
65
67
|
} catch (err) {
|
|
66
68
|
console.error('❌ Error fetching token:', err.message);
|
|
67
69
|
return null;
|
|
@@ -106,10 +108,10 @@ class TradingView {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
getSymbolId({ data }) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
111
|
+
// getSymbolId({ data }) {
|
|
112
|
+
// const name = data.type === 'futures' ? data.contracts[0].symbol : data.symbol;
|
|
113
|
+
// return data.exchange.toUpperCase() + ':' + name.toUpperCase();
|
|
114
|
+
// }
|
|
113
115
|
|
|
114
116
|
createSession({ startsWith }) {
|
|
115
117
|
if (typeof startsWith !== 'string' || startsWith.length === 0) {
|