Add "no vlm" indication to `FeedInit`
Stash it for now in the (now mutable by default) `.shm_write_opts` and have the new `Flume._has_vlm: bool` (only set to false internally by feed layer) which can be read via new public `.has_vlm()` predicate. Move out the old `.ui/_fsp` helper logic to this flume method.master
							parent
							
								
									e82f7f9012
								
							
						
					
					
						commit
						8e97814c1f
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue