feat: MD pipeline — market-data-service hardening + SenpAI NATS consumer
Producer (market-data-service):
- Backpressure: smart drop policy (heartbeats→quotes→trades preserved)
- Heartbeat monitor: synthetic HeartbeatEvent on provider silence
- Graceful shutdown: WS→bus→storage→DB engine cleanup sequence
- Bybit V5 public WS provider (backup for Binance, no API key needed)
- FailoverManager: health-based provider switching with recovery
- NATS output adapter: md.events.{type}.{symbol} for SenpAI
- /bus-stats endpoint for backpressure monitoring
- Dockerfile + docker-compose.node1.yml integration
- 36 tests (parsing + bus + failover), requirements.lock
Consumer (senpai-md-consumer):
- NATSConsumer: subscribe md.events.>, queue group senpai-md, backpressure
- State store: LatestState + RollingWindow (deque, 60s)
- Feature engine: 11 features (mid, spread, VWAP, return, vol, latency)
- Rule-based signals: long/short on return+volume+spread conditions
- Publisher: rate-limited features + signals + alerts to NATS
- HTTP API: /health, /metrics, /state/latest, /features/latest, /stats
- 10 Prometheus metrics
- Dockerfile + docker-compose.senpai.yml
- 41 tests (parsing + state + features + rate-limit), requirements.lock
CI: ruff + pytest + smoke import for both services
Tests: 77 total passed, lint clean
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
|
||||
# ── Binance (no key needed for public WebSocket) ──────────────────────
|
||||
BINANCE_WS_URL=wss://stream.binance.com:9443/ws
|
||||
# BINANCE_REST_URL=https://api.binance.com
|
||||
|
||||
# ── Bybit (backup crypto — no key needed) ────────────────────────────
|
||||
BYBIT_WS_URL=wss://stream.bybit.com/v5/public/spot
|
||||
|
||||
# ── Alpaca (paper trading — free) ─────────────────────────────────────
|
||||
# Get free paper keys at: https://app.alpaca.markets/paper/dashboard/overview
|
||||
@@ -22,9 +26,17 @@ RECONNECT_BASE_DELAY=1.0
|
||||
RECONNECT_MAX_DELAY=60.0
|
||||
HEARTBEAT_TIMEOUT=30.0
|
||||
|
||||
# ── HTTP Server ───────────────────────────────────────────────────────
|
||||
# ── HTTP Server / Metrics ─────────────────────────────────────────────
|
||||
HTTP_HOST=0.0.0.0
|
||||
HTTP_PORT=8891
|
||||
METRICS_ENABLED=true
|
||||
|
||||
# ── NATS Output (SenpAI integration) ─────────────────────────────────
|
||||
# Enable to push events to NATS for SenpAI consumption
|
||||
# Subject schema: md.events.{type}.{symbol} e.g. md.events.trade.BTCUSDT
|
||||
NATS_URL=nats://localhost:4222
|
||||
NATS_SUBJECT_PREFIX=md.events
|
||||
NATS_ENABLED=false
|
||||
|
||||
# ── Logging ───────────────────────────────────────────────────────────
|
||||
LOG_LEVEL=INFO
|
||||
|
||||
Reference in New Issue
Block a user