Thanhanh9's picture
download
raw
2.05 kB
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from typing import List
from database import get_db
import models, schemas
router = APIRouter(tags=["backtests"])
@router.get("/strategies/{strategy_id}/backtests", response_model=List[schemas.BacktestEntryOut])
def list_backtests(strategy_id: int, db: Session = Depends(get_db)):
strategy = db.query(models.Strategy).filter(models.Strategy.id == strategy_id).first()
if not strategy:
raise HTTPException(status_code=404, detail="Strategy not found")
return strategy.backtests
@router.post("/strategies/{strategy_id}/backtests", response_model=schemas.BacktestEntryOut, status_code=201)
def create_backtest(strategy_id: int, payload: schemas.BacktestEntryCreate, db: Session = Depends(get_db)):
strategy = db.query(models.Strategy).filter(models.Strategy.id == strategy_id).first()
if not strategy:
raise HTTPException(status_code=404, detail="Strategy not found")
entry = models.BacktestEntry(strategy_id=strategy_id, **payload.model_dump())
db.add(entry)
db.commit()
db.refresh(entry)
return entry
@router.put("/backtests/{entry_id}", response_model=schemas.BacktestEntryOut)
def update_backtest(entry_id: int, payload: schemas.BacktestEntryUpdate, db: Session = Depends(get_db)):
entry = db.query(models.BacktestEntry).filter(models.BacktestEntry.id == entry_id).first()
if not entry:
raise HTTPException(status_code=404, detail="Backtest entry not found")
for field, value in payload.model_dump(exclude_unset=True).items():
setattr(entry, field, value)
db.commit()
db.refresh(entry)
return entry
@router.delete("/backtests/{entry_id}", status_code=204)
def delete_backtest(entry_id: int, db: Session = Depends(get_db)):
entry = db.query(models.BacktestEntry).filter(models.BacktestEntry.id == entry_id).first()
if not entry:
raise HTTPException(status_code=404, detail="Backtest entry not found")
db.delete(entry)
db.commit()

Xet Storage Details

Size:
2.05 kB
·
Xet hash:
f866dcf6cc698de56b6514407b9d665e0797f4e51f2a16c05c348f1f63fdffef

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.