From 0eb83197cb5875576b4d8477a3066f822d76ffca Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Mon, 17 Feb 2025 16:28:33 -0800 Subject: [PATCH] feat: Add detailed debug logging for watchlist item creation and insertion --- src/pages/trading/trading_system_page.py | 10 ++++++++++ src/trading/watchlist.py | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/pages/trading/trading_system_page.py b/src/pages/trading/trading_system_page.py index 95338b5..44ec468 100644 --- a/src/pages/trading/trading_system_page.py +++ b/src/pages/trading/trading_system_page.py @@ -231,6 +231,16 @@ def trading_system_page(): if st.button("Add to Watch List", key="add_to_watchlist"): try: + # Debug print before creating item + print("\n=== PRE-WATCHLIST ITEM CREATION ===") + print(f"Ticker: {ticker}") + print(f"Entry Price: {entry_price}") + print(f"Target Price: {target_price}") + print(f"Stop Loss: {position['stop_loss']}") + print(f"Notes: {notes}") + print(f"Selected Watchlist ID: {selected_list[0]}") + print("=====================================\n") + logger.info(f"Attempting to add {ticker} to watchlist {selected_list[0]}") logger.info(f"Entry: {entry_price}, Target: {target_price}, Stop: {position['stop_loss']}") diff --git a/src/trading/watchlist.py b/src/trading/watchlist.py index 60c3759..e5eec59 100644 --- a/src/trading/watchlist.py +++ b/src/trading/watchlist.py @@ -37,6 +37,18 @@ def get_watchlists() -> List[dict]: def add_to_watchlist(watchlist_id: int, item: WatchlistItem) -> bool: with create_client() as client: try: + # Debug print at start of function + print("\n=== WATCHLIST INSERT ATTEMPT ===") + print("Input parameters:") + print(f"Watchlist ID: {watchlist_id}") + print(f"Item details:") + print(f" Ticker: {item.ticker}") + print(f" Entry Price: {item.entry_price}") + print(f" Target Price: {item.target_price}") + print(f" Stop Loss: {item.stop_loss}") + print(f" Notes: {item.notes}") + print("=============================\n") + # Log the initial state logger.info("=== Starting add_to_watchlist operation ===") @@ -92,6 +104,14 @@ def add_to_watchlist(watchlist_id: int, item: WatchlistItem) -> bool: logger.info(f"Column Types: {column_types}") logger.info(f"Data to insert: {data}") + # Add debug print before actual insert + print("\n=== DATABASE INSERT ATTEMPT ===") + print(f"Table: stock_db.watchlist_items") + print(f"Data to insert: {data}") + print(f"Column names: {column_names}") + print(f"Column types: {column_types}") + print("============================\n") + # Perform insert try: client.insert( @@ -100,8 +120,10 @@ def add_to_watchlist(watchlist_id: int, item: WatchlistItem) -> bool: column_names=column_names, column_types=column_types ) - logger.info("Insert operation completed") + print("Insert operation completed successfully") except Exception as insert_error: + print(f"\nINSERT ERROR: {insert_error}") + print(f"Error type: {type(insert_error)}") logger.error(f"Insert operation failed: {insert_error}") raise