From dbb1393c086efedb674246912823dd09fda537d9 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 10:29:01 -0800 Subject: [PATCH] feat: Add comprehensive debug statements to trading journal page and data retrieval functions --- src/pages/journal/trading_journal_page.py | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 5138964..6416681 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -116,24 +116,34 @@ def plot_trade_history(trades): def trading_journal_page(): st.header("Trading Journal") + print("\n=== Starting Trading Journal Page ===") # Debug # Tabs for different journal functions tab1, tab2, tab3, tab4 = st.tabs(["Open Positions", "Add Trade", "Update Trade", "Trade History"]) with tab1: st.subheader("Open Positions") + print("\n--- Fetching Open Positions ---") # Debug open_trades = get_open_trades() + print(f"Retrieved {len(open_trades) if open_trades else 0} open trades") # Debug + print(f"Open trades {open_trades}") # Debug + open_summary = get_open_trades_summary() + print(f"Retrieved {len(open_summary) if open_summary else 0} position summaries") # Debug + print(f"Open summary {open_summary}") # Debug if open_summary: # Get current prices unique_tickers = list(set(summary['ticker'] for summary in open_summary)) + print(f"Fetching prices for tickers: {unique_tickers}") # Debug current_prices = get_current_prices(unique_tickers) + print(f"Retrieved current prices: {current_prices}") # Debug total_portfolio_value = 0 total_paper_pl = 0 for summary in open_summary: + print(f"\nProcessing summary for {summary['ticker']}") # Debug with st.expander(f"{summary['ticker']} Summary"): ticker = summary['ticker'] avg_entry = summary['avg_entry_price'] @@ -141,6 +151,12 @@ def trading_journal_page(): total_shares = summary['total_shares'] position_value = avg_entry * total_shares + print(f"Position details for {ticker}:") # Debug + print(f"- Shares: {total_shares}") # Debug + print(f"- Avg Entry: {avg_entry}") # Debug + print(f"- Current Price: {current_price}") # Debug + print(f"- Position Value: {position_value}") # Debug + col1, col2 = st.columns(2) with col1: st.metric("Total Shares", f"{total_shares:,}") @@ -279,7 +295,10 @@ def trading_journal_page(): with tab3: st.subheader("Update Trade") + print("\n--- Update Trade Tab ---") # Debug open_trades = get_open_trades() + print(f"Retrieved {len(open_trades) if open_trades else 0} trades for update tab") # Debug + print(f"Update tab trades {open_trades}") # Debug if open_trades: trade_id = st.selectbox( @@ -290,6 +309,7 @@ def trading_journal_page(): ) trade = next(t for t in open_trades if t['id'] == trade_id) + print(f"\nSelected trade for update: {trade}") # Debug col1, col2 = st.columns(2) with col1: @@ -342,9 +362,20 @@ def trading_journal_page(): 'notes': new_notes } + print("\n--- Processing Trade Update ---") # Debug + print(f"Update data being sent: {updates}") # Debug + update_trade(trade_id, updates) + print("Trade update completed") # Debug + st.success("Trade updated successfully!") - st.experimental_rerun() + print("Clearing session state and triggering rerun") # Debug + + # Clear session state + for key in st.session_state.keys(): + del st.session_state[key] + + st.rerun() except Exception as e: st.error(f"Error updating trade: {str(e)}") else: