From 137aee510b09d123da515408c48d5037aa233207 Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 3 Mar 2026 16:24:38 -0500 Subject: [PATCH] Warn instead of raise on `start_dt`-trimmed frames Downgrade the `start_dt`-trimming check in `open_history_client()` from a `RuntimeError` raise to a warning log, allowing the caller to still receive a (shorter) frame of bars (though we may need to still specially handle such cases in the backfiller's biz logic layer). Deats, - add `trimmed_bars.size` guard to skip check on empty results. - change condition to `>=` and log a warning with the short-frame size instead of raising. - comment-out `raise RuntimeError` and breakpoint for future removal once confident. - add docstring-style comment on `start_dt=` kwarg noting that `Client.bars()` doesn't truly support it (uses duration-style queries internally). (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/brokers/ib/feed.py | 43 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/piker/brokers/ib/feed.py b/piker/brokers/ib/feed.py index e148bca4..fc273c07 100644 --- a/piker/brokers/ib/feed.py +++ b/piker/brokers/ib/feed.py @@ -201,6 +201,15 @@ async def open_history_client( fqme, timeframe, end_dt=end_dt, + + # XXX WARNING, we don't actually use this inside + # `Client.bars()` since it isn't really supported, + # the API instead supports a "duration" of time style + # from the `end_dt` (or at least that was the best + # way to get it working sanely).. + # + # SO, with that in mind be aware that any downstream + # logic based on this may be mostly futile Xp start_dt=start_dt, ) latency = time.time() - query_start @@ -278,19 +287,27 @@ async def open_history_client( trimmed_bars = bars_array[ bars_array['time'] >= start_dt.timestamp() ] - if ( - trimmed_first_dt := from_timestamp(trimmed_bars['time'][0]) - != - start_dt - ): - # TODO! rm this once we're more confident it never hits! - # breakpoint() - raise RuntimeError( - f'OHLC-bars array start is gt `start_dt` limit !!\n' - f'start_dt: {start_dt}\n' - f'first_dt: {first_dt}\n' - f'trimmed_first_dt: {trimmed_first_dt}\n' - ) + # XXX, should NEVER get HERE! + if trimmed_bars.size: + trimmed_first_dt: datetime = from_timestamp(trimmed_bars['time'][0]) + if ( + trimmed_first_dt + >= + start_dt + ): + msg: str = ( + f'OHLC-bars array start is gt `start_dt` limit !!\n' + f'start_dt: {start_dt}\n' + f'first_dt: {first_dt}\n' + f'trimmed_first_dt: {trimmed_first_dt}\n' + f'\n' + f'Delivering shorted frame of {trimmed_bars.size!r}\n' + ) + log.warning(msg) + # TODO! rm this once we're more confident it + # never breaks anything (in the caller)! + # breakpoint() + # raise RuntimeError(msg) # XXX, overwrite with start_dt-limited frame bars_array = trimmed_bars