fix: Add None checks for portfolio position metrics to prevent TypeError

This commit is contained in:
Bobby (aider) 2025-02-13 08:10:18 -08:00
parent 0cb11574a3
commit e60f18e41a

View File

@ -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'])