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

View File

@@ -0,0 +1,3 @@
from app.ml.utils import time_based_split, MLConfig
__all__ = ["time_based_split", "MLConfig"]

View File

@@ -0,0 +1,16 @@
from dataclasses import dataclass
from typing import List, Dict, Any
@dataclass
class MLConfig:
enable_gpu: bool = False
n_jobs: int = 4
verbose: bool = True
@classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> "MLConfig":
return cls(**{k: v for k, v in config_dict.items() if k in cls.__annotations__})
__all__ = ["MLConfig"]

View File

@@ -0,0 +1,25 @@
from typing import Tuple
import pandas as pd
from datetime import datetime
def time_based_split(
df: pd.DataFrame,
timestamp_col: str = "timestamp",
train_pct: float = 0.70,
val_pct: float = 0.85,
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
df_sorted = df.sort_values(timestamp_col)
n_total = len(df_sorted)
n_train = int(n_total * train_pct)
n_val = int(n_total * val_pct)
train = df_sorted.iloc[:n_train]
val = df_sorted.iloc[n_train:n_val]
test = df_sorted.iloc[n_val:]
return train, val, test
__all__ = ["time_based_split"]

View File

@@ -0,0 +1,4 @@
from app.ml.utils.data_split import time_based_split
from app.ml.utils.config import MLConfig
__all__ = ["time_based_split", "MLConfig"]