Skip to content

feat(streams): add /streams introspection endpoint for downstream WS clients#7

Merged
rdemeritt merged 2 commits into
mainfrom
feat/streams-endpoint-2026-06-17
Jun 17, 2026
Merged

feat(streams): add /streams introspection endpoint for downstream WS clients#7
rdemeritt merged 2 commits into
mainfrom
feat/streams-endpoint-2026-06-17

Conversation

@rdemeritt

Copy link
Copy Markdown
Member

Summary

Adds runtime introspection endpoint GET /streams for downstream WebSocket clients to query active subscriptions and client counts.

Features:

  • StreamRouter.status() — pure in-memory, zero I/O, no side effects
  • Compact mode (default): {"client_count": N, "subscriptions": M}
  • Verbose mode (?verbose=true): includes sorted symbol lists per subscription type
  • Type-switch on upstream_union (EquityStream/OptionStream) — schema documented
  • Auth-gated via X-API-Key header
  • 422 response on bad input (e.g., invalid verbose param)

Examples

Compact (default):

curl -H "X-API-Key: $(cat ./trader_token.json)" http://127.0.0.1:8000/streams
# {
#   "client_count": 2,
#   "subscriptions": {
#     "level_one_equity": 1,
#     "level_one_option": 1
#   }
# }

Verbose:

curl -H "X-API-Key: $(cat ./trader_token.json)" \
  'http://127.0.0.1:8000/streams?verbose=true'
# {
#   "client_count": 2,
#   "subscriptions": {
#     "level_one_equity": {
#       "count": 1,
#       "symbols": ["AAPL", "MSFT", ...]
#     },
#     "level_one_option": {
#       "count": 1,
#       "symbols": ["AAPL_061726C150", ...]
#     }
#   }
# }

Test Coverage: 30/30 QA criteria APPROVED (13/13 functional gates + 30 pytest assertions).

Files Changed

  • stream_router.pystatus() method + type discrimination
  • main.py — GET /streams route + auth decorator
  • tests/test_stream_router_status.py — new, 176 lines, 18 test cases
  • tests/test_streams_endpoint.py — new, 164 lines, 12 integration tests

…clients

Adds StreamRouter.status() (pure in-memory, no I/O, no mutation) and GET /streams
(auth-gated, verbose query param, 422 on bad input). 30 tests, all passing.
- ruff format applied to stream_router.py (long lines in status() split)
- tests/conftest.py sets SCHWAB_SKIP_INIT=true before any module import so
  the FastAPI lifespan skips session.start() in CI and clean local envs
@rdemeritt rdemeritt merged commit 36c9341 into main Jun 17, 2026
4 checks passed
@rdemeritt rdemeritt deleted the feat/streams-endpoint-2026-06-17 branch June 17, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant