mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
release: v0.4.2 - fix critical negative cash position bug
Remove debug logging and update CHANGELOG for v0.4.2 release. Fixed critical bug where trades calculated from initial $10,000 capital instead of accumulating, allowing over-spending and negative cash balances. Key changes: - Extract position dict from CallToolResult.structuredContent - Enable MCP service logging for better debugging - Update tests to match production MCP behavior All tests passing. Ready for production release.
This commit is contained in:
@@ -88,28 +88,17 @@ class ContextInjector:
|
||||
|
||||
# Update position state after successful trade
|
||||
if request.name in ["buy", "sell"]:
|
||||
# Debug: Log result type and structure
|
||||
print(f"[DEBUG ContextInjector] Trade result type: {type(result)}")
|
||||
print(f"[DEBUG ContextInjector] Trade result: {result}")
|
||||
|
||||
# Extract position dict from MCP result
|
||||
# MCP tools return CallToolResult objects with structuredContent field
|
||||
position_dict = None
|
||||
if hasattr(result, 'structuredContent') and result.structuredContent:
|
||||
position_dict = result.structuredContent
|
||||
print(f"[DEBUG ContextInjector] Extracted from structuredContent: {position_dict}")
|
||||
elif isinstance(result, dict):
|
||||
position_dict = result
|
||||
print(f"[DEBUG ContextInjector] Using result as dict: {position_dict}")
|
||||
|
||||
# Check if position dict is valid (not an error) and update state
|
||||
if position_dict and "error" not in position_dict and "CASH" in position_dict:
|
||||
# Update our tracked position with the new state
|
||||
self._current_position = position_dict.copy()
|
||||
print(f"[DEBUG ContextInjector] Updated _current_position: {self._current_position}")
|
||||
else:
|
||||
print(f"[DEBUG ContextInjector] Did NOT update _current_position - check failed")
|
||||
print(f"[DEBUG ContextInjector] position_dict: {position_dict}")
|
||||
print(f"[DEBUG ContextInjector] _current_position remains: {self._current_position}")
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user