| 6495 | }; |
| 6496 | |
| 6497 | const updateSymbolDepthCache = json => { |
| 6498 | // Get previous store symbol |
| 6499 | const symbol = json.symbol; |
| 6500 | // Initialize depth cache from snapshot |
| 6501 | this.depthCache[symbol] = this.depthData(json); |
| 6502 | // Prepare depth cache context |
| 6503 | const context = this.depthCacheContext[symbol]; |
| 6504 | context.snapshotUpdateId = json.lastUpdateId; |
| 6505 | context.messageQueue = context.messageQueue.filter(depth => depth.u > context.snapshotUpdateId); |
| 6506 | // Process any pending depth messages |
| 6507 | for (const depth of context.messageQueue) { |
| 6508 | /* Although sync errors shouldn't ever happen here, we catch and swallow them anyway |
| 6509 | just in case. The stream handler function above will deal with broken caches. */ |
| 6510 | try { |
| 6511 | this.depthHandler(depth); |
| 6512 | } catch (err) { |
| 6513 | // Do nothing |
| 6514 | } |
| 6515 | } |
| 6516 | delete context.messageQueue; |
| 6517 | if (callback) callback(symbol, this.depthCache[symbol]); |
| 6518 | }; |
| 6519 | |
| 6520 | /* If an array of symbols are sent we use a combined stream connection rather. |
| 6521 | This is transparent to the developer, and results in a single socket connection. |
nothing calls this directly
no test coverage detected