MCPcopy
hub / github.com/Mathieu2301/TradingView-API / getIndicator

Function getIndicator

src/miscRequests.js:278–351  ·  view source on GitHub ↗

* Get an indicator * @function getIndicator * @param {string} id Indicator ID (Like: PUB;XXXXXXXXXXXXXXXXXXXXX) * @param {'last' | string} [version] Wanted version of the indicator * @param {string} [session] User 'sessionid' cookie * @param {string} [signature] User 'sessionid_sign'

(id, version = 'last', session = '', signature = '')

Source from the content-addressed store, hash-verified

276 * @returns {Promise<PineIndicator>} Indicator
277 */
278 async getIndicator(id, version = 'last', session = '', signature = '') {
279 const indicID = id.replace(/ |%/g, '%25');
280
281 const { data } = await axios.get(
282 `https://pine-facade.tradingview.com/pine-facade/translate/${indicID}/${version}`,
283 {
284 headers: {
285 cookie: genAuthCookies(session, signature),
286 },
287 validateStatus,
288 },
289 );
290
291 if (!data.success || !data.result.metaInfo || !data.result.metaInfo.inputs) {
292 throw new Error(`Inexistent or unsupported indicator: "${data.reason}"`);
293 }
294
295 const inputs = {};
296
297 data.result.metaInfo.inputs.forEach((input) => {
298 if (['text', 'pineId', 'pineVersion'].includes(input.id)) return;
299
300 const inlineName = input.name.replace(/ /g, '_').replace(/[^a-zA-Z0-9_]/g, '');
301
302 inputs[input.id] = {
303 name: input.name,
304 inline: input.inline || inlineName,
305 internalID: input.internalID || inlineName,
306 tooltip: input.tooltip,
307
308 type: input.type,
309 value: input.defval,
310 isHidden: !!input.isHidden,
311 isFake: !!input.isFake,
312 };
313
314 if (input.options) inputs[input.id].options = input.options;
315 });
316
317 const plots = {};
318
319 Object.keys(data.result.metaInfo.styles).forEach((plotId) => {
320 const plotTitle = data
321 .result
322 .metaInfo
323 .styles[plotId]
324 .title
325 .replace(/ /g, '_')
326 .replace(/[^a-zA-Z0-9_]/g, '');
327
328 const titles = Object.values(plots);
329
330 if (titles.includes(plotTitle)) {
331 let i = 2;
332 while (titles.includes(`${plotTitle}_${i}`)) i += 1;
333 plots[plotId] = `${plotTitle}_${i}`;
334 } else plots[plotId] = plotTitle;
335 });

Callers

nothing calls this directly

Calls 1

genAuthCookiesFunction · 0.85

Tested by

no test coverage detected