From e60f18e41a7cafbfd0b984097403e4dd4642f0e7 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 08:10:18 -0800 Subject: [PATCH] fix: Add None checks for portfolio position metrics to prevent TypeError --- src/pages/trading/trading_system_page.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/trading/trading_system_page.py b/src/pages/trading/trading_system_page.py index 655b87d..691a00f 100644 --- a/src/pages/trading/trading_system_page.py +++ b/src/pages/trading/trading_system_page.py @@ -130,14 +130,14 @@ def trading_system_page(): 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}") - st.metric("Shares", pos['shares']) - st.metric("Current Value", f"${pos['current_value']:.2f}") + st.metric("Entry Price", f"${pos['entry_price']:.2f}" if pos['entry_price'] is not None else "N/A") + st.metric("Shares", pos['shares'] if pos['shares'] is not None else "N/A") + st.metric("Current Value", f"${pos['current_value']:.2f}" if pos['current_value'] is not None else "N/A") with col2: - st.metric("Stop Loss", f"${pos['stop_loss']:.2f}") - st.metric("Target", f"${pos['target_price']:.2f}") - st.metric("Risk/Reward", f"{pos['risk_reward_ratio']:.2f}") + st.metric("Stop Loss", f"${pos['stop_loss']:.2f}" if pos['stop_loss'] is not None else "N/A") + st.metric("Target", f"${pos['target_price']:.2f}" if pos['target_price'] is not None else "N/A") + st.metric("Risk/Reward", f"{pos['risk_reward_ratio']:.2f}" if pos['risk_reward_ratio'] is not None else "N/A") if st.button(f"Remove {pos['symbol']}", key=f"remove_{pos['symbol']}_{i}"): st.session_state.portfolio.remove_position(pos['symbol'])