From b579fbc6680c184bf28812b4b616ac43018aa854 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 20 Sep 2021 08:48:34 -0400 Subject: [PATCH] Add test logic for range based volume curve filling --- piker/ui/_chart.py | 14 +++++++++++++- piker/ui/_display.py | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) 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 88e8fc17..08d8942d 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 @@ -670,6 +677,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, { @@ -856,6 +865,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( @@ -876,6 +886,7 @@ async def display_symbol_data( feed.stream, ohlcv, wap_in_history, + vlm_chart, ) ln.start_soon( @@ -886,7 +897,6 @@ async def display_symbol_data( ) async with ( - maybe_open_vlm_display(linkedsplits, ohlcv), open_order_mode( feed, chart,