@ -314,9 +314,15 @@ def get_positions(session_id: str) -> dict[str, Any]:
is_parking = parking_symbol and p . symbol == parking_symbol
is_parking = parking_symbol and p . symbol == parking_symbol
if ss is None and not is_parking :
if ss is None and not is_parking :
continue # Only show positions tracked by this session
continue # Only show positions tracked by this session
# Use locally-recorded entry price/qty for strategy positions to avoid
# Use locally-recorded entry price/qty to avoid cross-session contamination
# o rphaned-share contamination o f Alpaca's blended avg_entry_price.
# o f Alpaca's blended avg_entry_price (multiple sessions share one broker account) .
ot = open_trades . get ( p . symbol ) if not is_parking else None
ot = open_trades . get ( p . symbol ) if not is_parking else None
if is_parking and parking_state :
qty = float ( parking_state . get ( " qty " ) or p . qty )
entry = float ( parking_state [ " avg_price " ] ) if parking_state . get ( " avg_price " ) else (
float ( p . avg_entry_price ) if p . avg_entry_price else 0.0
)
else :
qty = float ( ot [ " shares " ] ) if ot and ot . get ( " shares " ) else float ( p . qty )
qty = float ( ot [ " shares " ] ) if ot and ot . get ( " shares " ) else float ( p . qty )
entry = float ( ot [ " entry_price " ] ) if ot and ot . get ( " entry_price " ) else (
entry = float ( ot [ " entry_price " ] ) if ot and ot . get ( " entry_price " ) else (
float ( p . avg_entry_price ) if p . avg_entry_price else 0.0
float ( p . avg_entry_price ) if p . avg_entry_price else 0.0