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:
|
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}")
|
||||||
|
|
||||||
if st.button("Add to Watch List", key="add_to_watchlist"):
|
# Move Add to Watch List button outside of columns
|
||||||
try:
|
if st.button("Add to Watch List", key="add_to_watchlist"):
|
||||||
# Debug print before creating item
|
try:
|
||||||
debug_info = {
|
# Debug information
|
||||||
"Ticker": ticker,
|
debug_info = {
|
||||||
"Entry Price": entry_price,
|
"Ticker": ticker,
|
||||||
"Target Price": target_price,
|
"Entry Price": entry_price,
|
||||||
"Stop Loss": position['stop_loss'],
|
"Target Price": target_price,
|
||||||
"Notes": notes,
|
"Stop Loss": position['stop_loss'],
|
||||||
"Selected Watchlist ID": selected_list[0]
|
"Notes": notes,
|
||||||
}
|
"Selected Watchlist ID": selected_list[0]
|
||||||
|
}
|
||||||
|
|
||||||
st.write("=== PRE-WATCHLIST ITEM CREATION ===")
|
st.write("=== PRE-WATCHLIST ITEM CREATION ===")
|
||||||
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(
|
||||||
|
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(
|
st.write("=== WATCHLIST ITEM DETAILS ===")
|
||||||
ticker=ticker,
|
st.write(vars(item))
|
||||||
entry_price=float(entry_price),
|
st.write("==============================")
|
||||||
target_price=float(target_price),
|
|
||||||
stop_loss=float(position['stop_loss']),
|
|
||||||
notes=str(notes) if notes else ''
|
|
||||||
)
|
|
||||||
|
|
||||||
# Show the item details before adding
|
# Add 2 second delay to ensure debug info is visible
|
||||||
st.write("=== WATCHLIST ITEM DETAILS ===")
|
time.sleep(2)
|
||||||
st.write(item)
|
|
||||||
st.write("==============================")
|
|
||||||
|
|
||||||
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:
|
|
||||||
logger.error(f"Error in watchlist addition: {e}", exc_info=True)
|
except Exception as e:
|
||||||
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)}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user