feat: real-time WebSocket streaming for prices and news#155
Open
luceinaltis wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StreamingProviderprotocol toqracer/data/providers.pywith callback-driven subscribe/unsubscribe APIFinnhubWebSocketAdapterinqracer/data/finnhub_ws.py-- persistent WebSocket connection towss://ws.finnhub.iowith deferred subscriptionsServerto evaluate alerts instantly on trade updatesAlertMonitor.evaluate_price()for single-ticker evaluation without a full sweepqracer serveCLI with graceful fallback to REST polling on connection failurewebsockets>=12.0under[streaming]extraCloses #132
Test plan
tests/data/test_finnhub_ws.py(init, callbacks, connect, subscribe, message dispatch)tests/test_alert_monitor.py(evaluate_pricemethod)tests/test_server.py(streaming lifecycle, price callback, notification)https://claude.ai/code/session_01GBX6TmhVqSUB3RXdt5JtcF