From 0ba3c798d7ab4bb36bdce28450971bf4187dba17 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 2 Jun 2023 12:15:33 -0400 Subject: [PATCH] Drop `bar_wap` from default ohlc field set Turns out no backend (including kraken) requires it and really this kinda of measure should be implemented and recorded from our fsp layer instead of (hackily) sometimes expecting it to be in "source data". --- piker/brokers/ib/api.py | 15 +++++++++------ piker/brokers/kucoin.py | 3 +-- piker/data/_sampling.py | 5 +++-- piker/data/_source.py | 2 +- piker/ui/_cursor.py | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/piker/brokers/ib/api.py b/piker/brokers/ib/api.py index 8fc8c651..a5069e95 100644 --- a/piker/brokers/ib/api.py +++ b/piker/brokers/ib/api.py @@ -82,10 +82,7 @@ from piker.brokers._util import ( get_logger, ) -# Broker specific ohlc schema which includes a vwap field -_ohlc_dtype: list[tuple[str, type]] = [ - ('index', int), - +_bar_load_dtype: list[tuple[str, type]] = [ # NOTE XXX: only part that's diff # from our default fields where # time is normally an int. @@ -99,9 +96,15 @@ _ohlc_dtype: list[tuple[str, type]] = [ ('close', float), ('volume', float), ('count', int), - ('bar_wap', float), # Wait do we need this? ] +# Broker specific ohlc schema which includes a vwap field +_ohlc_dtype: list[tuple[str, type]] = _bar_load_dtype.copy() +_ohlc_dtype.insert( + 0, + ('index', int), +) + _time_units = { 's': ' sec', @@ -317,7 +320,7 @@ def bars_to_np(bars: list) -> np.ndarray: nparr = np.array( np_ready, - dtype=_ohlc_dtype, + dtype=_bar_load_dtype, ) assert nparr['time'][0] == bars[0].date.timestamp() assert nparr['time'][-1] == bars[-1].date.timestamp() diff --git a/piker/brokers/kucoin.py b/piker/brokers/kucoin.py index 2ab4a785..e3ef599e 100755 --- a/piker/brokers/kucoin.py +++ b/piker/brokers/kucoin.py @@ -455,7 +455,6 @@ class Client: ('low', float), ('close', float), ('volume', float), - ('bar_wap', float), # will be zeroed by sampler if not filled ] ''' @@ -520,7 +519,7 @@ class Client: # volume float(bar[5]), # bar_wap - 0.0, + # 0.0, ) ) diff --git a/piker/data/_sampling.py b/piker/data/_sampling.py index 20bf9b49..af8216c3 100644 --- a/piker/data/_sampling.py +++ b/piker/data/_sampling.py @@ -505,6 +505,7 @@ async def open_sample_stream( }, ) as (ctx, first) ): + assert len(first) > 1 async with ( ctx.open_stream() as istream, @@ -591,14 +592,14 @@ async def sample_and_broadcast( 'high', 'low', 'close', - 'bar_wap', # can be optionally provided + # 'bar_wap', # can be optionally provided 'volume', ]][-1] = ( o, max(high, last), min(low, last), last, - quote.get('bar_wap', 0), + # quote.get('bar_wap', 0), volume, ) diff --git a/piker/data/_source.py b/piker/data/_source.py index 7f739d7d..fc22d6f4 100644 --- a/piker/data/_source.py +++ b/piker/data/_source.py @@ -47,7 +47,7 @@ def_iohlcv_fields: list[tuple[str, type]] = [ # TODO: can we elim this from default field set to save on mem? # i think only kraken really uses this in terms of what we get from # their ohlc history API? - ('bar_wap', float), # shouldn't be default right? + # ('bar_wap', float), # shouldn't be default right? ] # remove index field diff --git a/piker/ui/_cursor.py b/piker/ui/_cursor.py index 0a2c82b1..f69f503a 100644 --- a/piker/ui/_cursor.py +++ b/piker/ui/_cursor.py @@ -215,8 +215,8 @@ class ContentsLabel(pg.LabelItem): "H:{}
" "L:{}
" "C:{}
" - "V:{}
" - "wap:{}".format( + "V:{}
".format( + # "wap:{}".format( *array[ix][ [ 'time', @@ -225,7 +225,7 @@ class ContentsLabel(pg.LabelItem): 'low', 'close', 'volume', - 'bar_wap', + # 'bar_wap', ] ], # name=name,