first commit

This commit is contained in:
k
2026-04-20 23:05:59 +08:00
commit 9a72566753
33 changed files with 2138 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
"""
Dev-only endpoint: manually insert a fake post to test the full pipeline.
"""
import asyncio
from datetime import datetime, timezone
from fastapi import APIRouter, BackgroundTasks, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db, AsyncSessionLocal
from app.models import Post
from app.ws.manager import manager
import hashlib, time
router = APIRouter()
@router.post("/dev/fake-post")
async def insert_fake_post(
text: str = "BITCOIN is the future of money! We will make America the greatest crypto capital EVER!",
sentiment: str = "bullish",
db: AsyncSession = Depends(get_db),
):
external_id = hashlib.md5(f"fake-{time.time()}".encode()).hexdigest()
post = Post(
external_id=external_id,
text=text,
source="truth",
published_at=datetime.now(timezone.utc).replace(tzinfo=None),
sentiment=sentiment,
ai_confidence=88,
relevant=True,
price_impact_asset="BTC",
price_impact_m5=1.2,
price_impact_m15=2.4,
price_impact_m1h=3.1,
price_at_post=94230.0,
)
db.add(post)
await db.commit()
await db.refresh(post)
await manager.broadcast({
"type": "new_post",
"post": {
"id": post.id,
"text": post.text,
"source": post.source,
"published_at": post.published_at.isoformat(),
"sentiment": post.sentiment,
"ai_confidence": post.ai_confidence,
"relevant": post.relevant,
"price_impact": {
"asset": "BTC", "m5": 1.2, "m15": 2.4, "m1h": 3.1, "price_at_post": 94230.0
},
},
})
return {"id": post.id, "text": post.text[:80]}
@router.post("/dev/backfill-prices")
async def trigger_price_backfill(background_tasks: BackgroundTasks, asset: str = "BTC"):
"""触发历史帖子价格回溯(后台运行)"""
from app.services.price_backfill import backfill_price_impact
background_tasks.add_task(backfill_price_impact, AsyncSessionLocal, asset)
return {"status": "started", "asset": asset, "message": "后台回溯中,约需 1-2 分钟"}