mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
Critical fixes: 1. Fixed api/database.py import - use get_db_path() instead of non-existent get_database_path() 2. Fixed state management - use database queries instead of reading from position.jsonl file 3. Fixed action counting - track during trading loop execution instead of retroactively from conversation history 4. Completed integration test to verify P&L calculation works correctly Changes: - agent/base_agent/base_agent.py: * Updated _get_current_portfolio_state() to query database via get_current_position_from_db() * Added today_date and job_id parameters to method signature * Count trade actions during trading loop instead of post-processing conversation history * Removed obsolete action counting logic - api/database.py: * Fixed import to use get_db_path() from deployment_config * Pass correct default database path "data/trading.db" - tests/integration/test_agent_pnl_integration.py: * Added proper mocks for dev mode and MCP client * Mocked get_current_position_from_db to return test data * Added comprehensive assertions to verify trading_day record fields * Test now actually validates P&L calculation integration Test results: - All unit tests passing (252 passed) - All P&L integration tests passing (8 passed) - No regressions detected