feat: Enhance trade selection with direction, strategy, and profit/loss details

This commit is contained in:
Bobby (aider) 2025-02-11 19:07:24 -08:00
parent 722f0d8a14
commit eeb7e6d682

View File

@ -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
)
)