Update L1 labels in price loop

bar_select
Tyler Goodlet 2020-11-03 22:03:49 -05:00
parent 73e54a2259
commit f438139ad7
1 changed files with 59 additions and 28 deletions

View File

@ -19,6 +19,7 @@ from ._graphics import (
ContentsLabel, ContentsLabel,
BarItems, BarItems,
level_line, level_line,
L1Labels,
) )
from ._axes import YSticky from ._axes import YSticky
from ._style import ( from ._style import (
@ -504,7 +505,7 @@ class ChartPlotWidget(pg.PlotWidget):
# TODO: something instead of stickies for overlays # TODO: something instead of stickies for overlays
# (we need something that avoids clutter on x-axis). # (we need something that avoids clutter on x-axis).
self._add_sticky(name) self._add_sticky(name, bg_color='default_light')
label = ContentsLabel(chart=self, anchor_at=anchor_at) label = ContentsLabel(chart=self, anchor_at=anchor_at)
self._labels[name] = (label, partial(label.update_from_value, name)) self._labels[name] = (label, partial(label.update_from_value, name))
@ -519,6 +520,7 @@ class ChartPlotWidget(pg.PlotWidget):
def _add_sticky( def _add_sticky(
self, self,
name: str, name: str,
bg_color='bracket',
# retreive: Callable[None, np.ndarray], # retreive: Callable[None, np.ndarray],
) -> YSticky: ) -> YSticky:
# add y-axis "last" value label # add y-axis "last" value label
@ -528,6 +530,7 @@ class ChartPlotWidget(pg.PlotWidget):
# TODO: pass this from symbol data # TODO: pass this from symbol data
# digits=0, # digits=0,
opacity=1, opacity=1,
bg_color=bg_color,
) )
return last return last
@ -801,10 +804,19 @@ async def chart_from_quotes(
last_bars_range, last_mx, last_mn = maxmin() last_bars_range, last_mx, last_mn = maxmin()
chart.default_view() chart.default_view()
l1 = L1Labels(chart)
last_bid = last_ask = ohlcv.array[-1]['close']
async for quotes in stream: async for quotes in stream:
for sym, quote in quotes.items(): for sym, quote in quotes.items():
for tick in iterticks(quote, type='trade'): for tick in quote.get('ticks', ()):
# for tick in iterticks(quote, type='trade'):
ticktype = tick.get('type')
price = tick.get('price')
if ticktype in ('trade', 'utrade'):
array = ohlcv.array array = ohlcv.array
# update price sticky(s) # update price sticky(s)
@ -837,6 +849,25 @@ async def chart_from_quotes(
# - in theory we should be able to read buffer data # - in theory we should be able to read buffer data
# faster then msgs arrive.. needs some tinkering and testing # faster then msgs arrive.. needs some tinkering and testing
# if trade volume jumps above / below prior L1 price
# levels adjust bid / ask lines to match
if price > last_ask:
l1.ask_label.update_from_data(0, price)
last_ask = price
elif price < last_bid:
l1.bid_label.update_from_data(0, price)
last_bid = price
elif ticktype == 'ask':
l1.ask_label.update_from_data(0, price)
last_ask = price
elif ticktype == 'bid':
l1.bid_label.update_from_data(0, price)
last_bid = price
async def chart_from_fsp( async def chart_from_fsp(
linked_charts, linked_charts,
@ -931,7 +962,7 @@ async def chart_from_fsp(
# add moveable over-[sold/bought] lines # add moveable over-[sold/bought] lines
level_line(chart, 30) level_line(chart, 30)
level_line(chart, 70) level_line(chart, 70, orient_v='top')
chart._shm = shm chart._shm = shm
chart._set_yrange() chart._set_yrange()