fix: Handle empty stats in get_daily_summary
Deploy to Windows VPS / deploy (push) Has been cancelled
Deploy to Windows VPS / deploy (push) Has been cancelled
Added .get() with defaults for total_trades, win_rate, and total_profit to prevent KeyError when no trades have been logged yet. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7044c19a60
commit
25b20fa0e2
1 file changed
+5
-1
@@ -547,11 +547,15 @@ class DemoTestTracker:
|
|||||||
today_wins = sum(1 for t in today_trades if t['is_win'])
|
today_wins = sum(1 for t in today_trades if t['is_win'])
|
||||||
today_wr = today_wins / len(today_trades) * 100 if today_trades else 0
|
today_wr = today_wins / len(today_trades) * 100 if today_trades else 0
|
||||||
|
|
||||||
|
total_trades = stats.get('total_trades', 0)
|
||||||
|
win_rate = stats.get('win_rate', 0)
|
||||||
|
total_profit = stats.get('total_profit', 0)
|
||||||
|
|
||||||
summary = f"""
|
summary = f"""
|
||||||
📊 Daily Summary - {today}
|
📊 Daily Summary - {today}
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
Today: {len(today_trades)} trades | {today_wins} wins | WR: {today_wr:.0f}% | P/L: ${today_profit:+.2f}
|
Today: {len(today_trades)} trades | {today_wins} wins | WR: {today_wr:.0f}% | P/L: ${today_profit:+.2f}
|
||||||
Overall: {stats['total_trades']} trades | WR: {stats['win_rate']*100:.1f}% | Total: ${stats['total_profit']:+.2f}
|
Overall: {total_trades} trades | WR: {win_rate*100:.1f}% | Total: ${total_profit:+.2f}
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
"""
|
"""
|
||||||
return summary
|
return summary
|
||||||
|
|||||||
Reference in new issue
Block a user