refactor: Update trade history query to explicitly list columns

This commit is contained in:
Bobby (aider) 2025-02-13 09:32:57 -08:00
parent e322743f33
commit 646d4b847f

View File

@ -536,7 +536,10 @@ def get_trade_history(limit: int = 50):
with create_client() as client:
query = f"""
SELECT
*,
id, position_id, ticker, entry_date, shares, entry_price,
target_price, stop_loss, strategy, order_type, direction,
followed_rules, entry_reason, exit_price, exit_date,
exit_reason, notes, created_at,
groupArray(ticker) OVER (PARTITION BY position_id) as related_tickers,
groupArray(id) OVER (PARTITION BY position_id) as related_ids
FROM stock_db.trades
@ -544,9 +547,11 @@ def get_trade_history(limit: int = 50):
LIMIT {limit}
"""
result = client.query(query).result_rows
columns = ['id', 'position_id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price',
'stop_loss', 'strategy', 'order_type', 'followed_rules', 'entry_reason', 'exit_price',
'exit_date', 'exit_reason', 'notes', 'created_at', 'direction', 'related_tickers', 'related_ids']
columns = ['id', 'position_id', 'ticker', 'entry_date', 'shares',
'entry_price', 'target_price', 'stop_loss', 'strategy',
'order_type', 'direction', 'followed_rules', 'entry_reason',
'exit_price', 'exit_date', 'exit_reason', 'notes',
'created_at', 'related_tickers', 'related_ids']
return [dict(zip(columns, row)) for row in result]
def journal_menu():