mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-09 12:17:24 -04:00
fix: enable intra-day position tracking for sell-then-buy trades
Resolves issue where sell proceeds were not immediately available for subsequent buy orders within the same trading session. Problem: - Both buy() and sell() independently queried database for starting position - Multiple trades within same day all saw pre-trade cash balance - Agents couldn't rebalance portfolios (sell + buy) in single session Solution: - ContextInjector maintains in-memory position state during trading session - Position updates accumulate after each successful trade - Position state injected into buy/sell via _current_position parameter - Reset position state at start of each trading day Changes: - agent/context_injector.py: Add position tracking with reset_position() - agent_tools/tool_trade.py: Accept _current_position in buy/sell functions - agent/base_agent/base_agent.py: Reset position state daily - tests: Add 13 comprehensive tests for position tracking All new tests pass. Backward compatible, no schema changes required.
This commit is contained in:
@@ -533,6 +533,8 @@ Summary:"""
|
||||
# Update context injector with current trading date
|
||||
if self.context_injector:
|
||||
self.context_injector.today_date = today_date
|
||||
# Reset position state for new trading day (enables intra-day tracking)
|
||||
self.context_injector.reset_position()
|
||||
|
||||
# Clear conversation history for new trading day
|
||||
self.clear_conversation_history()
|
||||
|
||||
Reference in New Issue
Block a user