diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index a9f8d70e..cc6fde36 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -951,6 +951,7 @@ class ChartPlotWidget(pg.PlotWidget): *, yrange: Optional[tuple[float, float]] = None, range_margin: float = 0.06, + bars_range: Optional[tuple[int, int, int, int]] = None ) -> None: '''Set the viewable y-range based on embedded data. @@ -974,7 +975,18 @@ class ChartPlotWidget(pg.PlotWidget): # Determine max, min y values in viewable x-range from data. # Make sure min bars/datums on screen is adhered. - l, lbar, rbar, r = self.bars_range() + l, lbar, rbar, r = bars_range or self.bars_range() + + if self.name != 'volume': + vlm_chart = self.linked.subplots.get('volume') + if vlm_chart: + vlm_chart._set_yrange(bars_range=(l, lbar, rbar, r)) + curve = vlm_chart._graphics['volume'] + # if rbar - lbar < 1500: + # # print('small range') + # curve._fill = True + # else: + # curve._fill = False # figure out x-range in view such that user can scroll "off" # the data set up to the point where ``_min_points_to_show`` diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 58a14676..64f2d487 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -19,8 +19,10 @@ Real-time display tasks for charting / graphics. ''' from contextlib import asynccontextmanager +from pprint import pformat import time from types import ModuleType +from typing import Optional import numpy as np from pydantic import create_model @@ -61,6 +63,7 @@ async def chart_from_quotes( stream: tractor.MsgStream, ohlcv: np.ndarray, wap_in_history: bool = False, + vlm_chart: Optional[ChartPlotWidget] = None, ) -> None: '''The 'main' (price) chart real-time update loop. @@ -149,7 +152,7 @@ async def chart_from_quotes( for tick in quote.get('ticks', ()): - # print(f"CHART: {quote['symbol']}: {tick}") + # log.info(f"quotes: {pformat(quote['symbol'])}: {pformat(tick)}") ticktype = tick.get('type') price = tick.get('price') size = tick.get('size') @@ -190,6 +193,10 @@ async def chart_from_quotes( # update vwap overlay line chart.update_curve_from_array('bar_wap', ohlcv.array) + if vlm_chart: + print(f"volume: {end['volume']}") + vlm_chart.update_curve_from_array('volume', ohlcv.array) + # l1 book events # throttle the book graphics updates at a lower rate # since they aren't as critical for a manual user @@ -666,6 +673,8 @@ async def maybe_open_vlm_display( if not has_vlm(ohlcv): log.warning(f"{linked.symbol.key} does not seem to have volume info") + yield + return else: async with open_sidepane( linked, { @@ -852,6 +861,7 @@ async def display_symbol_data( async with ( trio.open_nursery() as ln, + maybe_open_vlm_display(linkedsplits, ohlcv) as vlm_chart, ): # load initial fsp chain (otherwise known as "indicators") ln.start_soon( @@ -872,6 +882,7 @@ async def display_symbol_data( feed.stream, ohlcv, wap_in_history, + vlm_chart, ) ln.start_soon( @@ -882,7 +893,6 @@ async def display_symbol_data( ) async with ( - maybe_open_vlm_display(linkedsplits, ohlcv), open_order_mode( feed, chart,