diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 57d9b4e..d03d75f 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -226,20 +226,18 @@ def trading_journal_page(): st.error("Please enter time in HH:MM format (e.g. 09:30)") st.stop() - if existing_positions: - st.write(f"Existing {ticker} Positions:") - for pos in existing_positions: - st.write(f"Position ID: {pos['position_id']}") - st.write(f"Total Shares: {pos['total_shares']}") - st.write(f"Average Entry: ${pos['avg_entry_price']:.2f}") - - if direction == "Sell": - position_id = st.selectbox( - "Select Position to Exit", - options=[pos['position_id'] for pos in existing_positions], - key="position_select" - ) - else: # Buy + # Show existing positions for this ticker + existing_positions = get_position_summary(ticker) + + # Always show the "Add to existing position" option for buys + if direction == "Buy": + if existing_positions: + st.write(f"Existing {ticker} Positions:") + for pos in existing_positions: + st.write(f"Position ID: {pos['position_id']}") + st.write(f"Total Shares: {pos['total_shares']}") + st.write(f"Average Entry: ${pos['avg_entry_price']:.2f}") + add_to_existing = st.checkbox("Add to existing position") if add_to_existing: position_id = st.selectbox( @@ -249,11 +247,17 @@ def trading_journal_page(): ) else: position_id = generate_position_id(ticker, entry_datetime) - else: - if direction == "Sell": + else: + position_id = generate_position_id(ticker, entry_datetime) + else: # Sell + if not existing_positions: st.error("No existing positions found for this ticker") st.stop() - position_id = generate_position_id(ticker, entry_datetime) + position_id = st.selectbox( + "Select Position to Exit", + options=[pos['position_id'] for pos in existing_positions], + key="position_select" + ) col1, col2 = st.columns(2) with col1: