移除全部合约同步按钮,改为单合约后台同步带进度条

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 13:53:44 +08:00
parent b74dccd805
commit ca98967af0
3 changed files with 135 additions and 153 deletions
+12 -17
View File
@@ -4,8 +4,7 @@ from sqlalchemy.orm import Session
from app.database import get_db
from app.models import Product, Contract, DailyBar, PositionRanking
from app.collector import (
sync_active_contracts, sync_one_contract, sync_position_rankings,
start_sync_positions_background, get_sync_progress,
sync_one_contract, sync_contract_bars_bg, sync_positions_bg, get_progress,
)
router = APIRouter(prefix="/admin", tags=["admin"])
@@ -134,31 +133,27 @@ def delete_product(product_id: int, db: Session = Depends(get_db)):
return RedirectResponse("/admin/?tab=product", status_code=303)
@router.post("/sync")
def sync_all(request: Request):
results = sync_active_contracts()
total = sum(results.values())
print(f"[sync] Synced {total} bars across {len(results)} contracts: {results}")
return RedirectResponse(f"/admin/?tab=sync&synced={total}", status_code=303)
@router.post("/sync/{contract_code}")
def sync_single(contract_code: str):
count = sync_one_contract(contract_code.upper())
return RedirectResponse(f"/admin/?tab=sync&synced={count}", status_code=303)
@router.post("/sync-positions")
def sync_positions(request: Request):
started = start_sync_positions_background()
if not started:
return JSONResponse({"error": "同步正在进行中,请等待完成"})
return JSONResponse({"started": True})
@router.post("/sync/{contract_code}/bg")
def sync_single_bg(contract_code: str):
ok = sync_contract_bars_bg(contract_code.upper())
return JSONResponse({"ok": ok})
@router.post("/sync-positions/{contract_code}/bg")
def sync_positions_bg_ep(contract_code: str):
ok = sync_positions_bg(contract_code.upper())
return JSONResponse({"ok": ok})
@router.get("/sync-status")
def sync_status():
return JSONResponse(get_sync_progress())
return JSONResponse(get_progress())
@router.post("/sync/product/{product_id}")