ohlc retained length fix
This commit is contained in:
@@ -359,7 +359,7 @@ class OHLCRepository:
|
|||||||
if price is None, then bars are advanced based on the time but no new price is added to the series.
|
if price is None, then bars are advanced based on the time but no new price is added to the series.
|
||||||
"""
|
"""
|
||||||
if OHLC_LIMIT_POOLS_DEBUG is not None and (symbol,period) not in OHLC_LIMIT_POOLS_DEBUG:
|
if OHLC_LIMIT_POOLS_DEBUG is not None and (symbol,period) not in OHLC_LIMIT_POOLS_DEBUG:
|
||||||
return
|
return None
|
||||||
# logname = f'{symbol} {period_name(period)}'
|
# logname = f'{symbol} {period_name(period)}'
|
||||||
# log.debug(f'Updating OHLC {logname} {minutely(time)} {price}')
|
# log.debug(f'Updating OHLC {logname} {minutely(time)} {price}')
|
||||||
if price is not None:
|
if price is not None:
|
||||||
@@ -371,33 +371,31 @@ class OHLCRepository:
|
|||||||
# log.debug(f'got recent {historical}')
|
# log.debug(f'got recent {historical}')
|
||||||
if not historical:
|
if not historical:
|
||||||
if create is False or price is None:
|
if create is False or price is None:
|
||||||
return # do not track symbols which have not been explicity set up
|
return None # do not track symbols which have not been explicity set up
|
||||||
historical = []
|
|
||||||
updated = [NativeOHLC(ohlc_start_time(time, period), price, price, price, price)]
|
updated = [NativeOHLC(ohlc_start_time(time, period), price, price, price, price)]
|
||||||
# log.debug(f'\tcreated new bars {updated}')
|
# log.debug(f'\tcreated new bars {updated}')
|
||||||
else:
|
else:
|
||||||
updated = update_ohlc(historical[-1], period, time, price)
|
updated = update_ohlc(historical[-1], period, time, price)
|
||||||
# drop any historical bars that are older than we need
|
# overlap the updated OHLC's on top of the historical ones
|
||||||
# oldest_needed = cover the root block time plus one period prior
|
|
||||||
root_branch = current_blockstate.get().root_branch
|
|
||||||
root_hash = root_branch.head
|
|
||||||
if root_hash is not None:
|
|
||||||
root_timestamp = await get_block_timestamp(root_hash)
|
|
||||||
oldest_needed = from_timestamp(root_timestamp) - period
|
|
||||||
# noinspection PyTypeChecker
|
|
||||||
trim = (oldest_needed - historical[0].start) // period
|
|
||||||
if trim > 0:
|
|
||||||
historical = historical[trim:]
|
|
||||||
|
|
||||||
# now overlap the updated data on top of the historical data
|
|
||||||
if not historical or not updated:
|
|
||||||
updated = historical + updated
|
|
||||||
else:
|
|
||||||
last_bar = historical[-1].start
|
last_bar = historical[-1].start
|
||||||
first_updated = updated[0].start
|
first_updated = updated[0].start
|
||||||
overlap = (first_updated - last_bar) // period + 1
|
overlap = (first_updated - last_bar) // period + 1
|
||||||
updated = historical[:-overlap] + updated if overlap > 0 else historical + updated
|
updated = historical[:-overlap] + updated if overlap > 0 else historical + updated
|
||||||
# log.debug(f'\tnew recents: {updated}')
|
|
||||||
|
# drop any bars that are older than we need
|
||||||
|
# oldest_needed = cover the root block time plus one period prior
|
||||||
|
root_branch = current_blockstate.get().root_branch
|
||||||
|
root_hash = root_branch.head
|
||||||
|
if root_hash is not None:
|
||||||
|
root_timestamp = await get_block_timestamp(root_hash)
|
||||||
|
oldest_needed = from_timestamp(root_timestamp) - period
|
||||||
|
# noinspection PyTypeChecker
|
||||||
|
trim = (oldest_needed - updated[0].start) // period
|
||||||
|
if trim > 0:
|
||||||
|
updated = updated[trim:]
|
||||||
|
|
||||||
|
if len(updated) > 3:
|
||||||
|
log.debug(f'\tnew recents ({len(updated)}): {updated}')
|
||||||
recent_ohlcs.setitem(key, updated)
|
recent_ohlcs.setitem(key, updated)
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user