From 19c343e8b2946a9a780517a8b2adb5922d17189c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 11 Jun 2024 10:28:56 -0400 Subject: [PATCH] binance: raise `NoData` on null hist arrays Like we do with other history backends to indicate lack of a data set. This avoids any raise that will will bring down the backloader task with some downstream error. Raise a `ValueError` on no time index for now. --- piker/brokers/binance/feed.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/piker/brokers/binance/feed.py b/piker/brokers/binance/feed.py index 1416d6a7..9e36a626 100644 --- a/piker/brokers/binance/feed.py +++ b/piker/brokers/binance/feed.py @@ -48,6 +48,7 @@ import tractor from piker.brokers import ( open_cached_client, + NoData, ) from piker._cacheables import ( async_lifo_cache, @@ -254,22 +255,28 @@ async def open_history_client( # NOTE: always query using their native symbology! mktid: str = mkt.bs_mktid - array = await client.bars( + array: np.ndarray = await client.bars( mktid, start_dt=start_dt, end_dt=end_dt, ) + if array.size == 0: + raise NoData('No frame for {start_dt} -> {end_dt}\n') + times = array['time'] - if ( - end_dt is None - ): - inow = round(time.time()) + if not times.any(): + raise ValueError( + 'Bad frame with null-times?\n\n' + f'{times}' + ) + + if end_dt is None: + inow: int = round(time.time()) if (inow - times[-1]) > 60: await tractor.pause() start_dt = from_timestamp(times[0]) end_dt = from_timestamp(times[-1]) - return array, start_dt, end_dt yield get_ohlc, {'erlangs': 3, 'rate': 3}