diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index 37e88fd..59c9468 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -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()