add last sync time in index, fix csv file caching time in fetching new data

This commit is contained in:
2026-02-06 03:56:55 +08:00
parent 2d9fa9a47b
commit c0f158684f
29 changed files with 53379 additions and 704 deletions
+12 -13
View File
@@ -16,6 +16,9 @@ class DataEngine:
self.symbol = symbol.strip().upper() if symbol else None
self.name = name
# --- Fetch frequently ---
self.cache_expiry = 1 * 3600 # Set to 0 for forced refresh, 24 for normal
# 2. Setup the directory variable FIRST
# (This was likely below the file_path line, causing the crash)
base_path = os.path.dirname(os.path.abspath(__file__))
@@ -50,21 +53,17 @@ class DataEngine:
def ensure_data(self):
"""Checks if file exists and is fresh (less than 24h old)."""
CACHE_EXPIRY = 24 * 3600 # 24 hours
# Force expiry to 0
CACHE_EXPIRY = 0
if os.path.exists(self.file_path):
# NEW: Check how old the file is
file_age = time.time() - os.path.getmtime(self.file_path)
if file_age < CACHE_EXPIRY:
return True # Data is actually fresh
# By changing this to 'if False', we force it to ignore the cache every time
if False: # file_age < CACHE_EXPIRY:
return True
else:
print(f"DEBUG: {self.symbol} cache is stale ({round(file_age/3600)}h old). Refreshing...")
else:
print(f"DEBUG: {self.symbol} not found in cache. Attempting download...")
# If we reached here, it means we either have NO file or a STALE file
# Instead of just yfinance, call your specialized fetch_data()
# which uses the URLs from your TEMPLATES
print(f"DEBUG: {self.symbol} refreshing now...")
# This calls your actual downloader
return self.fetch_data()
def load_instruments_from_csv(self, file_path='instruments.csv'):
@@ -276,7 +275,7 @@ class DataEngine:
def fetch_data(self):
local_df = pd.DataFrame()
CACHE_EXPIRY = 24 * 3600
CACHE_EXPIRY = 0
file_exists = os.path.exists(self.file_path)
# 1. Load Local Cache & Check Age