Initial commit: btcdata — BTC data backend service

Split from btcprice monolith. Owns DB, migrations, Binance WebSocket,
Kraken OHLC pollers, and exposes a JSON API with SSE price stream.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-23 20:07:30 +01:00
co-authored by Claude Opus 4.6
commit f64aa98b04
35 changed files with 1079 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
# btcdata
Bitcoin data backend — Clojure Kit application. Fetches BTC prices from Binance WebSocket and Kraken HTTP, stores in PostgreSQL, exposes a JSON API with SSE price stream.
## Build & Development Commands
- `make run` — Start dev server on port 4100
- `make repl` — Start nREPL
- `make test` — Run tests
- `make uberjar` — Build production JAR
## REPL Commands
```clojure
(dev-prep!) ;; Prepare dev system
(go) ;; Start system
(reset) ;; Reload code & restart
(halt) ;; Stop system
(reset-db) ;; Drop & re-migrate database
(migrate) ;; Run pending migrations
(rollback) ;; Rollback last migration
(query-fn) ;; Get database query function
```
## Architecture
- **Framework:** Kit (Integrant-based)
- **Server:** Undertow
- **Routing:** Reitit
- **Database:** PostgreSQL + conman + Migratus
- **Port:** 4100 (env: BTCDATA_PORT)
- **CORS:** Configured via CORS_ORIGIN env var
## API Endpoints
- `GET /api/health` — Health check
- `GET /api/price/stream` — SSE stream with JSON price updates
- `GET /api/price/latest` — Latest price as JSON
## Source Layout
```
src/clj/pmagnus/btcdata/
├── core.clj # App entry point
├── config.clj # System config loader
├── ws/
│ └── binance.clj # Binance WebSocket client
├── kraken/
│ ├── ohlc.clj # Hourly OHLC poller
│ └── ohlc_daily.clj # Daily OHLC poller
└── web/
├── handler.clj # Ring handler + routes
├── controllers/
│ └── health.clj # Health check
├── middleware/
│ ├── core.clj # Base middleware + CORS
│ ├── exception.clj # Exception handling
│ └── formats.clj # Content negotiation
└── routes/
├── api.clj # /api routes (JSON + SSE)
└── utils.clj # Route utilities
```