|
|
|
@ -67,14 +67,18 @@ class HistoricalDataCache:
|
|
|
|
|
|
|
|
|
|
|
|
def _normalize_period_to_days(self, period: str) -> int:
|
|
|
|
def _normalize_period_to_days(self, period: str) -> int:
|
|
|
|
"""Convert period string to approximate days"""
|
|
|
|
"""Convert period string to approximate days"""
|
|
|
|
|
|
|
|
if period is None:
|
|
|
|
|
|
|
|
return 30
|
|
|
|
period_map = {
|
|
|
|
period_map = {
|
|
|
|
'1d': 1, '2d': 2, '5d': 5, '1mo': 30, '3mo': 90, '6mo': 180,
|
|
|
|
'1d': 1, '2d': 2, '5d': 5, '1mo': 30, '3mo': 90, '6mo': 180,
|
|
|
|
'1y': 365, '2y': 730, '5y': 1825, '10y': 3650, 'ytd': 365, 'max': 36500
|
|
|
|
'1y': 365, '2y': 730, '5y': 1825, '10y': 3650, 'ytd': 365, 'max': 36500
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return period_map.get(period.lower(), 30)
|
|
|
|
return period_map.get(str(period).lower(), 30)
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, symbol: str, period: str, interval: str, start: str = None, end: str = None) -> Optional[pd.DataFrame]:
|
|
|
|
def get(self, symbol: str, period: str, interval: str, start: str = None, end: str = None) -> Optional[pd.DataFrame]:
|
|
|
|
"""Get cached historical data if available and valid"""
|
|
|
|
"""Get cached historical data if available and valid"""
|
|
|
|
|
|
|
|
if period is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
with self._lock:
|
|
|
|
with self._lock:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# First check exact match
|
|
|
|
# First check exact match
|
|
|
|
@ -121,6 +125,8 @@ class HistoricalDataCache:
|
|
|
|
|
|
|
|
|
|
|
|
def store(self, symbol: str, period: str, interval: str, data: pd.DataFrame, start: str = None, end: str = None):
|
|
|
|
def store(self, symbol: str, period: str, interval: str, data: pd.DataFrame, start: str = None, end: str = None):
|
|
|
|
"""Store historical data in cache"""
|
|
|
|
"""Store historical data in cache"""
|
|
|
|
|
|
|
|
if period is None:
|
|
|
|
|
|
|
|
return
|
|
|
|
with self._lock:
|
|
|
|
with self._lock:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Check if we already have a longer period cache that contains this data
|
|
|
|
# Check if we already have a longer period cache that contains this data
|
|
|
|
|