.ui._display: filter y-ranging to `_auction_ticks`

Since we only ever want to do incremental y-range calcs based on the
price always skip any tick types emitted by the data daemon which aren't
defined in the fundamental set. Further, toss in a new `debug_n_trade:
bool` toggle which by default turns off all loggin and profiler calls;
if you want to do profiling this has to now be adjusted manually!
basic_buy_bot
Tyler Goodlet 2023-06-20 15:54:47 -04:00
parent d42aa60325
commit c4277ebd8e
1 changed files with 70 additions and 31 deletions

View File

@ -50,6 +50,7 @@ from ..data._sharedmem import (
)
from ..data._sampling import (
_tick_groups,
_auction_ticks,
open_sample_stream,
)
from ._axes import YAxisLabel
@ -518,8 +519,14 @@ def graphics_update_cycle(
trigger_all: bool = False, # flag used by prepend history updates
prepend_update_index: int | None = None,
# NOTE: this has to be manually turned on in code (or by
# caller) to get profiling since by default we never want the
# overhead!
debug_n_trace: bool = False,
) -> None:
if debug_n_trace:
profiler = Profiler(
msg=f'Graphics loop cycle for: `{ds.fqme}`',
disabled=not pg_profile_enabled(),
@ -558,6 +565,7 @@ def graphics_update_cycle(
do_rt_update,
should_tread,
) = main_viz.incr_info(ds=ds)
if debug_n_trace:
profiler('`.incr_info()`')
# TODO: we should only run mxmn when we know
@ -596,6 +604,7 @@ def graphics_update_cycle(
# since .interact_graphics_cycle() also calls it?
# I guess we can add a guard in there?
_, i_read_range, _ = main_viz.update_graphics()
if debug_n_trace:
profiler('`Viz.update_graphics()` call')
# don't real-time "shift" the curve to the
@ -611,6 +620,7 @@ def graphics_update_cycle(
# if vlm_chart:
# vlm_chart.increment_view(datums=append_diff)
if debug_n_trace:
profiler('view incremented')
# NOTE: do this **after** the tread to ensure we take the yrange
@ -623,9 +633,10 @@ def graphics_update_cycle(
i_read_range,
main_viz,
ds.vlm_viz,
profiler,
profiler if debug_n_trace else None,
)
if debug_n_trace:
profiler(f'{fqme} `multi_maxmin()` call')
# iterate frames of ticks-by-type such that we only update graphics
@ -633,6 +644,14 @@ def graphics_update_cycle(
ticks_by_type = quote.get('tbt', {})
for typ, ticks in ticks_by_type.items():
if typ not in _auction_ticks:
if debug_n_trace:
log.warning(
'Skipping non-auction-native `{typ}` ticks:\n'
f'{ticks}\n'
)
continue
# NOTE: ticks are `.append()`-ed to the `ticks_by_type: dict` by the
# `._sampling.uniform_rate_send()` loop
tick = ticks[-1] # get most recent value
@ -652,16 +671,18 @@ def graphics_update_cycle(
if (
price < mn
):
if debug_n_trace:
log.info(f'{this_viz.name} new MN from TICK {mn} -> {price}')
mn = price
yrange_margin = 0.16
# # print(f'{this_viz.name} new MN from TICK {mn}')
if (
price > mx
):
if debug_n_trace:
log.info(f'{this_viz.name} new MX from TICK {mx} -> {price}')
mx = price
yrange_margin = 0.16
# # print(f'{this_viz.name} new MX from TICK {mx}')
# mx = max(price, mx)
# mn = min(price, mn)
@ -719,6 +740,7 @@ def graphics_update_cycle(
):
l1.bid_label.update_fields({'level': price, 'size': size})
if debug_n_trace:
profiler('L1 labels updates')
# Y-autoranging: adjust y-axis limits based on state tracking
@ -737,9 +759,14 @@ def graphics_update_cycle(
# complain about out-of-range outliers which can show up
# in certain annoying feeds (like ib)..
if (
lmx
and lmn
and (
abs(mx_diff) > .25 * lmx
or
abs(mn_diff) > .25 * lmn
)
and debug_n_trace
):
log.error(
f'WTF MN/MX IS WAY OFF:\n'
@ -750,6 +777,9 @@ def graphics_update_cycle(
f'mx_diff: {mx_diff}\n'
f'mn_diff: {mn_diff}\n'
)
chart.pause_all_feeds()
breakpoint()
chart.resume_all_feeds()
# TODO: track local liv maxmin without doing a recompute all the
# time..plus, just generally the user is more likely to be
@ -792,6 +822,7 @@ def graphics_update_cycle(
},
}
)
if debug_n_trace:
profiler('main vb y-autorange')
# SLOW CHART y-auto-range resize casd
@ -820,6 +851,7 @@ def graphics_update_cycle(
# f'datetime: {dt}\n'
# )
# if debug_n_trace:
# profiler('hist `Viz.incr_info()`')
# hist_chart = ds.hist_chart
@ -876,7 +908,7 @@ def graphics_update_cycle(
# `draw_last_datum()` ..
only_last_uppx=True,
)
if debug_n_trace:
profiler('overlays updates')
# volume chart logic..
@ -925,6 +957,7 @@ def graphics_update_cycle(
# connected to update accompanying overlay
# graphics..
)
if debug_n_trace:
profiler('`main_vlm_viz.update_graphics()`')
if (
@ -948,6 +981,7 @@ def graphics_update_cycle(
},
},
)
if debug_n_trace:
profiler('`vlm_chart.view.interact_graphics_cycle()`')
# update all downstream FSPs
@ -968,6 +1002,7 @@ def graphics_update_cycle(
curve_name,
array_key=curve_name,
)
if debug_n_trace:
profiler(f'vlm `Viz[{viz.name}].update_graphics()`')
# is this even doing anything?
@ -980,6 +1015,7 @@ def graphics_update_cycle(
# do_linked_charts=False,
# do_overlay_scaling=False,
# )
if debug_n_trace:
profiler(
f'Viz[{viz.name}].plot.vb.interact_graphics_cycle()`'
)
@ -996,10 +1032,13 @@ def graphics_update_cycle(
# always update the last datum-element
# graphic for all vizs
viz.draw_last(array_key=curve_name)
if debug_n_trace:
profiler(f'vlm `Viz[{viz.name}].draw_last()`')
if debug_n_trace:
profiler('vlm Viz all updates complete')
if debug_n_trace:
profiler.finish()