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:
2026-02-12 00:59:26 +07:00
parent a22a13f6f4
commit fe76bc7629
72 changed files with 2931 additions and 0 deletions

54
backend/README.md Normal file
View File

@@ -0,0 +1,54 @@
# Energy Trading Backend
FastAPI backend for the energy trading system with ML model support.
## Setup
```bash
cd backend
pip install -r requirements.txt
cp .env.example .env
```
## Running
```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```
## API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## Project Structure
```
backend/
├── app/
│ ├── api/ # API routes and WebSocket
│ ├── services/ # Business logic services
│ ├── tasks/ # Background tasks
│ ├── ml/ # ML models and training
│ ├── models/ # Pydantic models
│ └── utils/ # Utilities
├── models/ # Trained models
├── results/ # Backtest results
└── tests/ # Tests
```
## Training ML Models
```bash
# Train price prediction models
python -m app.ml.training.cli price --horizons 1 5 15 60
# Train RL battery policy
python -m app.ml.training.cli rl --episodes 1000
```
## Running Tests
```bash
pytest
```