49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
from fastapi import APIRouter, Cookie
|
|
|
|
from app.db.analytics import get_stats
|
|
from app.db.onchain_db import get_onchain_overview
|
|
from app.web.shared import require_api_user_with_subscription
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/api/market/overview")
|
|
async def api_market_overview(hours: int = 24, altcoin_session: str = Cookie(default="")):
|
|
require_api_user_with_subscription(altcoin_session)
|
|
stats = get_stats()
|
|
onchain = get_onchain_overview(hours=hours)
|
|
newsfeed = {}
|
|
ai_analysis = {}
|
|
try:
|
|
from app.web.routes_content import _newsfeed_payload
|
|
|
|
newsfeed = _newsfeed_payload()
|
|
except Exception:
|
|
newsfeed = {}
|
|
try:
|
|
from app.db.llm_insights import get_latest_insight_by_type
|
|
|
|
latest_sentiment = get_latest_insight_by_type("sentiment_batch_analysis")
|
|
if latest_sentiment:
|
|
ai_analysis = {
|
|
"status": latest_sentiment.get("status"),
|
|
"updated_at": latest_sentiment.get("updated_at"),
|
|
"model": latest_sentiment.get("model"),
|
|
"prompt_version": latest_sentiment.get("prompt_version"),
|
|
"content": latest_sentiment.get("content") or {},
|
|
"input": latest_sentiment.get("input") or {},
|
|
}
|
|
except Exception:
|
|
ai_analysis = {}
|
|
return {
|
|
"hours": int(hours or 24),
|
|
"updated_at": stats.get("market_context_overview", {}).get("updated_at") if isinstance(stats, dict) else None,
|
|
"market": {
|
|
"stats": stats,
|
|
"newsfeed": newsfeed,
|
|
"onchain": onchain,
|
|
"ai_analysis": ai_analysis,
|
|
},
|
|
}
|