From 6854671109c3083e60af4779126b74c6413510a3 Mon Sep 17 00:00:00 2001 From: Thaddeus Date: Fri, 21 Oct 2022 20:52:38 +0200 Subject: [PATCH] improvement: tweak delta order book mapping code to handle undefined bids or asks --- src/mappers/delta.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mappers/delta.ts b/src/mappers/delta.ts index 722d2ba..7e78791 100644 --- a/src/mappers/delta.ts +++ b/src/mappers/delta.ts @@ -66,13 +66,16 @@ export const deltaBookChangeMapper: Mapper<'delta', BookChange> = { }, *map(message: DeltaL2OrderBook, localTimestamp: Date): IterableIterator { + if (message.buy === undefined && message.sell === undefined) { + return + } yield { type: 'book_change', symbol: message.symbol, exchange: 'delta', isSnapshot: true, - bids: message.buy.map(mapBookLevel), - asks: message.sell.map(mapBookLevel), + bids: message.buy !== undefined ? message.buy.map(mapBookLevel) : [], + asks: message.sell !== undefined ? message.sell.map(mapBookLevel) : [], timestamp: message.timestamp !== undefined ? fromMicroSecondsToDate(message.timestamp) : localTimestamp, localTimestamp }