feat: Add debug logging to get_open_trades function

This commit is contained in:
Bobby (aider) 2025-02-13 10:29:50 -08:00
parent c4b253cc88
commit 52839b451e

View File

@ -512,13 +512,23 @@ def get_open_trades_summary() -> dict:
raise raise
def get_open_trades(): def get_open_trades():
print("\n=== Fetching Open Trades ===") # Debug
with create_client() as client: with create_client() as client:
query = "SELECT * FROM stock_db.trades WHERE exit_price IS NULL ORDER BY entry_date DESC" query = "SELECT * FROM stock_db.trades WHERE exit_price IS NULL ORDER BY entry_date DESC"
result = client.query(query).result_rows print(f"Executing query: {query}") # Debug
columns = ['id', 'position_id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price', try:
'stop_loss', 'strategy', 'order_type', 'followed_rules', 'entry_reason', 'exit_price', result = client.query(query).result_rows
'exit_date', 'exit_reason', 'notes', 'created_at'] print(f"Query returned {len(result)} rows") # Debug
return [dict(zip(columns, row)) for row in result]
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']
trades = [dict(zip(columns, row)) for row in result]
print(f"Processed trades: {trades}") # Debug
return trades
except Exception as e:
print(f"Error in get_open_trades: {str(e)}") # Debug
raise
def get_current_prices(tickers: list) -> dict: def get_current_prices(tickers: list) -> dict:
"""Get current prices for multiple tickers using yfinance""" """Get current prices for multiple tickers using yfinance"""