Update vlm sticky

windows_testing_volume
Tyler Goodlet 2021-09-21 08:14:22 -04:00
parent d751707e06
commit 6a82b1802b
1 changed files with 26 additions and 11 deletions

View File

@ -19,7 +19,7 @@ Real-time display tasks for charting / graphics.
''' '''
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pprint import pformat # from pprint import pformat
import time import time
from types import ModuleType from types import ModuleType
from typing import Optional from typing import Optional
@ -57,11 +57,12 @@ _clear_throttle_rate: int = 58 # Hz
_book_throttle_rate: int = 16 # Hz _book_throttle_rate: int = 16 # Hz
async def chart_from_quotes( async def update_chart_from_quotes(
chart: ChartPlotWidget, chart: ChartPlotWidget,
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, vlm_chart: Optional[ChartPlotWidget] = None,
@ -78,7 +79,8 @@ async def chart_from_quotes(
# - handle odd lot orders # - handle odd lot orders
# - update last open price correctly instead # - update last open price correctly instead
# of copying it from last bar's close # of copying it from last bar's close
# - 5 sec bar lookback-autocorrection like tws does? # - 1-5 sec bar lookback-autocorrection like tws does?
# (would require a background history checker task)
# update last price sticky # update last price sticky
last_price_sticky = chart._ysticks[chart.name] last_price_sticky = chart._ysticks[chart.name]
@ -86,6 +88,9 @@ async def chart_from_quotes(
*ohlcv.array[-1][['index', 'close']] *ohlcv.array[-1][['index', 'close']]
) )
if vlm_chart:
vlm_sticky = vlm_chart._ysticks['volume']
def maxmin(): def maxmin():
# TODO: implement this # TODO: implement this
# https://arxiv.org/abs/cs/0610046 # https://arxiv.org/abs/cs/0610046
@ -127,11 +132,11 @@ async def chart_from_quotes(
# TODO: # TODO:
# - in theory we should be able to read buffer data faster # - in theory we should be able to read buffer data faster
# then msgs arrive.. needs some tinkering and testing # then msgs arrive.. needs some tinkering and testing
# - if trade volume jumps above / below prior L1 price # - if trade volume jumps above / below prior L1 price
# levels this might be dark volume we need to # levels this might be dark volume we need to
# present differently? # present differently -> likely dark vlm
tick_size = chart.linked.symbol.tick_size tick_size = chart.linked.symbol.tick_size
tick_margin = 2 * tick_size tick_margin = 2 * tick_size
@ -152,7 +157,8 @@ async def chart_from_quotes(
for tick in quote.get('ticks', ()): for tick in quote.get('ticks', ()):
# log.info(f"quotes: {pformat(quote['symbol'])}: {pformat(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')
@ -193,9 +199,14 @@ 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)
# TODO: show dark trades differently
# https://github.com/pikers/piker/issues/116
if vlm_chart: if vlm_chart:
print(f"volume: {end['volume']}") # print(f"volume: {end['volume']}")
vlm_chart.update_curve_from_array('volume', ohlcv.array) vlm_chart.update_curve_from_array(
'volume', ohlcv.array
)
vlm_sticky.update_from_data(*end[['index', 'volume']])
# l1 book events # l1 book events
# throttle the book graphics updates at a lower rate # throttle the book graphics updates at a lower rate
@ -701,9 +712,13 @@ async def maybe_open_vlm_display(
# curve by default # curve by default
ohlc=False, ohlc=False,
# Draw vertical bars from zero.
# we do this internally ourselves since
# the curve item internals are pretty convoluted.
style='step', style='step',
# vertical bars, we do this internally ourselves # original pyqtgraph flag for reference
# stepMode=True, # stepMode=True,
) )
@ -881,7 +896,7 @@ async def display_symbol_data(
# start graphics update loop(s)after receiving first live quote # start graphics update loop(s)after receiving first live quote
ln.start_soon( ln.start_soon(
chart_from_quotes, update_chart_from_quotes,
chart, chart,
feed.stream, feed.stream,
ohlcv, ohlcv,