* 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 = {})
| 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 |
nothing calls this directly
no test coverage detected