refactor: Improve watchlist addition layout and debug information display

This commit is contained in:
Bobby (aider) 2025-02-17 16:36:13 -08:00
parent f3570ac6b3
commit e1a01a6f97

View File

@ -196,42 +196,38 @@ def trading_system_page():
if not watchlists: if not watchlists:
st.warning("No watch lists available. Create one in the Watch Lists tab.") st.warning("No watch lists available. Create one in the Watch Lists tab.")
else: else:
col1, col2 = st.columns([3, 1]) # Create three columns for better layout
col1, col2, col3 = st.columns([2, 2, 1])
with col1: with col1:
selected_list = st.selectbox( selected_list = st.selectbox(
"Select Watch List", "Select Watch List",
options=[(w['id'], w['name']) for w in watchlists], options=[(w['id'], w['name']) for w in watchlists],
format_func=lambda x: x[1] format_func=lambda x: x[1]
) )
notes = st.text_area("Notes")
with col2: with col2:
if st.button("Debug Database State"): notes = st.text_area("Notes", key="watchlist_notes")
with col3:
# Move Debug button outside of conditional
if st.button("Debug DB", key="debug_db"):
try: try:
with create_client() as client: with create_client() as client:
# Check watchlists table
watchlists_query = "SELECT * FROM stock_db.watchlists"
watchlists_result = client.query(watchlists_query)
st.write("=== Watchlists Table ===") st.write("=== Watchlists Table ===")
watchlists_result = client.query("SELECT * FROM stock_db.watchlists")
st.write(watchlists_result.result_rows) st.write(watchlists_result.result_rows)
# Check watchlist_items table
items_query = "SELECT * FROM stock_db.watchlist_items"
items_result = client.query(items_query)
st.write("=== Watchlist Items Table ===") st.write("=== Watchlist Items Table ===")
items_result = client.query("SELECT * FROM stock_db.watchlist_items")
st.write(items_result.result_rows) st.write(items_result.result_rows)
# Show table structure
structure_query = "DESCRIBE TABLE stock_db.watchlist_items"
structure_result = client.query(structure_query)
st.write("=== Table Structure ===")
st.write(structure_result.result_rows)
except Exception as e: except Exception as e:
st.error(f"Debug query error: {e}") st.error(f"Debug query error: {e}")
# Move Add to Watch List button outside of columns
if st.button("Add to Watch List", key="add_to_watchlist"): if st.button("Add to Watch List", key="add_to_watchlist"):
try: try:
# Debug print before creating item # Debug information
debug_info = { debug_info = {
"Ticker": ticker, "Ticker": ticker,
"Entry Price": entry_price, "Entry Price": entry_price,
@ -245,8 +241,6 @@ def trading_system_page():
st.write(debug_info) st.write(debug_info)
st.write("=====================================") st.write("=====================================")
logger.info(f"Attempting to add {ticker} to watchlist {selected_list[0]}")
item = WatchlistItem( item = WatchlistItem(
ticker=ticker, ticker=ticker,
entry_price=float(entry_price), entry_price=float(entry_price),
@ -255,25 +249,29 @@ def trading_system_page():
notes=str(notes) if notes else '' notes=str(notes) if notes else ''
) )
# Show the item details before adding
st.write("=== WATCHLIST ITEM DETAILS ===") st.write("=== WATCHLIST ITEM DETAILS ===")
st.write(item) st.write(vars(item))
st.write("==============================") st.write("==============================")
# Add 2 second delay to ensure debug info is visible
time.sleep(2)
success = add_to_watchlist(selected_list[0], item) success = add_to_watchlist(selected_list[0], item)
# Show the result # Show the result and wait before rerun
st.write(f"Add to watchlist result: {success}") st.write(f"Add to watchlist result: {success}")
time.sleep(2)
if success: if success:
st.success(f"Added {ticker} to watch list!") st.success(f"Added {ticker} to watch list!")
time.sleep(2) # Give more time to see the debug output time.sleep(1)
st.rerun() st.rerun()
else: else:
st.error("Failed to add to watch list. Check the details above.") st.error("Failed to add to watch list. Check the details above.")
except Exception as e: except Exception as e:
logger.error(f"Error in watchlist addition: {e}", exc_info=True)
st.error(f"Error adding to watchlist: {str(e)}") st.error(f"Error adding to watchlist: {str(e)}")
logger.exception("Error in watchlist addition")
except Exception as e: except Exception as e:
st.error(f"Error calculating position: {str(e)}") st.error(f"Error calculating position: {str(e)}")