Skip to content

feat: real-time WebSocket streaming for prices and news#155

Open
luceinaltis wants to merge 1 commit into
mainfrom
feat/132-websocket-streaming
Open

feat: real-time WebSocket streaming for prices and news#155
luceinaltis wants to merge 1 commit into
mainfrom
feat/132-websocket-streaming

Conversation

@luceinaltis
Copy link
Copy Markdown
Owner

Summary

  • Add StreamingProvider protocol to qracer/data/providers.py with callback-driven subscribe/unsubscribe API
  • Implement FinnhubWebSocketAdapter in qracer/data/finnhub_ws.py -- persistent WebSocket connection to wss://ws.finnhub.io with deferred subscriptions
  • Integrate real-time price callbacks into Server to evaluate alerts instantly on trade updates
  • Add AlertMonitor.evaluate_price() for single-ticker evaluation without a full sweep
  • Wire adapter into qracer serve CLI with graceful fallback to REST polling on connection failure
  • New optional dependency: websockets>=12.0 under [streaming] extra

Closes #132

Test plan

  • 15 new tests in tests/data/test_finnhub_ws.py (init, callbacks, connect, subscribe, message dispatch)
  • 4 new tests in tests/test_alert_monitor.py (evaluate_price method)
  • 5 new tests in tests/test_server.py (streaming lifecycle, price callback, notification)
  • Full suite: 784 passed, 14 skipped
  • Ruff lint: all checks passed

https://claude.ai/code/session_01GBX6TmhVqSUB3RXdt5JtcF

Adds a FinnhubWebSocketAdapter that maintains a persistent WebSocket
connection to Finnhub and dispatches trade and news messages to
registered callbacks.  Integrated into `qracer serve` so price
alerts evaluate instantly on every tick instead of waiting for the
next REST poll.

- `StreamingProvider` protocol in `qracer/data/providers.py`
- `FinnhubWebSocketAdapter` in `qracer/data/finnhub_ws.py` with
  deferred-subscription, graceful disconnect, and resilient dispatch
- `AlertMonitor.evaluate_price(ticker, price)` for push-based evaluation
- `Server` connects and wires the adapter at startup, subscribing to
  every ticker with an active alert, and falls back to REST polling on
  handshake failure
- `qracer serve` builds the adapter from `providers.toml` + the
  `FINNHUB_API_KEY` credential when the `streaming` extra is installed
- New `streaming` optional dependency (`websockets>=12.0`)
- Tests: adapter init, connect/subscribe/dispatch, alert evaluate_price,
  server streaming lifecycle and callback wiring

https://claude.ai/code/session_01YY9Dx62ZyhP5tV5XumdvPs
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.

feat: real-time WebSocket streaming for prices and news

2 participants