Skip to content

Commit 461632c

Browse files
author
fvetter
committed
🔧 Fix all timestamp conversion bugs in database methods
🐛 Multiple Critical Bugs Fixed: - get_daily_buy_count() - daily transaction counting - get_quick_stats() - stats logging - All methods using timestamp conversion 🔧 Technical Problem: - Multiple methods calculated date ranges in seconds (Python) - Binance transact_time stored in milliseconds - x1000 conversion factor missing across multiple functions 📊 Impact: - Daily buy counting: 0 instead of 4 - Quick stats logging: 0 instead of 4 - All timestamp-based filtering broken ✅ Solution: - Convert all date range calculations to milliseconds (*1000) - Consistent timestamp handling across all database methods - Added debug logging for verification 🎯 All timestamp-based database queries now work correctly
1 parent 308f5ab commit 461632c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/database.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,16 @@ def get_last_buy_time(self, symbol: str) -> Optional[float]:
248248
return None
249249

250250
def get_quick_stats(self) -> Dict:
251-
"""Stats rapides pour les logs (UTILISÉE)"""
251+
"""Stats rapides pour les logs - VERSION CORRIGÉE timestamps"""
252252
try:
253253
today = datetime.now().strftime('%Y-%m-%d')
254-
today_start = int(datetime.strptime(today, '%Y-%m-%d').timestamp())
255-
today_end = today_start + 86400
254+
255+
# 🔧 CORRECTION: Timestamps Binance en millisecondes !
256+
today_start = int(datetime.strptime(today, '%Y-%m-%d').timestamp() * 1000) # x1000
257+
today_end = today_start + (86400 * 1000) # +24h en millisecondes
256258

257259
with self.get_connection() as conn:
258-
# Achats du jour
260+
# Achats du jour - VERSION CORRIGÉE
259261
cursor = conn.execute("""
260262
SELECT COUNT(*) FROM transactions
261263
WHERE order_side = 'BUY'
@@ -272,6 +274,9 @@ def get_quick_stats(self) -> Dict:
272274
cursor = conn.execute("SELECT COUNT(*) FROM transactions")
273275
total_transactions = cursor.fetchone()[0]
274276

277+
# Debug pour vérification
278+
self.logger.debug(f"🔍 Stats quick: {daily_buys} achats aujourd'hui (range: {today_start}-{today_end})")
279+
275280
return {
276281
'daily_buys': daily_buys,
277282
'active_oco': active_oco,

0 commit comments

Comments
 (0)