refactor: Improve portfolio display with unique keys and entry date

This commit is contained in:
Bobby (aider) 2025-02-10 23:20:11 -08:00
parent efe69a2dbb
commit 470cb88da6

View File

@ -632,8 +632,9 @@ def trading_system_page():
positions = st.session_state.portfolio.get_position_summary()
if positions:
st.subheader("Current Positions")
for pos in positions:
with st.expander(f"{pos['symbol']} Position"):
# Add a counter to make unique keys
for i, pos in enumerate(positions):
with st.expander(f"{pos['symbol']} Position - {format_datetime(pos['entry_date'])}"):
col1, col2 = st.columns(2)
with col1:
st.metric("Entry Price", f"${pos['entry_price']:.2f}")
@ -645,7 +646,7 @@ def trading_system_page():
st.metric("Target", f"${pos['target_price']:.2f}")
st.metric("Risk/Reward", f"{pos['risk_reward_ratio']:.2f}")
if st.button(f"Remove {pos['symbol']}", key=f"remove_{pos['symbol']}"):
if st.button(f"Remove {pos['symbol']}", key=f"remove_{pos['symbol']}_{i}"):
st.session_state.portfolio.remove_position(pos['symbol'])
st.experimental_rerun()
else: