Add test logic for range based volume curve filling

basic_vlm_display
Tyler Goodlet 2021-09-20 08:48:34 -04:00
parent 4f9aa0d965
commit 216afec19c
2 changed files with 25 additions and 3 deletions

View File

@ -959,6 +959,7 @@ class ChartPlotWidget(pg.PlotWidget):
*, *,
yrange: Optional[tuple[float, float]] = None, yrange: Optional[tuple[float, float]] = None,
range_margin: float = 0.06, range_margin: float = 0.06,
bars_range: Optional[tuple[int, int, int, int]] = None
) -> None: ) -> None:
'''Set the viewable y-range based on embedded data. '''Set the viewable y-range based on embedded data.
@ -982,7 +983,18 @@ class ChartPlotWidget(pg.PlotWidget):
# Determine max, min y values in viewable x-range from data. # Determine max, min y values in viewable x-range from data.
# Make sure min bars/datums on screen is adhered. # 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" # figure out x-range in view such that user can scroll "off"
# the data set up to the point where ``_min_points_to_show`` # the data set up to the point where ``_min_points_to_show``

View File

@ -19,8 +19,10 @@ Real-time display tasks for charting / graphics.
''' '''
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pprint import pformat
import time import time
from types import ModuleType from types import ModuleType
from typing import Optional
import numpy as np import numpy as np
from pydantic import create_model from pydantic import create_model
@ -61,6 +63,7 @@ async def chart_from_quotes(
stream: tractor.MsgStream, stream: tractor.MsgStream,
ohlcv: np.ndarray, ohlcv: np.ndarray,
wap_in_history: bool = False, wap_in_history: bool = False,
vlm_chart: Optional[ChartPlotWidget] = None,
) -> None: ) -> None:
'''The 'main' (price) chart real-time update loop. '''The 'main' (price) chart real-time update loop.
@ -149,7 +152,7 @@ async def chart_from_quotes(
for tick in quote.get('ticks', ()): 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') ticktype = tick.get('type')
price = tick.get('price') price = tick.get('price')
size = tick.get('size') size = tick.get('size')
@ -190,6 +193,10 @@ async def chart_from_quotes(
# update vwap overlay line # update vwap overlay line
chart.update_curve_from_array('bar_wap', ohlcv.array) 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 # l1 book events
# throttle the book graphics updates at a lower rate # throttle the book graphics updates at a lower rate
# since they aren't as critical for a manual user # 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): if not has_vlm(ohlcv):
log.warning(f"{linked.symbol.key} does not seem to have volume info") log.warning(f"{linked.symbol.key} does not seem to have volume info")
yield
return
else: else:
async with open_sidepane( async with open_sidepane(
linked, { linked, {
@ -852,6 +861,7 @@ async def display_symbol_data(
async with ( async with (
trio.open_nursery() as ln, trio.open_nursery() as ln,
maybe_open_vlm_display(linkedsplits, ohlcv) as vlm_chart,
): ):
# load initial fsp chain (otherwise known as "indicators") # load initial fsp chain (otherwise known as "indicators")
ln.start_soon( ln.start_soon(
@ -872,6 +882,7 @@ async def display_symbol_data(
feed.stream, feed.stream,
ohlcv, ohlcv,
wap_in_history, wap_in_history,
vlm_chart,
) )
ln.start_soon( ln.start_soon(
@ -882,7 +893,6 @@ async def display_symbol_data(
) )
async with ( async with (
maybe_open_vlm_display(linkedsplits, ohlcv),
open_order_mode( open_order_mode(
feed, feed,
chart, chart,