From 470cb88da6b64ff31c84e7d6895b3aa839ac8d0d Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Mon, 10 Feb 2025 23:20:11 -0800 Subject: [PATCH] refactor: Improve portfolio display with unique keys and entry date --- src/streamlit_app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/streamlit_app.py b/src/streamlit_app.py index 8ae8116..597bd3b 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -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: