diff --git a/src/streamlit_app.py b/src/streamlit_app.py index cfe59f5..e43c1d6 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -1170,24 +1170,42 @@ def trading_plan_page(): # Get available trades with create_client() as client: query = """ - SELECT id, ticker, entry_date, entry_price, shares, exit_price, exit_date + SELECT + id, + ticker, + entry_date, + entry_price, + shares, + exit_price, + exit_date, + direction, + strategy, + CASE + WHEN exit_price IS NOT NULL + THEN (exit_price - entry_price) * shares + ELSE NULL + END as profit_loss FROM stock_db.trades WHERE plan_id IS NULL ORDER BY entry_date DESC """ result = client.query(query) available_trades = [dict(zip( - ['id', 'ticker', 'entry_date', 'entry_price', 'shares', 'exit_price', 'exit_date'], + ['id', 'ticker', 'entry_date', 'entry_price', 'shares', + 'exit_price', 'exit_date', 'direction', 'strategy', 'profit_loss'], row )) for row in result.result_rows] - + if available_trades: st.write("Link Existing Trades:") selected_trades = st.multiselect( "Select trades to link to this plan", options=[t['id'] for t in available_trades], format_func=lambda x: next( - f"{t['ticker']} - {t['entry_date']} - ${t['entry_price']:.2f}" + f"{t['ticker']} - {t['entry_date']} - ${t['entry_price']:.2f} " + f"({t['direction']}) - {t['strategy']} " + f"{'[Closed]' if t['exit_price'] else '[Open]'} " + f"{f'P/L: ${t['profit_loss']:.2f}' if t['profit_loss'] is not None else ''}" for t in available_trades if t['id'] == x ) )