infinite scroll fix
This commit is contained in:
@@ -189,7 +189,8 @@ class DuckDBStorage:
|
||||
def get_ohlcv_data(self, symbol: str, timeframe: str,
|
||||
start_time: Optional[datetime] = None,
|
||||
end_time: Optional[datetime] = None,
|
||||
limit: Optional[int] = None) -> Optional[pd.DataFrame]:
|
||||
limit: Optional[int] = None,
|
||||
direction: str = 'latest') -> Optional[pd.DataFrame]:
|
||||
"""
|
||||
Query OHLCV data directly from DuckDB table
|
||||
|
||||
@@ -199,6 +200,7 @@ class DuckDBStorage:
|
||||
start_time: Start time filter
|
||||
end_time: End time filter
|
||||
limit: Maximum number of candles
|
||||
direction: 'latest' (most recent), 'before' (older data), 'after' (newer data)
|
||||
|
||||
Returns:
|
||||
DataFrame with OHLCV data
|
||||
@@ -212,15 +214,28 @@ class DuckDBStorage:
|
||||
"""
|
||||
params = [symbol, timeframe]
|
||||
|
||||
if start_time:
|
||||
query += " AND timestamp >= ?"
|
||||
params.append(int(start_time.timestamp() * 1000))
|
||||
|
||||
if end_time:
|
||||
query += " AND timestamp <= ?"
|
||||
# Handle different direction modes
|
||||
if direction == 'before' and end_time:
|
||||
# Get older data: candles BEFORE end_time
|
||||
query += " AND timestamp < ?"
|
||||
params.append(int(end_time.timestamp() * 1000))
|
||||
|
||||
query += " ORDER BY timestamp DESC"
|
||||
query += " ORDER BY timestamp DESC"
|
||||
elif direction == 'after' and start_time:
|
||||
# Get newer data: candles AFTER start_time
|
||||
query += " AND timestamp > ?"
|
||||
params.append(int(start_time.timestamp() * 1000))
|
||||
query += " ORDER BY timestamp ASC"
|
||||
else:
|
||||
# Default: get most recent data in range
|
||||
if start_time:
|
||||
query += " AND timestamp >= ?"
|
||||
params.append(int(start_time.timestamp() * 1000))
|
||||
|
||||
if end_time:
|
||||
query += " AND timestamp <= ?"
|
||||
params.append(int(end_time.timestamp() * 1000))
|
||||
|
||||
query += " ORDER BY timestamp DESC"
|
||||
|
||||
if limit:
|
||||
query += f" LIMIT {limit}"
|
||||
@@ -236,7 +251,7 @@ class DuckDBStorage:
|
||||
df = df.set_index('timestamp')
|
||||
df = df.sort_index()
|
||||
|
||||
logger.debug(f"Retrieved {len(df)} candles for {symbol} {timeframe} from DuckDB")
|
||||
logger.debug(f"Retrieved {len(df)} candles for {symbol} {timeframe} from DuckDB (direction={direction})")
|
||||
return df
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user