Gateway Service
WebSocket hub and REST API
The Gateway subscribes to all Redis channels and streams, then fans out real-time data to connected browser clients. It also exposes REST endpoints for account management (Postgres-backed CRUD), PnL history, and signal history. Any service that publishes to Redis is automatically available to the browser through the Gateway.
WebSocket Protocol
Clients connect to ws://host/ws and subscribe with JSON:
{"subscribe": ["feed:BTC:tick", "feed:BTC:market:15min", "exec:*"]}
Pattern matching supports exact channels or globs: feed:*:tick, signal:*, system:status. New subscribers receive immediate hydration from Redis state.
Available Channels
feed:{token}:tick— Price ticks (~150ms debounced)feed:{token}:market:{frame}— Full market snapshot per frame (e.g. 15min, hourly)feed:{token}:book— Orderbook summarysignal:{strategy}:{account}:{token}— Per-strategy signalsexec:order_update— Order lifecycle eventsexec:position_update— Position state changessystem:status— Aggregated system healthoptimizer:status— Optimizer run progress
REST Endpoints
Accounts — CRUD for trading accounts (Postgres-backed). On mutation, publishes accounts:reload so Executor picks up changes.
History — /api/pnl, /api/signals for PnL and signal history.
Optimizer — POST /api/optimizer/run to trigger runs; GET for runs and results.
Backtester — POST /api/backtester/run; GET for results.
Backpressure
Each client has a send queue (max 256 messages). If a client is slow, oldest messages are dropped; newest is enqueued. Price data is latest-wins.