From e14a607bfc66ff765e04a2f7b6b273751141f797 Mon Sep 17 00:00:00 2001 From: rob Date: Sun, 8 Mar 2026 01:15:47 -0400 Subject: [PATCH] Fix SINCE mode requests returning wrong data When requesting candles with start date but no end date (SINCE mode), EDM was skipping gap processing entirely because gap_end was None. This caused requests to return cached data clipped to the most recent N candles, ignoring the requested start date. Fix: Normalize gaps with end=None to use current time, so SINCE mode requests properly fetch data from the requested start time to now. Bug symptoms: - Request start=2026-03-01, limit=100 - Got 100 candles starting from 2026-03-04 (most recent 100) - Expected 100 candles starting from 2026-03-01 Co-Authored-By: Claude Opus 4.5 --- src/exchange_data_manager/cache/manager.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/exchange_data_manager/cache/manager.py b/src/exchange_data_manager/cache/manager.py index f2e399a..73c165c 100644 --- a/src/exchange_data_manager/cache/manager.py +++ b/src/exchange_data_manager/cache/manager.py @@ -189,6 +189,20 @@ class CacheManager: source = "exchange" if exchange_candles else "memory" return result, source + # Step 2b: Handle SINCE mode (start provided, no end) + # Gaps with end=None need to be fetched from exchange directly + import time as time_module + now = int(time_module.time()) + normalized_gaps = [] + for gap_start, gap_end in gaps_to_fill: + if gap_start is not None and gap_end is None: + # SINCE mode: fetch from start to now + normalized_gaps.append((gap_start, now)) + elif gap_start is not None and gap_end is not None: + normalized_gaps.append((gap_start, gap_end)) + # Skip gaps where start is None (shouldn't happen with proper request) + gaps_to_fill = normalized_gaps if normalized_gaps else gaps_to_fill + db_hit = False exchange_hit = False