From bd73d02cfb1e0ab2a0520fa92775edf8936ea0a3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 28 Dec 2020 13:31:15 -0500 Subject: [PATCH] Avoid loading volume FSPs on symbols without any data --- piker/ui/_chart.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index c27f57e0..7ba23f5b 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -841,10 +841,6 @@ async def _async_main( # eventually we'll support some kind of n-compose syntax fsp_conf = { - 'vwap': { - 'overlay': True, - 'anchor': 'session', - }, 'rsi': { 'period': 14, 'chart_kwargs': { @@ -854,6 +850,24 @@ async def _async_main( } + # make sure that the instrument supports volume history + # (sometimes this is not the case for some commodities and derivatives) + volm = ohlcv.array['volume'] + if ( + np.all(np.isin(volm, -1)) or + np.all(np.isnan(volm)) + ): + log.warning( + f"{sym} does not seem to have volume info," + " dropping volume signals") + else: + fsp_conf.update({ + 'vwap': { + 'overlay': True, + 'anchor': 'session', + }, + }) + async with trio.open_nursery() as n: # load initial fsp chain (otherwise known as "indicators")