* @param {PineIndicator | BuiltInIndicator} indicator Indicator object instance
(indicator)
| 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') { |
nothing calls this directly
no test coverage detected