feat: Add get_current_price function to retrieve latest stock price

This commit is contained in:
Bobby Abellana (aider) 2025-02-06 23:45:21 -08:00
parent af392bbaec
commit bc7d20e179
No known key found for this signature in database
GPG Key ID: 647714CC45F3647B

View File

@ -30,6 +30,27 @@ def get_interval_choice() -> str:
else:
print("Invalid choice. Please try again.")
def get_current_price(ticker: str) -> float:
"""Get the most recent price for a ticker from stock_prices table"""
client = create_client()
query = f"""
SELECT close
FROM stock_db.stock_prices
WHERE ticker = '{ticker}'
ORDER BY window_start DESC
LIMIT 1
"""
try:
result = client.query(query)
if result.result_rows:
return float(result.result_rows[0][0])
return None
except Exception as e:
print(f"Error getting current price for {ticker}: {str(e)}")
return None
def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interval: str) -> pd.DataFrame:
"""Fetch stock data from the database"""
client = create_client()