(client, message, subscription)
| 248 | this.spawn(this.fetchOrderBookSnapshot, client, message, subscription); |
| 249 | } |
| 250 | async fetchOrderBookSnapshot(client, message, subscription) { |
| 251 | const symbol = this.safeString(subscription, 'symbol'); |
| 252 | const messageHash = this.safeString(message, 'topic'); |
| 253 | try { |
| 254 | const defaultLimit = this.safeInteger(this.options, 'watchOrderBookLimit', 1000); |
| 255 | const limit = this.safeInteger(subscription, 'limit', defaultLimit); |
| 256 | const params = this.safeValue(subscription, 'params'); |
| 257 | const snapshot = await this.fetchRestOrderBookSafe(symbol, limit, params); |
| 258 | if (this.safeValue(this.orderbooks, symbol) === undefined) { |
| 259 | // if the orderbook is dropped before the snapshot is received |
| 260 | return; |
| 261 | } |
| 262 | const orderbook = this.orderbooks[symbol]; |
| 263 | orderbook.reset(snapshot); |
| 264 | const messages = orderbook.cache; |
| 265 | for (let i = 0; i < messages.length; i++) { |
| 266 | const messageItem = messages[i]; |
| 267 | const ts = this.safeInteger(messageItem, 'ts'); |
| 268 | if (ts < orderbook['timestamp']) { |
| 269 | continue; |
| 270 | } |
| 271 | else { |
| 272 | this.handleOrderBookMessage(client, messageItem, orderbook); |
| 273 | } |
| 274 | } |
| 275 | this.orderbooks[symbol] = orderbook; |
| 276 | client.resolve(orderbook, messageHash); |
| 277 | } |
| 278 | catch (e) { |
| 279 | delete client.subscriptions[messageHash]; |
| 280 | client.reject(e, messageHash); |
| 281 | } |
| 282 | } |
| 283 | handleOrderBookMessage(client, message, orderbook) { |
| 284 | const data = this.safeDict(message, 'data'); |
| 285 | this.handleDeltas(orderbook['asks'], this.safeValue(data, 'asks', [])); |
nothing calls this directly
no test coverage detected