From 1640906b097b19be359b1b3bd27c6da4f6b37c84 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 3 Nov 2020 08:14:37 -0500 Subject: [PATCH] Write shm volume (facepalm), update open=close on first volume --- piker/brokers/ib.py | 17 ++++++++++++++--- piker/brokers/kraken.py | 23 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index c2067665..94adb39e 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -645,15 +645,26 @@ async def stream_quotes( if not writer_already_exists: for tick in iterticks(quote, type='trade'): last = tick['price'] - # print(f'broker last: {tick}') # update last entry # benchmarked in the 4-5 us range - high, low = shm.array[-1][['high', 'low']] - shm.array[['high', 'low', 'close']][-1] = ( + o, high, low, v = shm.array[-1][ + ['open', 'high', 'low', 'volume'] + ] + + new_v = tick['size'] + + if v == 0 and new_v: + # no trades for this bar yet so the open + # is also the close/last trade price + o = last + + shm.array[['open', 'high', 'low', 'close', 'volume']][-1] = ( + o, max(high, last), min(low, last), last, + v + new_v, ) con = quote['contract'] diff --git a/piker/brokers/kraken.py b/piker/brokers/kraken.py index 3d1d8e7a..21627c69 100644 --- a/piker/brokers/kraken.py +++ b/piker/brokers/kraken.py @@ -342,12 +342,31 @@ async def stream_quotes( if not writer_exists: # update last entry # benchmarked in the 4-5 us range - high, low = shm.array[-1][['high', 'low']] - shm.array[['high', 'low', 'close', 'vwap']][-1] = ( + o, high, low, v = shm.array[-1][ + ['open', 'high', 'low', 'volume'] + ] + new_v = tick_volume + + if v == 0 and new_v: + # no trades for this bar yet so the open + # is also the close/last trade price + o = last + + # write shm + shm.array[ + ['open', + 'high', + 'low', + 'close', + 'vwap', + 'volume'] + ][-1] = ( + o, max(high, last), min(low, last), last, ohlc.vwap, + volume, ) # XXX: format required by ``tractor.msg.pub``