cpatino10 commited on
Commit
f6c6118
·
verified ·
1 Parent(s): a4da15d

Updated FMP api url

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -11,7 +11,7 @@ from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
- def fetch_historical_price_data(symbol: str, start_date: str, end_date: str) -> list[dict]:
15
  """
16
  Fetch daily historical stock price data for a given stock symbol between start_date and end_date. Use
17
  toda=datetime.now() to confirm the dates are valid dates prior to calling the API.
@@ -19,24 +19,16 @@ def fetch_historical_price_data(symbol: str, start_date: str, end_date: str) ->
19
  Args:
20
  symbol: Stock market symbol such as 'AAPL', 'MSFT', 'NVDA'
21
  start_date: Start date in 'YYYY-MM-DD' format
22
- end_date: End date in 'YYYY-MM-DD' format
23
  """
24
  FMP_KEY = os.getenv("FMP_KEY")
25
  if not FMP_KEY:
26
  return [{"error": "Missing FMP_KEY environment variable"}]
27
 
28
- # Validate and adjust date inputs
29
- try:
30
- start_dt = datetime.strptime(start_date, "%Y-%m-%d")
31
- end_dt = datetime.strptime(end_date, "%Y-%m-%d")
32
- today = datetime.now()
33
- if end_dt > today:
34
- end_dt = today
35
- end_date = today.strftime("%Y-%m-%d")
36
- except ValueError:
37
- return [{"error": "Invalid date format. Use 'YYYY-MM-DD'."}]
38
-
39
- url = f"https://financialmodelingprep.com/stable/historical-price-eod/light?symbol={symbol}&from={start_date}&to={end_date}&apikey={FMP_KEY}"
40
 
41
  try:
42
  response = requests.get(url)
 
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def fetch_historical_price_data(symbol: str, start_date: str) -> list[dict]:
15
  """
16
  Fetch daily historical stock price data for a given stock symbol between start_date and end_date. Use
17
  toda=datetime.now() to confirm the dates are valid dates prior to calling the API.
 
19
  Args:
20
  symbol: Stock market symbol such as 'AAPL', 'MSFT', 'NVDA'
21
  start_date: Start date in 'YYYY-MM-DD' format
22
+
23
  """
24
  FMP_KEY = os.getenv("FMP_KEY")
25
  if not FMP_KEY:
26
  return [{"error": "Missing FMP_KEY environment variable"}]
27
 
28
+ #Get today's date to validate start_date input
29
+ today = datetime.now()
30
+
31
+ url = f"https://financialmodelingprep.com/stable/historical-price-eod/non-split-adjusted?symbol={symbol}&from={start_date}&apikey={FMP_API_KEY}"
 
 
 
 
 
 
 
 
32
 
33
  try:
34
  response = requests.get(url)