Asish Karthikeya Gogineni commited on
Commit ·
b9116fc
1
Parent(s): d9af5a7
Fix: Flat graph lines - detect AV rate limits + fix 1D/3D/1W mock data point counts
Browse files- alphavantage_mcp.py +20 -6
alphavantage_mcp.py
CHANGED
|
@@ -63,12 +63,21 @@ async def get_market_data(payload: dict):
|
|
| 63 |
# Intraday data (last 4-6 hours, 5-min intervals)
|
| 64 |
data, meta_data = ts.get_intraday(symbol=symbol, interval="5min", outputsize='compact')
|
| 65 |
logger.info(f"Successfully retrieved intraday data for {symbol}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
meta_data["Source"] = "Real API (Alpha Vantage)"
|
| 67 |
else:
|
| 68 |
# Daily data for historical ranges
|
| 69 |
data, meta_data = ts.get_daily(symbol=symbol, outputsize='full')
|
| 70 |
logger.info(f"Successfully retrieved daily data for {symbol}")
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# Filter data based on time range
|
| 73 |
data = filter_data_by_time_range(data, time_range)
|
| 74 |
logger.info(f"Filtered to {len(data)} data points for time_range={time_range}")
|
|
@@ -119,12 +128,17 @@ async def get_market_data(payload: dict):
|
|
| 119 |
if time_range == "INTRADAY":
|
| 120 |
num_points = 100
|
| 121 |
time_delta = timedelta(minutes=5)
|
| 122 |
-
elif time_range
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
elif time_range == "1W":
|
| 126 |
-
num_points = 7
|
| 127 |
-
time_delta = timedelta(
|
| 128 |
elif time_range == "1M":
|
| 129 |
num_points = 30
|
| 130 |
time_delta = timedelta(days=1)
|
|
|
|
| 63 |
# Intraday data (last 4-6 hours, 5-min intervals)
|
| 64 |
data, meta_data = ts.get_intraday(symbol=symbol, interval="5min", outputsize='compact')
|
| 65 |
logger.info(f"Successfully retrieved intraday data for {symbol}")
|
| 66 |
+
# Detect Alpha Vantage rate-limit / info response (200 OK but no real data)
|
| 67 |
+
if isinstance(data, dict) and "Information" in data:
|
| 68 |
+
raise Exception(f"Alpha Vantage rate limit: {data['Information']}")
|
| 69 |
+
if isinstance(data, dict) and "Note" in data:
|
| 70 |
+
raise Exception(f"Alpha Vantage note (rate limit): {data['Note']}")
|
| 71 |
meta_data["Source"] = "Real API (Alpha Vantage)"
|
| 72 |
else:
|
| 73 |
# Daily data for historical ranges
|
| 74 |
data, meta_data = ts.get_daily(symbol=symbol, outputsize='full')
|
| 75 |
logger.info(f"Successfully retrieved daily data for {symbol}")
|
| 76 |
+
# Detect Alpha Vantage rate-limit / info response
|
| 77 |
+
if isinstance(data, dict) and "Information" in data:
|
| 78 |
+
raise Exception(f"Alpha Vantage rate limit: {data['Information']}")
|
| 79 |
+
if isinstance(data, dict) and "Note" in data:
|
| 80 |
+
raise Exception(f"Alpha Vantage note (rate limit): {data['Note']}")
|
| 81 |
# Filter data based on time range
|
| 82 |
data = filter_data_by_time_range(data, time_range)
|
| 83 |
logger.info(f"Filtered to {len(data)} data points for time_range={time_range}")
|
|
|
|
| 128 |
if time_range == "INTRADAY":
|
| 129 |
num_points = 100
|
| 130 |
time_delta = timedelta(minutes=5)
|
| 131 |
+
elif time_range == "1D":
|
| 132 |
+
# FIX: 1D needs enough intraday points for a real chart (not just 1!)
|
| 133 |
+
num_points = 390 # ~6.5 trading hours at 1-min intervals
|
| 134 |
+
time_delta = timedelta(minutes=1)
|
| 135 |
+
elif time_range == "3D":
|
| 136 |
+
# FIX: 3D needs enough points (not just 3!)
|
| 137 |
+
num_points = 72 # 3 days × 24 hourly data points
|
| 138 |
+
time_delta = timedelta(hours=1)
|
| 139 |
elif time_range == "1W":
|
| 140 |
+
num_points = 168 # 7 days × 24 hourly data points
|
| 141 |
+
time_delta = timedelta(hours=1)
|
| 142 |
elif time_range == "1M":
|
| 143 |
num_points = 30
|
| 144 |
time_delta = timedelta(days=1)
|