magnusandClaude Opus 4.6 9283826ac4 Replace SSE price stream with WebSocket, use separate Docker port
- Replace SSE endpoint (/api/price/stream) with WebSocket (/api/price/ws)
  using ring-undertow-adapter's built-in WebSocket support
- Change Docker internal port from 4100 to 4101 to avoid conflicts with
  local dev (make run still uses 4100)
- Add free-port.sh utility script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 21:32:19 +01:00

btcdata

Bitcoin data backend service. Fetches BTC prices from Binance (WebSocket) and Kraken (HTTP polling), stores them in PostgreSQL, and exposes a JSON API with Server-Sent Events for live price streaming.

API

Endpoint Description
GET /api/price/stream SSE stream — emits price-update events with JSON {price, prev_price, recorded_at}
GET /api/price/latest Latest price as JSON
GET /api/health Health check

Quick Start

# Local dev (requires PostgreSQL)
cp .env.example .env   # edit JDBC_URL
make run               # starts on port 4100

# Docker
docker compose up -d   # starts on port 4101

Environment Variables

Variable Default Description
BTCDATA_PORT 4100 HTTP server port
JDBC_URL PostgreSQL connection string
CORS_ORIGIN * Allowed origin for CORS headers

Data Sources

  • Binance — WebSocket trade stream (btcusdt@trade), throttled to 5s writes
  • Kraken hourly — OHLC candles polled at HH:01:00 UTC
  • Kraken daily — OHLC candles polled at 00:01:00 UTC

Tech Stack

Clojure · Kit · Undertow · Reitit · PostgreSQL · conman · Migratus

S
Description
Bitcoin data backend — BTC price API with WebSocket streaming
Readme
220 KiB
Languages
Clojure 97.5%
Shell 1.3%
Dockerfile 0.8%
Makefile 0.4%