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'
This commit is contained in:
opencode
2025-11-11 00:38:07 +01:00
parent 8494583779
commit 25e9a22a8e

View File

@ -30,8 +30,11 @@ class DashboardDataFetcher:
sys.exit(1) sys.exit(1)
self.info = Info(constants.MAINNET_API_URL, skip_ws=True) 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}") logging.info(f"Dashboard Data Fetcher initialized for vault: {self.vault_address}")
def load_managed_positions(self) -> dict: def load_managed_positions(self) -> dict:
@ -47,7 +50,7 @@ class DashboardDataFetcher:
return {} return {}
def fetch_and_save_status(self): 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: try:
perpetuals_state = self.info.user_state(self.vault_address) perpetuals_state = self.info.user_state(self.vault_address)
spot_state = self.info.spot_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" "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 # Use atomic write to prevent partial reads from main_app
temp_file_path = self.status_file_path + ".tmp" temp_file_path = self.status_file_path + ".tmp"
with open(temp_file_path, 'w', encoding='utf-8') as f: with open(temp_file_path, 'w', encoding='utf-8') as f: