From 25e9a22a8e34c54dbcbb8d271b2564fd6394d6f1 Mon Sep 17 00:00:00 2001 From: opencode Date: Tue, 11 Nov 2025 00:38:07 +0100 Subject: [PATCH] Fix DashboardDataFetcher path resolution error - Use absolute path for status file to ensure consistency across subprocess execution - Add os.makedirs() call to ensure _logs directory exists - Prevents 'No such file or directory' error when running as subprocess - Fixes issue: [Errno 2] No such file or directory: '_logs/trade_executor_status.json.tmp' --- dashboard_data_fetcher.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dashboard_data_fetcher.py b/dashboard_data_fetcher.py index 789fbeb..e9397b2 100644 --- a/dashboard_data_fetcher.py +++ b/dashboard_data_fetcher.py @@ -30,8 +30,11 @@ class DashboardDataFetcher: sys.exit(1) self.info = Info(constants.MAINNET_API_URL, skip_ws=True) - self.status_file_path = os.path.join("_logs", "trade_executor_status.json") - self.managed_positions_path = os.path.join("_data", "executor_managed_positions.json") + + # Use absolute path to ensure consistency across different working directories + project_root = os.path.dirname(os.path.abspath(__file__)) + self.status_file_path = os.path.join(project_root, "_logs", "trade_executor_status.json") + self.managed_positions_path = os.path.join(project_root, "_data", "executor_managed_positions.json") logging.info(f"Dashboard Data Fetcher initialized for vault: {self.vault_address}") def load_managed_positions(self) -> dict: @@ -47,7 +50,7 @@ class DashboardDataFetcher: return {} def fetch_and_save_status(self): - """Fetches all account data and saves it to the JSON status file.""" + """Fetches all account data and saves it to JSON status file.""" try: perpetuals_state = self.info.user_state(self.vault_address) spot_state = self.info.spot_user_state(self.vault_address) @@ -105,7 +108,11 @@ class DashboardDataFetcher: "position_value": total_balance * mark_price, "pnl": "N/A" }) - # 3. Write to file + # 3. Ensure directory exists and write to file + # Ensure the _logs directory exists + logs_dir = os.path.dirname(self.status_file_path) + os.makedirs(logs_dir, exist_ok=True) + # Use atomic write to prevent partial reads from main_app temp_file_path = self.status_file_path + ".tmp" with open(temp_file_path, 'w', encoding='utf-8') as f: