Yield history `dict`s, add a `flow_rates` fsp

windows_fixes_yo
Tyler Goodlet 2022-02-01 15:18:12 -05:00
parent 1aae40cdeb
commit dfe4473c9a
1 changed files with 53 additions and 4 deletions

View File

@ -108,7 +108,6 @@ async def tina_vwap(
@fsp( @fsp(
outputs=('dolla_vlm', 'dark_vlm'), outputs=('dolla_vlm', 'dark_vlm'),
ohlc=False,
curve_style='step', curve_style='step',
) )
async def dolla_vlm( async def dolla_vlm(
@ -132,14 +131,24 @@ async def dolla_vlm(
v = a['volume'] v = a['volume']
# on first iteration yield history # on first iteration yield history
yield chl3 * v yield {
'dolla_vlm': chl3 * v,
'dark_vlm': None,
}
i = ohlcv.index i = ohlcv.index
output = vlm = 0 output = vlm = 0
dvlm = 0 dvlm = 0
async for quote in source: async for quote in source:
for tick in iterticks(quote): for tick in iterticks(
quote,
types=(
'trade',
'dark_trade',
),
deduplicate_darks=True,
):
# this computes tick-by-tick weightings from here forward # this computes tick-by-tick weightings from here forward
size = tick['size'] size = tick['size']
@ -156,13 +165,15 @@ async def dolla_vlm(
# is reported in the sym info. # is reported in the sym info.
ttype = tick.get('type') ttype = tick.get('type')
if ttype == 'dark_trade': if ttype == 'dark_trade':
print(f'dark_trade: {tick}') # print(f'dark_trade: {tick}')
key = 'dark_vlm' key = 'dark_vlm'
dvlm += price * size dvlm += price * size
output = dvlm output = dvlm
else: else:
# print(f'vlm: {tick}')
key = 'dolla_vlm' key = 'dolla_vlm'
vlm += price * size vlm += price * size
output = vlm output = vlm
@ -175,3 +186,41 @@ async def dolla_vlm(
# print(f' tinal vlm: {tina_lvlm}') # print(f' tinal vlm: {tina_lvlm}')
yield key, output yield key, output
@fsp(
outputs=(
'1m_trade_rate',
'1m_vlm_rate',
),
curve_style='step',
)
async def flow_rates(
source: AsyncReceiver[dict],
ohlcv: ShmArray, # OHLC sampled history
) -> AsyncIterator[
tuple[str, Union[np.ndarray, float]],
]:
# generally no history available prior to real-time calcs
yield {
'1m_trade_rate': None,
'1m_vlm_rate': None,
}
ltr = 0
lvr = 0
async for quote in source:
if quote:
tr = quote['tradeRate'],
if tr != ltr:
print(f'trade rate: {tr}')
yield '1m_trade_rate', tr
ltr = tr
vr = quote['volumeRate'],
if vr != lvr:
print(f'vlm rate: {tr}')
yield '1m_vlm_rate', tr
ltr = tr