feat: Enhance trade selection with direction, strategy, and profit/loss details
This commit is contained in:
parent
722f0d8a14
commit
eeb7e6d682
@ -1170,14 +1170,29 @@ def trading_plan_page():
|
|||||||
# Get available trades
|
# Get available trades
|
||||||
with create_client() as client:
|
with create_client() as client:
|
||||||
query = """
|
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
|
FROM stock_db.trades
|
||||||
WHERE plan_id IS NULL
|
WHERE plan_id IS NULL
|
||||||
ORDER BY entry_date DESC
|
ORDER BY entry_date DESC
|
||||||
"""
|
"""
|
||||||
result = client.query(query)
|
result = client.query(query)
|
||||||
available_trades = [dict(zip(
|
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
|
row
|
||||||
)) for row in result.result_rows]
|
)) for row in result.result_rows]
|
||||||
|
|
||||||
@ -1187,7 +1202,10 @@ def trading_plan_page():
|
|||||||
"Select trades to link to this plan",
|
"Select trades to link to this plan",
|
||||||
options=[t['id'] for t in available_trades],
|
options=[t['id'] for t in available_trades],
|
||||||
format_func=lambda x: next(
|
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
|
for t in available_trades if t['id'] == x
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user