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

Function getChartToken

src/miscRequests.js:529–553  ·  view source on GitHub ↗

* Get a chart token from a layout ID and the user credentials if the layout is not public * @function getChartToken * @param {string} layout The layout ID found in the layout URL (Like: 'XXXXXXXX') * @param {UserCredentials} [credentials] User credentials (id + session + [signature]) * @

(layout, credentials = {})

Source from the content-addressed store, hash-verified

527 * @returns {Promise<string>} Token
528 */
529 async getChartToken(layout, credentials = {}) {
530 const { id, session, signature } = (
531 credentials.id && credentials.session
532 ? credentials
533 : { id: -1, session: null, signature: null }
534 );
535
536 const { data } = await axios.get(
537 'https://www.tradingview.com/chart-token',
538 {
539 headers: {
540 cookie: genAuthCookies(session, signature),
541 },
542 params: {
543 image_url: layout,
544 user_id: id,
545 },
546 validateStatus,
547 },
548 );
549
550 if (!data.token) throw new Error('Wrong layout or credentials');
551
552 return data.token;
553 },
554
555 /**
556 * @typedef {Object} DrawingPoint Drawing poitn

Callers

nothing calls this directly

Calls 1

genAuthCookiesFunction · 0.85

Tested by

no test coverage detected