mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-08 03:37:24 -04:00
Compare commits
1 Commits
v0.4.2-alp
...
v0.4.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 277714f664 |
@@ -88,9 +88,18 @@ class ContextInjector:
|
|||||||
|
|
||||||
# Update position state after successful trade
|
# Update position state after successful trade
|
||||||
if request.name in ["buy", "sell"]:
|
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}")
|
||||||
|
print(f"[DEBUG ContextInjector] isinstance(result, dict): {isinstance(result, dict)}")
|
||||||
|
|
||||||
# Check if result is a valid position dict (not an error)
|
# Check if result is a valid position dict (not an error)
|
||||||
if isinstance(result, dict) and "error" not in result and "CASH" in result:
|
if isinstance(result, dict) and "error" not in result and "CASH" in result:
|
||||||
# Update our tracked position with the new state
|
# Update our tracked position with the new state
|
||||||
self._current_position = result.copy()
|
self._current_position = result.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] _current_position remains: {self._current_position}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -132,11 +132,14 @@ def _buy_impl(symbol: str, amount: int, signature: str = None, today_date: str =
|
|||||||
# Step 1: Get current position
|
# Step 1: Get current position
|
||||||
# Use injected position if available (for intra-day tracking),
|
# Use injected position if available (for intra-day tracking),
|
||||||
# otherwise query database for starting position
|
# otherwise query database for starting position
|
||||||
|
print(f"[DEBUG buy] _current_position received: {_current_position}")
|
||||||
if _current_position is not None:
|
if _current_position is not None:
|
||||||
current_position = _current_position
|
current_position = _current_position
|
||||||
next_action_id = 0 # Not used in new schema
|
next_action_id = 0 # Not used in new schema
|
||||||
|
print(f"[DEBUG buy] Using injected position: {current_position}")
|
||||||
else:
|
else:
|
||||||
current_position, next_action_id = get_current_position_from_db(job_id, signature, today_date)
|
current_position, next_action_id = get_current_position_from_db(job_id, signature, today_date)
|
||||||
|
print(f"[DEBUG buy] Queried position from DB: {current_position}")
|
||||||
|
|
||||||
# Step 2: Get stock price
|
# Step 2: Get stock price
|
||||||
try:
|
try:
|
||||||
@@ -189,6 +192,8 @@ def _buy_impl(symbol: str, amount: int, signature: str = None, today_date: str =
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print(f"[buy] {signature} bought {amount} shares of {symbol} at ${this_symbol_price}")
|
print(f"[buy] {signature} bought {amount} shares of {symbol} at ${this_symbol_price}")
|
||||||
|
print(f"[DEBUG buy] Returning new_position: {new_position}")
|
||||||
|
print(f"[DEBUG buy] new_position keys: {list(new_position.keys())}")
|
||||||
return new_position
|
return new_position
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user