Write shm volume (facepalm), update open=close on first volume

bar_select
Tyler Goodlet 2020-11-03 08:14:37 -05:00
parent b23e459027
commit 1640906b09
2 changed files with 35 additions and 5 deletions

View File

@ -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']

View File

@ -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``