From 52b2e4c348596287192a94f8cd78d28f92799b64 Mon Sep 17 00:00:00 2001 From: Peter Willemsen Date: Mon, 17 Jun 2024 22:55:17 +0200 Subject: [PATCH] Backtest errors returned in try-catch. --- backend/services/backend_api_client.py | 2 ++ frontend/components/backtesting.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/services/backend_api_client.py b/backend/services/backend_api_client.py index 786eacfe..8be28afe 100644 --- a/backend/services/backend_api_client.py +++ b/backend/services/backend_api_client.py @@ -196,6 +196,8 @@ def run_backtesting(self, start_time: int, end_time: int, backtesting_resolution } response = requests.post(url, json=payload) backtesting_results = response.json() + if "error" in backtesting_results: + raise Exception(backtesting_results["error"]) if "processed_data" not in backtesting_results: data = None else: diff --git a/frontend/components/backtesting.py b/frontend/components/backtesting.py index d3332561..6b9d54a7 100644 --- a/frontend/components/backtesting.py +++ b/frontend/components/backtesting.py @@ -22,13 +22,18 @@ def backtesting_section(inputs, backend_api_client): if run_backtesting: start_datetime = datetime.combine(start_date, datetime.min.time()) end_datetime = datetime.combine(end_date, datetime.max.time()) - backtesting_results = backend_api_client.run_backtesting( - start_time=int(start_datetime.timestamp()) * 1000, - end_time=int(end_datetime.timestamp()) * 1000, - backtesting_resolution=backtesting_resolution, - trade_cost=trade_cost / 100, - config=inputs, - ) + try: + backtesting_results = backend_api_client.run_backtesting( + start_time=int(start_datetime.timestamp()) * 1000, + end_time=int(end_datetime.timestamp()) * 1000, + backtesting_resolution=backtesting_resolution, + trade_cost=trade_cost / 100, + config=inputs, + ) + except Exception as e: + st.error(e) + return None + if len(backtesting_results["processed_data"]) == 0: st.error("No trades were executed during the backtesting period.") return None