()
| 181 | } |
| 182 | |
| 183 | constructor() { |
| 184 | this.#client.sessions[this.#chartSessionID] = { |
| 185 | type: 'chart', |
| 186 | onData: (packet) => { |
| 187 | if (global.TW_DEBUG) console.log('§90§30§106 CHART SESSION §0 DATA', packet); |
| 188 | |
| 189 | if (typeof packet.data[1] === 'string' && this.#studyListeners[packet.data[1]]) { |
| 190 | this.#studyListeners[packet.data[1]](packet); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | if (packet.type === 'symbol_resolved') { |
| 195 | this.#infos = { |
| 196 | series_id: packet.data[1], |
| 197 | ...packet.data[2], |
| 198 | }; |
| 199 | |
| 200 | this.#handleEvent('symbolLoaded'); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | if (['timescale_update', 'du'].includes(packet.type)) { |
| 205 | const changes = []; |
| 206 | |
| 207 | Object.keys(packet.data[1]).forEach((k) => { |
| 208 | changes.push(k); |
| 209 | if (k === '$prices') { |
| 210 | const periods = packet.data[1].$prices; |
| 211 | if (!periods || !periods.s) return; |
| 212 | |
| 213 | periods.s.forEach((p) => { |
| 214 | [this.#chartSession.indexes[p.i]] = p.v; |
| 215 | this.#periods[p.v[0]] = { |
| 216 | time: p.v[0], |
| 217 | open: p.v[1], |
| 218 | close: p.v[4], |
| 219 | max: p.v[2], |
| 220 | min: p.v[3], |
| 221 | volume: Math.round(p.v[5] * 100) / 100, |
| 222 | }; |
| 223 | }); |
| 224 | |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | if (this.#studyListeners[k]) this.#studyListeners[k](packet); |
| 229 | }); |
| 230 | |
| 231 | this.#handleEvent('update', changes); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | if (packet.type === 'symbol_error') { |
| 236 | this.#handleError(`(${packet.data[1]}) Symbol error:`, packet.data[2]); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | if (packet.type === 'series_error') { |
nothing calls this directly
no test coverage detected