From 2399c618b6dde3fbddc596610a2a3fd287966691 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 24 Nov 2022 15:05:06 -0500 Subject: [PATCH] Expand sampler loop shm write lines --- piker/data/_sampling.py | 43 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/piker/data/_sampling.py b/piker/data/_sampling.py index 143f1c19..f3c92d56 100644 --- a/piker/data/_sampling.py +++ b/piker/data/_sampling.py @@ -128,22 +128,43 @@ async def increment_ohlc_buffer( # TODO: ``numba`` this! for shm in shms: + # append new entry to buffer thus "incrementing" the bar + array = shm.array + last = array[-1:][shm._write_fields].copy() + + (t, close) = last[0][[ + 'time', + 'close', + ]] + + # this copies non-std fields (eg. vwap) from the last datum + last[[ + 'time', + + 'open', + 'high', + 'low', + 'close', + + 'volume', + ]][0] = ( + # epoch timestamp + t + this_delay_s, + + # OHLC + close, + close, + close, + close, + + 0, # vlm + ) + # TODO: in theory we could make this faster by copying the # "last" readable value into the underlying larger buffer's # next value and then incrementing the counter instead of # using ``.push()``? - # append new entry to buffer thus "incrementing" the bar - array = shm.array - last = array[-1:][shm._write_fields].copy() - # (index, t, close) = last[0][['index', 'time', 'close']] - (t, close) = last[0][['time', 'close']] - - # this copies non-std fields (eg. vwap) from the last datum - last[ - ['time', 'volume', 'open', 'high', 'low', 'close'] - ][0] = (t + this_delay_s, 0, close, close, close, close) - # write to the buffer shm.push(last)