| 115 | * @param {import('../client').ClientBridge} client |
| 116 | */ |
| 117 | module.exports = (client) => class ChartSession { |
| 118 | #chartSessionID = genSessionID('cs'); |
| 119 | |
| 120 | #replaySessionID = genSessionID('rs'); |
| 121 | |
| 122 | #replayMode = false; |
| 123 | |
| 124 | /** @type {Object<string, (): any>} */ |
| 125 | #replayOKCB = {}; |
| 126 | |
| 127 | /** Parent client */ |
| 128 | #client = client; |
| 129 | |
| 130 | /** @type {StudyListeners} */ |
| 131 | #studyListeners = {}; |
| 132 | |
| 133 | /** |
| 134 | * Table of periods values indexed by timestamp |
| 135 | * @type {Object<number, PricePeriod[]>} |
| 136 | */ |
| 137 | #periods = {}; |
| 138 | |
| 139 | /** @return {PricePeriod[]} List of periods values */ |
| 140 | get periods() { |
| 141 | return Object.values(this.#periods).sort((a, b) => b.time - a.time); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Current market infos |
| 146 | * @type {MarketInfos} |
| 147 | */ |
| 148 | #infos = {}; |
| 149 | |
| 150 | /** @return {MarketInfos} Current market infos */ |
| 151 | get infos() { |
| 152 | return this.#infos; |
| 153 | } |
| 154 | |
| 155 | #callbacks = { |
| 156 | seriesLoaded: [], |
| 157 | symbolLoaded: [], |
| 158 | update: [], |
| 159 | |
| 160 | replayLoaded: [], |
| 161 | replayPoint: [], |
| 162 | replayResolution: [], |
| 163 | replayEnd: [], |
| 164 | |
| 165 | event: [], |
| 166 | error: [], |
| 167 | }; |
| 168 | |
| 169 | /** |
| 170 | * @param {ChartEvent} ev Client event |
| 171 | * @param {...{}} data Packet data |
| 172 | */ |
| 173 | #handleEvent(ev, ...data) { |
| 174 | this.#callbacks[ev].forEach((e) => e(...data)); |
nothing calls this directly
no test coverage detected