feat: Add get_current_price function to retrieve latest stock price
This commit is contained in:
parent
af392bbaec
commit
bc7d20e179
@ -30,6 +30,27 @@ def get_interval_choice() -> str:
|
|||||||
else:
|
else:
|
||||||
print("Invalid choice. Please try again.")
|
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:
|
def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interval: str) -> pd.DataFrame:
|
||||||
"""Fetch stock data from the database"""
|
"""Fetch stock data from the database"""
|
||||||
client = create_client()
|
client = create_client()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user