mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
fix: resolve async execution and position storage issues
- Fix async call in model_day_executor.py by wrapping with asyncio.run() Resolves RuntimeWarning where run_trading_session coroutine was never awaited - Remove register_agent() call in API mode to prevent file-based position storage Position data is now stored exclusively in SQLite database (jobs.db) - Update test mocks to use AsyncMock for async run_trading_session method This fixes production deployment issues: 1. Trading sessions now execute properly (async bug) 2. No position files created, database-only storage 3. All tests pass Closes issue with no trades being executed in production
This commit is contained in:
@@ -11,6 +11,7 @@ This module provides:
|
||||
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
from typing import Dict, Any, Optional, List, TYPE_CHECKING
|
||||
from pathlib import Path
|
||||
|
||||
@@ -118,7 +119,7 @@ class ModelDayExecutor:
|
||||
|
||||
# Run trading session
|
||||
logger.info(f"Running trading session for {self.model_sig} on {self.date}")
|
||||
session_result = agent.run_trading_session(self.date)
|
||||
session_result = asyncio.run(agent.run_trading_session(self.date))
|
||||
|
||||
# Persist results to SQLite
|
||||
self._write_results_to_db(agent, session_result)
|
||||
@@ -211,8 +212,10 @@ class ModelDayExecutor:
|
||||
init_date=config.get("date_range", {}).get("init_date", "2025-10-13")
|
||||
)
|
||||
|
||||
# Register agent (creates initial position if needed)
|
||||
agent.register_agent()
|
||||
# Note: In API mode, we don't call register_agent() because:
|
||||
# - Position data is stored in SQLite database, not files
|
||||
# - Database initialization is handled by JobManager
|
||||
# - File-based position tracking is only for standalone/CLI mode
|
||||
|
||||
return agent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user