feat: raise market_api rate to 20/min, add global Polygon cap at 45/min, add rate-limit API + watchlist warning

This commit is contained in:
Celes Renata
2026-04-16 07:26:10 +00:00
parent 0b3ab4ed90
commit 0ee7f26633
5 changed files with 148 additions and 9 deletions
+54
View File
@@ -1534,6 +1534,60 @@ async def get_source_coverage_gaps():
}
# ---------------------------------------------------------------------------
# System: Rate Limit Info
# ---------------------------------------------------------------------------
@app.get("/api/system/rate-limits")
async def get_rate_limits():
"""Return current rate limit configuration and usage.
Exposes the scheduler's rate limits so the frontend can calculate
how many tickers can be refreshed within the configured cadence.
"""
from services.scheduler.app import (
DEFAULT_CADENCES,
DEFAULT_RATE_LIMITS,
POLYGON_GLOBAL_RATE_LIMIT,
POLYGON_SOURCE_TYPES,
)
# Count active market_api sources to report current load
market_count = await pool.fetchval(
"SELECT count(*) FROM sources WHERE active = TRUE AND source_type = 'market_api'"
)
news_count = await pool.fetchval(
"SELECT count(*) FROM sources WHERE active = TRUE AND source_type = 'news_api'"
)
market_cadence = DEFAULT_CADENCES.get("market_api", 300)
market_rate = DEFAULT_RATE_LIMITS.get("market_api", 20)
# How many tickers can we refresh within one cadence window?
# cadence_minutes * rate_per_minute = max tickers per cycle
cadence_minutes = market_cadence / 60
max_tickers_per_cycle = int(cadence_minutes * market_rate)
return {
"polygon_global_limit": POLYGON_GLOBAL_RATE_LIMIT,
"polygon_source_types": sorted(POLYGON_SOURCE_TYPES),
"per_type_limits": DEFAULT_RATE_LIMITS,
"cadences_seconds": DEFAULT_CADENCES,
"market_api": {
"rate_per_minute": market_rate,
"cadence_seconds": market_cadence,
"max_tickers_per_cycle": max_tickers_per_cycle,
"active_sources": market_count,
},
"news_api": {
"rate_per_minute": DEFAULT_RATE_LIMITS.get("news_api", 20),
"cadence_seconds": DEFAULT_CADENCES.get("news_api", 300),
"active_sources": news_count,
},
}
# ---------------------------------------------------------------------------
# Analytics: Trino SQL Proxy (Requirement 10.1, 10.3, 13.7)
# ---------------------------------------------------------------------------