对冲管理新增品种筛选,合约下拉去掉品种前缀
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from fastapi import APIRouter, Depends, Form, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from sqlalchemy.orm import Session
|
||||
from app.database import get_db
|
||||
from app.models import Round, Position, Contract
|
||||
from app.models import Round, Position, Contract, Product
|
||||
|
||||
router = APIRouter(prefix="/positions", tags=["positions"])
|
||||
|
||||
@@ -18,6 +18,16 @@ def get_active_contracts(db: Session) -> list[str]:
|
||||
return [c[0] for c in contracts]
|
||||
|
||||
|
||||
def get_product_contracts(db: Session) -> dict:
|
||||
result: dict[str, list[str]] = {}
|
||||
products = db.query(Product).order_by(Product.code).all()
|
||||
for p in products:
|
||||
codes = [c.code for c in p.contracts if c.is_active]
|
||||
if codes:
|
||||
result[p.code] = codes
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def positions_page(request: Request, db: Session = Depends(get_db)):
|
||||
active_rounds = (
|
||||
@@ -33,6 +43,7 @@ def positions_page(request: Request, db: Session = Depends(get_db)):
|
||||
request=request,
|
||||
active_nav="positions",
|
||||
contracts=get_active_contracts(db),
|
||||
product_contracts=get_product_contracts(db),
|
||||
active_rounds=active_rounds,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user