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:
0
backend/tests/__init__.py
Normal file
0
backend/tests/__init__.py
Normal file
32
backend/tests/conftest.py
Normal file
32
backend/tests/conftest.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_price_data():
|
||||
return {
|
||||
"timestamp": "2024-01-01T00:00:00",
|
||||
"region": "FR",
|
||||
"day_ahead_price": 50.0,
|
||||
"real_time_price": 55.0,
|
||||
"volume_mw": 1000.0,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_battery_state():
|
||||
return {
|
||||
"timestamp": "2024-01-01T00:00:00",
|
||||
"battery_id": "battery_1",
|
||||
"capacity_mwh": 100.0,
|
||||
"charge_level_mwh": 50.0,
|
||||
"charge_rate_mw": 50.0,
|
||||
"discharge_rate_mw": 50.0,
|
||||
"efficiency": 0.9,
|
||||
}
|
||||
3
backend/tests/test_api/__init__.py
Normal file
3
backend/tests/test_api/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from tests.conftest import sample_price_data, sample_battery_state
|
||||
|
||||
__all__ = ["sample_price_data", "sample_battery_state"]
|
||||
13
backend/tests/test_api/test_backtest.py
Normal file
13
backend/tests/test_api/test_backtest.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_backtest_start():
|
||||
pass
|
||||
|
||||
|
||||
def test_backtest_status():
|
||||
pass
|
||||
|
||||
|
||||
def test_backtest_history():
|
||||
pass
|
||||
46
backend/tests/test_api/test_dashboard.py
Normal file
46
backend/tests/test_api/test_dashboard.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_health_check(client: TestClient):
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "healthy"
|
||||
|
||||
|
||||
def test_dashboard_summary(client: TestClient):
|
||||
response = client.get("/api/v1/dashboard/summary")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_latest_prices(client: TestClient):
|
||||
response = client.get("/api/v1/dashboard/prices")
|
||||
assert response.status_code == 200
|
||||
assert "regions" in response.json()
|
||||
|
||||
|
||||
def test_battery_states(client: TestClient):
|
||||
response = client.get("/api/v1/dashboard/battery")
|
||||
assert response.status_code == 200
|
||||
assert "batteries" in response.json()
|
||||
|
||||
|
||||
def test_arbitrage_opportunities(client: TestClient):
|
||||
response = client.get("/api/v1/dashboard/arbitrage")
|
||||
assert response.status_code == 200
|
||||
assert "opportunities" in response.json()
|
||||
|
||||
|
||||
def test_get_settings(client: TestClient):
|
||||
response = client.get("/api/v1/settings")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_list_models(client: TestClient):
|
||||
response = client.get("/api/v1/models")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_get_strategies(client: TestClient):
|
||||
response = client.get("/api/v1/trading/strategies")
|
||||
assert response.status_code == 200
|
||||
9
backend/tests/test_api/test_models.py
Normal file
9
backend/tests/test_api/test_models.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_model_prediction():
|
||||
pass
|
||||
|
||||
|
||||
def test_model_training():
|
||||
pass
|
||||
9
backend/tests/test_api/test_trading.py
Normal file
9
backend/tests/test_api/test_trading.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_strategy_toggle():
|
||||
pass
|
||||
|
||||
|
||||
def test_trading_positions():
|
||||
pass
|
||||
10
backend/tests/test_services/__init__.py
Normal file
10
backend/tests/test_services/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def test_data_service():
|
||||
pass
|
||||
|
||||
|
||||
def test_ml_service():
|
||||
pass
|
||||
|
||||
|
||||
def test_strategy_service():
|
||||
pass
|
||||
2
backend/tests/test_websocket.py
Normal file
2
backend/tests/test_websocket.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def test_websocket():
|
||||
pass
|
||||
Reference in New Issue
Block a user