diff --git a/piker/data/feed.py b/piker/data/feed.py index 0a8fd0f6..88d2a386 100644 --- a/piker/data/feed.py +++ b/piker/data/feed.py @@ -309,7 +309,7 @@ async def allocate_persistent_feed( init: FeedInit = validate_backend( mod, [symstr], - init_msgs, + init_msgs, # NOTE: only 1 should be delivered for now.. ) mkt: MktPair = init.mkt_info fqme: str = mkt.fqme @@ -355,6 +355,10 @@ async def allocate_persistent_feed( _hist_shm_token=hist_shm.token, izero_hist=izero_hist, izero_rt=izero_rt, + + # NOTE: some instruments don't have this provided, + # eg. commodities and forex from ib. + _has_vlm=init.shm_write_opts['has_vlm'], ) # for ambiguous names we simply register the diff --git a/piker/data/flows.py b/piker/data/flows.py index ecb727e8..07ca304e 100644 --- a/piker/data/flows.py +++ b/piker/data/flows.py @@ -240,3 +240,23 @@ class Flume(Struct): ) imx = times.shape[0] - 1 return min(first, imx) + + # only set by external msg or creator, never + # manually! + _has_vlm: bool = True + + def has_vlm(self) -> bool: + + if not self._has_vlm: + return False + + # make sure that the instrument supports volume history + # (sometimes this is not the case for some commodities and + # derivatives) + vlm: np.ndarray = self.rt_shm.array['volume'] + return not bool( + np.all(np.isin(vlm, -1)) + or np.all(np.isnan(vlm)) + ) + + diff --git a/piker/data/validate.py b/piker/data/validate.py index c295c179..8f6c1d5a 100644 --- a/piker/data/validate.py +++ b/piker/data/validate.py @@ -25,6 +25,8 @@ from typing import ( Any, ) +from msgspec import field + from .types import Struct from ..accounting import ( Asset, @@ -52,8 +54,11 @@ class FeedInit(Struct, frozen=True): # NOTE: only field we use rn in ``.data.feed`` # TODO: maybe make a SamplerConfig(Struct)? - shm_write_opts: dict[str, Any] = {} - # 'sum_tick_vlm': True + shm_write_opts: dict[str, Any] = field( + default_factory=lambda: { + 'has_vlm': True, + 'sum_tick_vlm': True, + }) def validate_backend( diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 40ec23b2..eb8e330b 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -62,7 +62,6 @@ from ._style import hcolor from ._fsp import ( update_fsp_chart, start_fsp_displays, - has_vlm, open_vlm_displays, ) from ._forms import ( @@ -1335,7 +1334,7 @@ async def display_symbol_data( None | ChartPlotWidget ] = {}.fromkeys(feed.flumes) if ( - has_vlm(ohlcv) + flume.has_vlm() and vlm_chart is None ): vlm_chart = vlm_charts[fqme] = await ln.start( diff --git a/piker/ui/_fsp.py b/piker/ui/_fsp.py index 06814c28..6435e970 100644 --- a/piker/ui/_fsp.py +++ b/piker/ui/_fsp.py @@ -72,14 +72,6 @@ from .._profile import Profiler log = get_logger(__name__) -def has_vlm(ohlcv: ShmArray) -> bool: - # make sure that the instrument supports volume history - # (sometimes this is not the case for some commodities and - # derivatives) - vlm = ohlcv.array['volume'] - return not bool(np.all(np.isin(vlm, -1)) or np.all(np.isnan(vlm))) - - def update_fsp_chart( viz, graphics_name: str,