Add FastAPI backend for energy trading system
Implements FastAPI backend with ML model support for energy trading, including price prediction models and RL-based battery trading policy. Features dashboard, trading, backtest, and settings API routes with WebSocket support for real-time updates.
This commit is contained in:
27
backend/app/api/routes/trading.py
Normal file
27
backend/app/api/routes/trading.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import List
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from app.models.enums import StrategyEnum
|
||||
from app.models.schemas import StrategyStatus
|
||||
from app.services import StrategyService
|
||||
|
||||
router = APIRouter()
|
||||
strategy_service = StrategyService()
|
||||
|
||||
|
||||
@router.get("/strategies", response_model=List[StrategyStatus])
|
||||
async def get_strategies():
|
||||
return await strategy_service.get_all_strategies()
|
||||
|
||||
|
||||
@router.post("/strategies")
|
||||
async def toggle_strategy(strategy: StrategyEnum, action: str):
|
||||
if action not in ["start", "stop"]:
|
||||
raise HTTPException(status_code=400, detail="Action must be 'start' or 'stop'")
|
||||
|
||||
status = await strategy_service.toggle_strategy(strategy, action)
|
||||
return {"status": status}
|
||||
|
||||
|
||||
@router.get("/positions")
|
||||
async def get_positions():
|
||||
return {"positions": [], "total": 0}
|
||||
Reference in New Issue
Block a user