Spaces:
Sleeping
Sleeping
Audit execution and add frozen research phases
Browse files- data/historical.py +13 -0
data/historical.py
CHANGED
|
@@ -8,6 +8,7 @@ from utils.helpers import feature_warmup_days
|
|
| 8 |
from data.validation import DataFetchError, validate_ohlcv, positive_integer
|
| 9 |
|
| 10 |
_YF_TIMEOUT_SECONDS = 30
|
|
|
|
| 11 |
OHLCV_COLUMNS = ['Open', 'High', 'Low', 'Close', 'Volume']
|
| 12 |
|
| 13 |
def _fetch_yf(symbol: str, interval: str, start: datetime, end: datetime) -> pd.DataFrame:
|
|
@@ -65,6 +66,16 @@ def _native_fetch(symbol: str, interval: str, days: int) -> pd.DataFrame:
|
|
| 65 |
while remaining > 0:
|
| 66 |
window_days = min(request_days, remaining)
|
| 67 |
window_start = window_end - timedelta(days=window_days)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
frame = _download_window(symbol, interval, window_start, window_end)
|
| 69 |
if not frame.empty:
|
| 70 |
frames.append(frame)
|
|
@@ -81,6 +92,8 @@ def _native_fetch(symbol: str, interval: str, days: int) -> pd.DataFrame:
|
|
| 81 |
df.attrs['effective_lookback_days'] = days
|
| 82 |
df.attrs['source_interval'] = interval
|
| 83 |
df.attrs['empty_request_windows'] = empty_windows
|
|
|
|
|
|
|
| 84 |
return df
|
| 85 |
|
| 86 |
def resample_ohlc(df: pd.DataFrame, rule: str, source_step=None) -> pd.DataFrame:
|
|
|
|
| 8 |
from data.validation import DataFetchError, validate_ohlcv, positive_integer
|
| 9 |
|
| 10 |
_YF_TIMEOUT_SECONDS = 30
|
| 11 |
+
_RETENTION_GUARD_SECONDS = 300
|
| 12 |
OHLCV_COLUMNS = ['Open', 'High', 'Low', 'Close', 'Volume']
|
| 13 |
|
| 14 |
def _fetch_yf(symbol: str, interval: str, start: datetime, end: datetime) -> pd.DataFrame:
|
|
|
|
| 66 |
while remaining > 0:
|
| 67 |
window_days = min(request_days, remaining)
|
| 68 |
window_start = window_end - timedelta(days=window_days)
|
| 69 |
+
retention_guard = (
|
| 70 |
+
_RETENTION_GUARD_SECONDS
|
| 71 |
+
if max_days is not None and days == max_days and remaining == window_days
|
| 72 |
+
else 0
|
| 73 |
+
)
|
| 74 |
+
# A start at exactly now-minus-retention can age outside Yahoo's
|
| 75 |
+
# inclusive rolling bound while its request is in flight. Keep a
|
| 76 |
+
# small fixed provider guard, not a result-dependent shorter sample.
|
| 77 |
+
if retention_guard:
|
| 78 |
+
window_start += timedelta(seconds=retention_guard)
|
| 79 |
frame = _download_window(symbol, interval, window_start, window_end)
|
| 80 |
if not frame.empty:
|
| 81 |
frames.append(frame)
|
|
|
|
| 92 |
df.attrs['effective_lookback_days'] = days
|
| 93 |
df.attrs['source_interval'] = interval
|
| 94 |
df.attrs['empty_request_windows'] = empty_windows
|
| 95 |
+
df.attrs['retention_guard_seconds'] = _RETENTION_GUARD_SECONDS if max_days is not None and days == max_days else 0
|
| 96 |
+
df.attrs['requested_earliest_start_utc'] = window_start.isoformat()
|
| 97 |
return df
|
| 98 |
|
| 99 |
def resample_ohlc(df: pd.DataFrame, rule: str, source_step=None) -> pd.DataFrame:
|