From 814a7db5de2369a305a72e7573a26e5e91190f54 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 10:52:36 -0800 Subject: [PATCH] feat: Add debug print statements to trading journal page for trade entry tracking --- src/pages/journal/trading_journal_page.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 924b714..97a02d1 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -202,8 +202,10 @@ def trading_journal_page(): with tab2: st.subheader("Add New Trade") + print("\n--- Add Trade Tab ---") # Debug ticker = st.text_input("Ticker Symbol").upper() + print(f"Ticker entered: {ticker}") # Debug # Add direction selection direction = st.selectbox( @@ -211,31 +213,40 @@ def trading_journal_page(): ["Buy", "Sell"], key="trade_direction" ) + print(f"Direction selected: {direction}") # Debug if ticker: - # Show existing positions for this ticker FIRST + print(f"\nProcessing ticker {ticker}") # Debug existing_positions = get_position_summary(ticker) + print(f"Found existing positions: {existing_positions}") # Debug # Handle position selection based on direction if direction == "Buy": if existing_positions: + print(f"Processing existing positions for {ticker}") # Debug st.write(f"Existing {ticker} Positions:") for pos in existing_positions: + print(f"Position details: {pos}") # Debug 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") + print(f"Add to existing selected: {add_to_existing}") # Debug + if add_to_existing: position_id = st.selectbox( "Select Position ID", options=[pos['position_id'] for pos in existing_positions], key="position_select" ) + print(f"Selected position ID: {position_id}") # Debug else: - position_id = None # Will be generated later + position_id = None + print("Creating new position") # Debug else: - position_id = None # Will be generated later + position_id = None + print("No existing positions found, creating new position") # Debug else: # Sell if not existing_positions: st.error("No existing positions found for this ticker") @@ -288,8 +299,10 @@ def trading_journal_page(): if st.button("Add Trade"): try: + print("\n--- Processing Add Trade ---") # Debug entry_datetime = datetime.combine(entry_date, entry_time) entry_datetime = pytz.timezone('US/Pacific').localize(entry_datetime) + print(f"Entry datetime: {entry_datetime}") # Debug trade = TradeEntry( ticker=ticker, @@ -308,10 +321,14 @@ def trading_journal_page(): direction=direction.lower() ) + print(f"Trade object created: {trade.__dict__}") # Debug + add_trade(trade) + print("Trade added successfully") # Debug st.success("Trade added successfully!") st.query_params(rerun=True) except Exception as e: + print(f"Error adding trade: {str(e)}") # Debug st.error(f"Error adding trade: {str(e)}") with tab3: