fix: Handle empty stats in check_go_live_readiness
Deploy to Windows VPS / deploy (push) Has been cancelled
Deploy to Windows VPS / deploy (push) Has been cancelled
Added default values using .get() for all stats fields 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:
+17
-10
@@ -358,24 +358,31 @@ class DemoTestTracker:
|
|||||||
|
|
||||||
checks = {}
|
checks = {}
|
||||||
|
|
||||||
|
# Get values with defaults for when no trades exist yet
|
||||||
|
total_trades = stats.get('total_trades', 0)
|
||||||
|
win_rate = stats.get('win_rate', 0)
|
||||||
|
profit_factor = stats.get('profit_factor', 0)
|
||||||
|
max_drawdown = stats.get('max_drawdown', 0)
|
||||||
|
sessions_tested = stats.get('sessions_tested', [])
|
||||||
|
|
||||||
# 1. Minimum Trades
|
# 1. Minimum Trades
|
||||||
checks['min_trades'] = {
|
checks['min_trades'] = {
|
||||||
'passed': stats['total_trades'] >= self.criteria['min_trades'],
|
'passed': total_trades >= self.criteria['min_trades'],
|
||||||
'current': stats['total_trades'],
|
'current': total_trades,
|
||||||
'required': self.criteria['min_trades'],
|
'required': self.criteria['min_trades'],
|
||||||
'label': f"Trades: {stats['total_trades']}/{self.criteria['min_trades']}"
|
'label': f"Trades: {total_trades}/{self.criteria['min_trades']}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 2. Win Rate
|
# 2. Win Rate
|
||||||
checks['win_rate'] = {
|
checks['win_rate'] = {
|
||||||
'passed': stats['win_rate'] >= self.criteria['min_win_rate'],
|
'passed': win_rate >= self.criteria['min_win_rate'],
|
||||||
'current': stats['win_rate'],
|
'current': win_rate,
|
||||||
'required': self.criteria['min_win_rate'],
|
'required': self.criteria['min_win_rate'],
|
||||||
'label': f"Win Rate: {stats['win_rate']*100:.1f}% (min {self.criteria['min_win_rate']*100:.0f}%)"
|
'label': f"Win Rate: {win_rate*100:.1f}% (min {self.criteria['min_win_rate']*100:.0f}%)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 3. Profit Factor
|
# 3. Profit Factor
|
||||||
pf = stats['profit_factor'] if stats['profit_factor'] != float('inf') else 999
|
pf = profit_factor if profit_factor != float('inf') else 999
|
||||||
checks['profit_factor'] = {
|
checks['profit_factor'] = {
|
||||||
'passed': pf >= self.criteria['min_profit_factor'],
|
'passed': pf >= self.criteria['min_profit_factor'],
|
||||||
'current': pf,
|
'current': pf,
|
||||||
@@ -385,10 +392,10 @@ class DemoTestTracker:
|
|||||||
|
|
||||||
# 4. Max Drawdown
|
# 4. Max Drawdown
|
||||||
checks['max_drawdown'] = {
|
checks['max_drawdown'] = {
|
||||||
'passed': stats['max_drawdown'] <= self.criteria['max_drawdown'],
|
'passed': max_drawdown <= self.criteria['max_drawdown'],
|
||||||
'current': stats['max_drawdown'],
|
'current': max_drawdown,
|
||||||
'required': self.criteria['max_drawdown'],
|
'required': self.criteria['max_drawdown'],
|
||||||
'label': f"Max Drawdown: {stats['max_drawdown']*100:.1f}% (max {self.criteria['max_drawdown']*100:.0f}%)"
|
'label': f"Max Drawdown: {max_drawdown*100:.1f}% (max {self.criteria['max_drawdown']*100:.0f}%)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 5. Days Running
|
# 5. Days Running
|
||||||
|
|||||||
Reference in New Issue
Block a user