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".
basic_buy_bot
Tyler Goodlet 2023-06-02 12:15:33 -04:00
parent 7b4f4bf804
commit 0ba3c798d7
5 changed files with 17 additions and 14 deletions

View File

@ -82,10 +82,7 @@ from piker.brokers._util import (
get_logger, get_logger,
) )
# Broker specific ohlc schema which includes a vwap field _bar_load_dtype: list[tuple[str, type]] = [
_ohlc_dtype: list[tuple[str, type]] = [
('index', int),
# NOTE XXX: only part that's diff # NOTE XXX: only part that's diff
# from our default fields where # from our default fields where
# time is normally an int. # time is normally an int.
@ -99,9 +96,15 @@ _ohlc_dtype: list[tuple[str, type]] = [
('close', float), ('close', float),
('volume', float), ('volume', float),
('count', int), ('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 = { _time_units = {
's': ' sec', 's': ' sec',
@ -317,7 +320,7 @@ def bars_to_np(bars: list) -> np.ndarray:
nparr = np.array( nparr = np.array(
np_ready, np_ready,
dtype=_ohlc_dtype, dtype=_bar_load_dtype,
) )
assert nparr['time'][0] == bars[0].date.timestamp() assert nparr['time'][0] == bars[0].date.timestamp()
assert nparr['time'][-1] == bars[-1].date.timestamp() assert nparr['time'][-1] == bars[-1].date.timestamp()

View File

@ -455,7 +455,6 @@ class Client:
('low', float), ('low', float),
('close', float), ('close', float),
('volume', float), ('volume', float),
('bar_wap', float), # will be zeroed by sampler if not filled
] ]
''' '''
@ -520,7 +519,7 @@ class Client:
# volume # volume
float(bar[5]), float(bar[5]),
# bar_wap # bar_wap
0.0, # 0.0,
) )
) )

View File

@ -505,6 +505,7 @@ async def open_sample_stream(
}, },
) as (ctx, first) ) as (ctx, first)
): ):
assert len(first) > 1
async with ( async with (
ctx.open_stream() as istream, ctx.open_stream() as istream,
@ -591,14 +592,14 @@ async def sample_and_broadcast(
'high', 'high',
'low', 'low',
'close', 'close',
'bar_wap', # can be optionally provided # 'bar_wap', # can be optionally provided
'volume', 'volume',
]][-1] = ( ]][-1] = (
o, o,
max(high, last), max(high, last),
min(low, last), min(low, last),
last, last,
quote.get('bar_wap', 0), # quote.get('bar_wap', 0),
volume, volume,
) )

View File

@ -47,7 +47,7 @@ def_iohlcv_fields: list[tuple[str, type]] = [
# TODO: can we elim this from default field set to save on mem? # 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 # i think only kraken really uses this in terms of what we get from
# their ohlc history API? # their ohlc history API?
('bar_wap', float), # shouldn't be default right? # ('bar_wap', float), # shouldn't be default right?
] ]
# remove index field # remove index field

View File

@ -215,8 +215,8 @@ class ContentsLabel(pg.LabelItem):
"<b>H</b>:{}<br/>" "<b>H</b>:{}<br/>"
"<b>L</b>:{}<br/>" "<b>L</b>:{}<br/>"
"<b>C</b>:{}<br/>" "<b>C</b>:{}<br/>"
"<b>V</b>:{}<br/>" "<b>V</b>:{}<br/>".format(
"<b>wap</b>:{}".format( # "<b>wap</b>:{}".format(
*array[ix][ *array[ix][
[ [
'time', 'time',
@ -225,7 +225,7 @@ class ContentsLabel(pg.LabelItem):
'low', 'low',
'close', 'close',
'volume', 'volume',
'bar_wap', # 'bar_wap',
] ]
], ],
# name=name, # name=name,