market cap fixes

This commit is contained in:
2025-10-25 19:58:52 +02:00
parent 5805601218
commit fe5cc8e1d1
5 changed files with 184 additions and 44 deletions

View File

@ -41,7 +41,6 @@ class MarketCapFetcher:
"DAI": "dai", "PYUSD": "paypal-usd"
}
# --- ADDED: Ensure all tables have the correct schema ---
self._ensure_tables_exist()
def _ensure_tables_exist(self):
@ -291,8 +290,14 @@ class MarketCapFetcher:
if not market_caps: return pd.DataFrame()
df = pd.DataFrame(market_caps, columns=['timestamp_ms', 'market_cap'])
# --- FIX: Convert to datetime object, but do not format as string ---
df['datetime_utc'] = pd.to_datetime(df['timestamp_ms'], unit='ms')
# --- FIX: Normalize all timestamps to the start of the day (00:00:00 UTC) ---
# This prevents duplicate entries for the same day (e.g., a "live" candle vs. the daily one)
df['datetime_utc'] = pd.to_datetime(df['timestamp_ms'], unit='ms').dt.normalize()
# Recalculate the timestamp_ms to match the normalized 00:00:00 datetime
df['timestamp_ms'] = (df['datetime_utc'].astype('int64') // 10**6)
df.drop_duplicates(subset=['timestamp_ms'], keep='last', inplace=True)
return df[['datetime_utc', 'timestamp_ms', 'market_cap']]