refactor: Improve watchlist addition layout and debug information display
This commit is contained in:
parent
f3570ac6b3
commit
e1a01a6f97
@ -196,84 +196,82 @@ def trading_system_page():
|
||||
if not watchlists:
|
||||
st.warning("No watch lists available. Create one in the Watch Lists tab.")
|
||||
else:
|
||||
col1, col2 = st.columns([3, 1])
|
||||
# Create three columns for better layout
|
||||
col1, col2, col3 = st.columns([2, 2, 1])
|
||||
|
||||
with col1:
|
||||
selected_list = st.selectbox(
|
||||
"Select Watch List",
|
||||
options=[(w['id'], w['name']) for w in watchlists],
|
||||
format_func=lambda x: x[1]
|
||||
)
|
||||
notes = st.text_area("Notes")
|
||||
|
||||
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:
|
||||
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 ===")
|
||||
watchlists_result = client.query("SELECT * FROM stock_db.watchlists")
|
||||
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 ===")
|
||||
items_result = client.query("SELECT * FROM stock_db.watchlist_items")
|
||||
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:
|
||||
st.error(f"Debug query error: {e}")
|
||||
|
||||
if st.button("Add to Watch List", key="add_to_watchlist"):
|
||||
try:
|
||||
# Debug print before creating item
|
||||
debug_info = {
|
||||
"Ticker": ticker,
|
||||
"Entry Price": entry_price,
|
||||
"Target Price": target_price,
|
||||
"Stop Loss": position['stop_loss'],
|
||||
"Notes": notes,
|
||||
"Selected Watchlist ID": selected_list[0]
|
||||
}
|
||||
# Move Add to Watch List button outside of columns
|
||||
if st.button("Add to Watch List", key="add_to_watchlist"):
|
||||
try:
|
||||
# Debug information
|
||||
debug_info = {
|
||||
"Ticker": ticker,
|
||||
"Entry Price": entry_price,
|
||||
"Target Price": target_price,
|
||||
"Stop Loss": position['stop_loss'],
|
||||
"Notes": notes,
|
||||
"Selected Watchlist ID": selected_list[0]
|
||||
}
|
||||
|
||||
st.write("=== PRE-WATCHLIST ITEM CREATION ===")
|
||||
st.write(debug_info)
|
||||
st.write("=====================================")
|
||||
st.write("=== PRE-WATCHLIST ITEM CREATION ===")
|
||||
st.write(debug_info)
|
||||
st.write("=====================================")
|
||||
|
||||
logger.info(f"Attempting to add {ticker} to watchlist {selected_list[0]}")
|
||||
item = WatchlistItem(
|
||||
ticker=ticker,
|
||||
entry_price=float(entry_price),
|
||||
target_price=float(target_price),
|
||||
stop_loss=float(position['stop_loss']),
|
||||
notes=str(notes) if notes else ''
|
||||
)
|
||||
|
||||
item = WatchlistItem(
|
||||
ticker=ticker,
|
||||
entry_price=float(entry_price),
|
||||
target_price=float(target_price),
|
||||
stop_loss=float(position['stop_loss']),
|
||||
notes=str(notes) if notes else ''
|
||||
)
|
||||
st.write("=== WATCHLIST ITEM DETAILS ===")
|
||||
st.write(vars(item))
|
||||
st.write("==============================")
|
||||
|
||||
# Show the item details before adding
|
||||
st.write("=== WATCHLIST ITEM DETAILS ===")
|
||||
st.write(item)
|
||||
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
|
||||
st.write(f"Add to watchlist result: {success}")
|
||||
# Show the result and wait before rerun
|
||||
st.write(f"Add to watchlist result: {success}")
|
||||
time.sleep(2)
|
||||
|
||||
if success:
|
||||
st.success(f"Added {ticker} to watch list!")
|
||||
time.sleep(2) # Give more time to see the debug output
|
||||
st.rerun()
|
||||
else:
|
||||
st.error("Failed to add to watch list. Check the details above.")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in watchlist addition: {e}", exc_info=True)
|
||||
st.error(f"Error adding to watchlist: {str(e)}")
|
||||
if success:
|
||||
st.success(f"Added {ticker} to watch list!")
|
||||
time.sleep(1)
|
||||
st.rerun()
|
||||
else:
|
||||
st.error("Failed to add to watch list. Check the details above.")
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"Error adding to watchlist: {str(e)}")
|
||||
logger.exception("Error in watchlist addition")
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"Error calculating position: {str(e)}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user