Add vlm axis titles and humanized $vlm y-range

vlm_plotz
Tyler Goodlet 2022-01-17 18:56:58 -05:00
parent e8cad45952
commit 56f9ddb880
1 changed files with 83 additions and 56 deletions

View File

@ -33,7 +33,9 @@ import pyqtgraph as pg
import trio import trio
from trio_typing import TaskStatus from trio_typing import TaskStatus
from ._axes import PriceAxis
from .._cacheables import maybe_open_context from .._cacheables import maybe_open_context
from ..calc import humanize
from ..data._sharedmem import ( from ..data._sharedmem import (
ShmArray, ShmArray,
maybe_open_shm_array, maybe_open_shm_array,
@ -661,73 +663,98 @@ async def open_vlm_displays(
# size view to data once at outset # size view to data once at outset
chart.view._set_yrange() chart.view._set_yrange()
if not dvlm: # add axis title
return axis = chart.getAxis('right')
axis.set_title(' vlm')
# spawn and overlay $ vlm on the same subchart if dvlm:
shm, started = await admin.start_engine_task(
'dolla_vlm', # spawn and overlay $ vlm on the same subchart
# linked.symbol.front_feed(), # data-feed symbol key shm, started = await admin.start_engine_task(
{ # fsp engine conf 'dolla_vlm',
'func_name': 'dolla_vlm', # linked.symbol.front_feed(), # data-feed symbol key
'zero_on_step': True, { # fsp engine conf
'params': { 'func_name': 'dolla_vlm',
'price_func': { 'zero_on_step': True,
'default_value': 'chl3', 'params': {
'price_func': {
'default_value': 'chl3',
},
}, },
}, },
}, # loglevel,
# loglevel, )
) # profiler(f'created shm for fsp actor: {display_name}')
# profiler(f'created shm for fsp actor: {display_name}')
await started.wait() await started.wait()
pi = chart.overlay_plotitem( pi = chart.overlay_plotitem(
'dolla_vlm', 'dolla_vlm',
) axis_kwargs={
# add custom auto range handler # 'humanize': True,
pi.vb._maxmin = partial(maxmin, name='dolla_vlm') # 'text': 'dvlm',
'typical_max_str': ' 99.9 M ',
'formatter': partial(
humanize,
digits=2,
),
},
curve, _ = chart.draw_curve( )
name='dolla_vlm', # add axis title
data=shm.array, raxis = pi.getAxis('right')
raxis.set_title(' $vlm', view=pi.getViewBox())
array_key='dolla_vlm', # add custom auto range handler
overlay=pi, pi.vb._maxmin = partial(maxmin, name='dolla_vlm')
color='charcoal',
step_mode=True,
# **conf.get('chart_kwargs', {})
)
# TODO: is there a way to "sync" the dual axes such that only
# one curve is needed?
# curve.hide()
# TODO: we need a better API to do this.. curve, _ = chart.draw_curve(
# specially store ref to shm for lookup in display loop
# since only a placeholder of `None` is entered in
# ``.draw_curve()``.
chart._overlays['dolla_vlm'] = shm
# XXX: old dict-style config before it was moved into the helper task name='dolla_vlm',
# 'dolla_vlm': { data=shm.array,
# 'func_name': 'dolla_vlm',
# 'zero_on_step': True,
# 'overlay': 'volume',
# 'separate_axes': True,
# 'params': {
# 'price_func': {
# 'default_value': 'chl3',
# # tell target ``Edit`` widget to not allow
# # edits for now.
# 'widget_kwargs': {'readonly': True},
# },
# },
# 'chart_kwargs': {'step_mode': True}
# },
# } array_key='dolla_vlm',
overlay=pi,
color='charcoal',
step_mode=True,
# **conf.get('chart_kwargs', {})
)
# TODO: is there a way to "sync" the dual axes such that only
# one curve is needed?
# curve.hide()
# TODO: we need a better API to do this..
# specially store ref to shm for lookup in display loop
# since only a placeholder of `None` is entered in
# ``.draw_curve()``.
chart._overlays['dolla_vlm'] = shm
# XXX: old dict-style config before it was moved into the
# helper task
# 'dolla_vlm': {
# 'func_name': 'dolla_vlm',
# 'zero_on_step': True,
# 'overlay': 'volume',
# 'separate_axes': True,
# 'params': {
# 'price_func': {
# 'default_value': 'chl3',
# # tell target ``Edit`` widget to not allow
# # edits for now.
# 'widget_kwargs': {'readonly': True},
# },
# },
# 'chart_kwargs': {'step_mode': True}
# },
# }
for name, axis_info in pi.axes.items():
# lol this sux XD
axis = axis_info['item']
if isinstance(axis, PriceAxis):
axis.size_to_values()
# built-in vlm fsps # built-in vlm fsps
for display_name, conf in { for display_name, conf in {