feat: migrate trade tools to write to actions table (new schema)

This commit implements Task 1 from the schema migration plan:
- Trade tools (buy/sell) now write to actions table instead of old positions table
- Added trading_day_id parameter to buy/sell functions
- Updated ContextInjector to inject trading_day_id
- Updated RuntimeConfigManager to include TRADING_DAY_ID in config
- Removed P&L calculation from trade functions (now done at trading_days level)
- Added tests verifying correct behavior with new schema

Changes:
- agent_tools/tool_trade.py: Modified _buy_impl and _sell_impl to write to actions table
- agent/context_injector.py: Added trading_day_id parameter and injection logic
- api/model_day_executor.py: Updated to read trading_day_id from runtime config
- api/runtime_manager.py: Added trading_day_id to config initialization
- tests/unit/test_trade_tools_new_schema.py: New tests for new schema compliance

All tests passing.
This commit is contained in:
2025-11-04 09:18:35 -05:00
parent faa2135668
commit 7d9d093d6c
5 changed files with 282 additions and 114 deletions

View File

@@ -138,11 +138,15 @@ class ModelDayExecutor:
# Create and inject context with correct values
from agent.context_injector import ContextInjector
from tools.general_tools import get_config_value
trading_day_id = get_config_value('TRADING_DAY_ID') # Get from runtime config
context_injector = ContextInjector(
signature=self.model_sig,
today_date=self.date, # Current trading day
job_id=self.job_id,
session_id=session_id
session_id=session_id,
trading_day_id=trading_day_id
)
logger.info(f"[DEBUG] ModelDayExecutor: Created ContextInjector with signature={self.model_sig}, date={self.date}, job_id={self.job_id}, session_id={session_id}")
logger.info(f"[DEBUG] ModelDayExecutor: Calling await agent.set_context()")

View File

@@ -48,7 +48,8 @@ class RuntimeConfigManager:
self,
job_id: str,
model_sig: str,
date: str
date: str,
trading_day_id: int = None
) -> str:
"""
Create isolated runtime config file for this execution.
@@ -57,6 +58,7 @@ class RuntimeConfigManager:
job_id: Job UUID
model_sig: Model signature
date: Trading date (YYYY-MM-DD)
trading_day_id: Trading day record ID (optional, can be set later)
Returns:
Path to created runtime config file
@@ -79,7 +81,8 @@ class RuntimeConfigManager:
"TODAY_DATE": date,
"SIGNATURE": model_sig,
"IF_TRADE": False,
"JOB_ID": job_id
"JOB_ID": job_id,
"TRADING_DAY_ID": trading_day_id
}
with open(config_path, "w", encoding="utf-8") as f: