MCPcopy Index your code
hub / github.com/Mathieu2301/TradingView-API / constructor

Method constructor

src/chart/study.js:228–371  ·  view source on GitHub ↗

* @param {PineIndicator | BuiltInIndicator} indicator Indicator object instance

(indicator)

Source from the content-addressed store, hash-verified

226 * @param {PineIndicator | BuiltInIndicator} indicator Indicator object instance
227 */
228 constructor(indicator) {
229 if (!(indicator instanceof PineIndicator) && !(indicator instanceof BuiltInIndicator)) {
230 throw new Error(`Indicator argument must be an instance of PineIndicator or BuiltInIndicator.
231 Please use 'TradingView.getIndicator(...)' function.`);
232 }
233
234 /** @type {PineIndicator | BuiltInIndicator} Indicator instance */
235 this.instance = indicator;
236
237 this.#studyListeners[this.#studID] = async (packet) => {
238 if (global.TW_DEBUG) console.log('§90§30§105 STUDY §0 DATA', packet);
239
240 if (packet.type === 'study_completed') {
241 this.#handleEvent('studyCompleted');
242 return;
243 }
244
245 if (['timescale_update', 'du'].includes(packet.type)) {
246 const changes = [];
247 const data = packet.data[1][this.#studID];
248
249 if (data && data.st && data.st[0]) {
250 data.st.forEach((p) => {
251 const period = {};
252
253 p.v.forEach((plot, i) => {
254 if (!this.instance.plots) {
255 period[i === 0 ? '$time' : `plot_${i - 1}`] = plot;
256 return;
257 }
258 const plotName = (i === 0 ? '$time' : this.instance.plots[`plot_${i - 1}`]);
259 if (plotName && !period[plotName]) period[plotName] = plot;
260 else period[`plot_${i - 1}`] = plot;
261 });
262
263 this.#periods[p.v[0]] = period;
264 });
265
266 changes.push('plots');
267 }
268
269 if (data.ns && data.ns.d) {
270 const parsed = JSON.parse(data.ns.d);
271
272 if (parsed.graphicsCmds) {
273 if (parsed.graphicsCmds.erase) {
274 parsed.graphicsCmds.erase.forEach((instruction) => {
275 // console.log('Erase', instruction);
276 if (instruction.action === 'all') {
277 if (!instruction.type) {
278 Object.keys(this.#graphic).forEach((drawType) => {
279 this.#graphic[drawType] = {};
280 });
281 } else delete this.#graphic[instruction.type];
282 return;
283 }
284
285 if (instruction.action === 'one') {

Callers

nothing calls this directly

Calls 5

#handleEventMethod · 0.95
#handleErrorMethod · 0.95
parseCompressedFunction · 0.85
getInputsFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected