From dab122d15f903d8cacb681e2abb2ea812ca796c9 Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 20 Nov 2024 01:38:46 -0400 Subject: [PATCH] A lot of stuff is fixed. The strategies need to reflect the stats in the ui. --- src/BrighterTrades.py | 26 ++++++++++++++++++++------ src/static/backtesting.js | 4 ---- src/templates/backtest_popup.html | 8 +++++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/BrighterTrades.py b/src/BrighterTrades.py index 8abc513..ab05334 100644 --- a/src/BrighterTrades.py +++ b/src/BrighterTrades.py @@ -830,13 +830,27 @@ class BrighterTrades: required_fields = ['strategy', 'start_date', 'capital', 'commission', 'user_name'] if not all(field in msg_data for field in required_fields): return standard_reply("backtest_error", {"message": "Missing required fields."}) - # Delegate backtest handling to the Backtester - resp = self.backtester.handle_backtest_message( - user_id=self.get_user_info(user_name=msg_data['user_name'], info='User_id'), - msg_data=msg_data, - socket_conn_id=socket_conn_id) - return standard_reply("backtest_submitted", resp) + try: + # Delegate backtest handling to the Backtester + resp = self.backtester.handle_backtest_message( + user_id=self.get_user_info(user_name=msg_data['user_name'], info='User_id'), + msg_data=msg_data, + socket_conn_id=socket_conn_id + ) + + if 'error' in resp: + # If there's an error, send a backtest_error message + return standard_reply("backtest_error", {"message": resp['error']}) + else: + # If successful, send a backtest_submitted message + return standard_reply("backtest_submitted", resp) + + except Exception as e: + # Catch any unexpected exceptions and send a backtest_error message + logger.error(f"Unhandled exception during backtest submission: {e}", exc_info=True) + return standard_reply("backtest_error", + {"message": "An unexpected error occurred during backtest submission."}) if msg_type == 'delete_backtest': response = self.delete_backtest(msg_data) diff --git a/src/static/backtesting.js b/src/static/backtesting.js index 9d600b2..6d048e8 100644 --- a/src/static/backtesting.js +++ b/src/static/backtesting.js @@ -100,9 +100,6 @@ class Backtesting { } } - - - handleBacktestError(data) { console.error("Backtest error:", data.message); @@ -120,7 +117,6 @@ class Backtesting { this.hideElement(this.resultsContainer); } - handleBacktestResults(data) { const test = this.tests.find(t => t.name === data.test_id); if (test) { diff --git a/src/templates/backtest_popup.html b/src/templates/backtest_popup.html index 0ea4122..622b2b9 100644 --- a/src/templates/backtest_popup.html +++ b/src/templates/backtest_popup.html @@ -40,7 +40,7 @@ - +
@@ -163,5 +163,11 @@ #backtest-results.show { display: block; /* Show when backtest is complete */ } + #backtest-status-message { + display: none; + } + #backtest-status-message.show{ + display: block; + }