PR2: read-only FastAPI dashboard backend #2

Merged
DasAoD merged 6 commits from feature/backend-api into main 2026-08-28 15:50:36 +02:00
Owner

Zweiter von vier PRs. Das Backend, das PR3 (Dashboard) konsumiert.

Inhalt

  • analytics.py: reine Portfolio-Mathematik aus SQLite (keine Exchange-Calls)
    • Summary: investiert, Cash, Bestaende + Bewertung, Equity, PnL abs/%%
    • Buy&Hold-Referenz: gleiches Geld, aber pro Symbol als Einmalkauf zum ersten Fill-Preis -> zeigt, ob das Einstreuen geholfen hat (Wert + Serie)
    • History: Zeitreihen fuer Portfoliowert, kumuliert investiert, Buy&Hold-Linie, Kurse je Symbol; days-Fenster
  • api.py: FastAPI-App, read-only, keine Writes
    • GET /api/health - Liveness + DB-Check
    • GET /api/summary
    • GET /api/history?days=30 (1..365)
    • GET /api/trades?limit=50&offset=0 (neueste zuerst, paginiert)
    • Swagger unter /api/docs; lazy api.app fuer uvicorn krypto_dca.api:app
  • paths.py: Config-Aufloesung aus cli.py herausgezogen (explizit / KRYPTO_DCA_CONFIG / bekannte Pfade), von cli + api geteilt
  • krypto-dca serve: neuer CLI-Subcommand, startet uvicorn auf [backend] host/port (Default 127.0.0.1:8787)
  • Deploy: krypto-dca-backend.service (Type=simple, Restart=always, gleiches Hardening wie die Timer) + nginx-trading.uliana.de.conf (TLS via acme.sh + HTTP Basic Auth vor 127.0.0.1:8787)
  • Deps: fastapi, uvicorn als Runtime; httpx im dev-Extra (TestClient)
  • Docs: README-Endpunkttabelle + Architektur aktualisiert, SETUP.md Abschnitt 6 (Backend + nginx)

Verifiziert

  • pytest -> 26 passed (6 neue: health, summary-Mathe, Trade-Pagination, History-Serie + Tagesfenster)
  • End-to-End gegen echte Kraken-Kurse: buy + snapshot + serve, alle vier Endpunkte liefern 200; summary rechnet investiert 12,00 / holdings_value 11,97 (Fees) / Buy&Hold 12,00 sauber aus

Sicherheit

  • API bindet nur 127.0.0.1, ausschliesslich lesend, keine ccxt-Aufrufe
  • TLS + Auth komplett in nginx; Service laeuft als krypto-dca, nicht root

Co-authored-by: Claude claude@anthropic.com

Zweiter von vier PRs. Das Backend, das PR3 (Dashboard) konsumiert. ## Inhalt - **`analytics.py`**: reine Portfolio-Mathematik aus SQLite (keine Exchange-Calls) - Summary: investiert, Cash, Bestaende + Bewertung, Equity, PnL abs/%% - Buy&Hold-Referenz: gleiches Geld, aber pro Symbol als Einmalkauf zum ersten Fill-Preis -> zeigt, ob das Einstreuen geholfen hat (Wert + Serie) - History: Zeitreihen fuer Portfoliowert, kumuliert investiert, Buy&Hold-Linie, Kurse je Symbol; `days`-Fenster - **`api.py`**: FastAPI-App, read-only, keine Writes - `GET /api/health` - Liveness + DB-Check - `GET /api/summary` - `GET /api/history?days=30` (1..365) - `GET /api/trades?limit=50&offset=0` (neueste zuerst, paginiert) - Swagger unter `/api/docs`; lazy `api.app` fuer `uvicorn krypto_dca.api:app` - **`paths.py`**: Config-Aufloesung aus cli.py herausgezogen (explizit / `KRYPTO_DCA_CONFIG` / bekannte Pfade), von cli + api geteilt - **`krypto-dca serve`**: neuer CLI-Subcommand, startet uvicorn auf `[backend] host/port` (Default `127.0.0.1:8787`) - **Deploy**: `krypto-dca-backend.service` (Type=simple, Restart=always, gleiches Hardening wie die Timer) + `nginx-trading.uliana.de.conf` (TLS via acme.sh + HTTP Basic Auth vor `127.0.0.1:8787`) - **Deps**: `fastapi`, `uvicorn` als Runtime; `httpx` im dev-Extra (TestClient) - **Docs**: README-Endpunkttabelle + Architektur aktualisiert, SETUP.md Abschnitt 6 (Backend + nginx) ## Verifiziert - `pytest` -> 26 passed (6 neue: health, summary-Mathe, Trade-Pagination, History-Serie + Tagesfenster) - End-to-End gegen echte Kraken-Kurse: `buy` + `snapshot` + `serve`, alle vier Endpunkte liefern 200; summary rechnet investiert 12,00 / holdings_value 11,97 (Fees) / Buy&Hold 12,00 sauber aus ## Sicherheit - API bindet nur `127.0.0.1`, ausschliesslich lesend, keine ccxt-Aufrufe - TLS + Auth komplett in nginx; Service laeuft als `krypto-dca`, nicht root Co-authored-by: Claude <claude@anthropic.com>
- move config.ini lookup (explicit / KRYPTO_DCA_CONFIG / well-known paths) into paths.py
- cli imports resolve_config from there; drop the duplicated helpers
- new `krypto-dca serve` subcommand runs the dashboard API via uvicorn

Co-authored-by: Claude <claude@anthropic.com>
- analytics: portfolio summary and time series (invested, portfolio value,
  buy&hold reference line, per-symbol prices) computed purely from SQLite
- api: FastAPI app with /api/health, /api/summary, /api/history, /api/trades
- no exchange calls, no writes; lazy `api.app` for `uvicorn krypto_dca.api:app`

Co-authored-by: Claude <claude@anthropic.com>
- fastapi + uvicorn become runtime deps for the backend
- httpx added to the dev extra for FastAPI's TestClient

Co-authored-by: Claude <claude@anthropic.com>
- krypto-dca-backend.service: Type=simple, Restart=always, same hardening as the timers
- nginx-trading.uliana.de.conf: TLS + HTTP Basic Auth in front of 127.0.0.1:8787

Co-authored-by: Claude <claude@anthropic.com>
- exchange_factory fixture for building FakeExchange with custom prices
- test_api: health, summary maths, trade pagination, history series + day window

Co-authored-by: Claude <claude@anthropic.com>
- REST endpoint table, updated architecture and repo layout
- SETUP: backend service + nginx vhost walkthrough, PR2 marked done

Co-authored-by: Claude <claude@anthropic.com>
DasAoD merged commit 7ac941024f into main 2026-08-28 15:50:36 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DasAoD/krypto-dca-bot!2
No description provided.