| 5708 | }; |
| 5709 | |
| 5710 | let updateSymbolDepthCache = json => { |
| 5711 | // Get previous store symbol |
| 5712 | let symbol = json.symb; |
| 5713 | // Initialize depth cache from snapshot |
| 5714 | Binance.depthCache[symbol] = depthData(json); |
| 5715 | // Prepare depth cache context |
| 5716 | let context = Binance.depthCacheContext[symbol]; |
| 5717 | context.snapshotUpdateId = json.lastUpdateId; |
| 5718 | context.messageQueue = context.messageQueue.filter(depth => depth.u > context.snapshotUpdateId); |
| 5719 | // Process any pending depth messages |
| 5720 | for (let depth of context.messageQueue) { |
| 5721 | /* Although sync errors shouldn't ever happen here, we catch and swallow them anyway |
| 5722 | just in case. The stream handler function above will deal with broken caches. */ |
| 5723 | try { |
| 5724 | depthHandler(depth); |
| 5725 | } catch (err) { |
| 5726 | // Do nothing |
| 5727 | } |
| 5728 | } |
| 5729 | delete context.messageQueue; |
| 5730 | if (callback) callback(symbol, Binance.depthCache[symbol]); |
| 5731 | }; |
| 5732 | |
| 5733 | /* If an array of symbols are sent we use a combined stream connection rather. |
| 5734 | This is transparent to the developer, and results in a single socket connection. |
nothing calls this directly
no test coverage detected