ib; return `None` on empty bars frame resp so as to trigger raising `NoData` in the caller

distribute_dis
Tyler Goodlet 2024-01-03 18:16:48 -05:00
parent 2669db785c
commit b23d44e21a
1 changed files with 39 additions and 43 deletions

View File

@ -434,57 +434,53 @@ async def get_bars(
# current impl) to detect a cancel case. # current impl) to detect a cancel case.
# timeout=timeout, # timeout=timeout,
) )
# usually either a request during a venue closure
# or into a large (weekend) closure gap.
if not bars:
# no data returned?
log.warning(
'History frame is blank?\n'
f'start_dt: {start_dt}\n'
f'end_dt: {end_dt}\n'
f'duration: {dt_duration}\n'
)
# NOTE: REQUIRED to pass back value..
result = None
return None
# not enough bars signal, likely due to venue # not enough bars signal, likely due to venue
# operational gaps. # operational gaps.
# too_little: bool = False
if end_dt: if end_dt:
if not bars: dur_s: float = len(bars) * timeframe
# no data returned? bars_dur = Duration(seconds=dur_s)
dt_dur_s: float = dt_duration.in_seconds()
if dur_s < dt_dur_s:
log.warning( log.warning(
'History frame is blank?\n' 'History frame is shorter then expected?\n'
f'start_dt: {start_dt}\n' f'start_dt: {start_dt}\n'
f'end_dt: {end_dt}\n' f'end_dt: {end_dt}\n'
f'duration: {dt_duration}\n' f'duration: {dt_dur_s}\n'
f'frame duration seconds: {dur_s}\n'
f'dur diff: {dt_duration - bars_dur}\n'
) )
result = None # NOTE: we used to try to get a minimal
return None # set of bars by recursing but this ran
# raise NoData( # into possible infinite query loops
# f'{fqme}\n' # when logic in the `Client.bars()` dt
# f'end_dt:{end_dt}\n' # diffing went bad. So instead for now
# ) # we just return the
# shorter-then-expected history with
else: # a warning.
dur_s: float = len(bars) * timeframe # TODO: in the future it prolly makes
bars_dur = Duration(seconds=dur_s) # the most send to do venue operating
dt_dur_s: float = dt_duration.in_seconds() # hours lookup and
if dur_s < dt_dur_s: # timestamp-in-operating-range set
log.warning( # checking to know for sure if we can
'History frame is shorter then expected?\n' # safely and quickly ignore non-uniform history
f'start_dt: {start_dt}\n' # frame timestamp gaps..
f'end_dt: {end_dt}\n' # end_dt -= dt_duration
f'duration: {dt_dur_s}\n' # continue
f'frame duration seconds: {dur_s}\n' # await tractor.pause()
f'dur diff: {dt_duration - bars_dur}\n'
)
# NOTE: we used to try to get a minimal
# set of bars by recursing but this ran
# into possible infinite query loops
# when logic in the `Client.bars()` dt
# diffing went bad. So instead for now
# we just return the
# shorter-then-expected history with
# a warning.
# TODO: in the future it prolly makes
# the most send to do venue operating
# hours lookup and
# timestamp-in-operating-range set
# checking to know for sure if we can
# safely and quickly ignore non-uniform history
# frame timestamp gaps..
# end_dt -= dt_duration
# continue
# await tractor.pause()
first_dt = from_timestamp( first_dt = from_timestamp(
bars[0].date.timestamp()) bars[0].date.timestamp())