Migrate streaming clients off websockets.legacy before next major release
- Vorherrschende Sprache
- Python
- Sterne
- 1.5k
- Forks
- 397
- Ø Merge
- 1 T. 16 Std.
- Gemergte PRs (30 T.)
- 6
Beschreibung
## Summary
Alpaca-py streaming clients (`DataStream` / `TradingStream`) still bind the deprecated `websockets.legacy` client API. This emits `DeprecationWarning: websockets.legacy is deprecated` and blocks a clean upgrade path to modern `websockets` majors.
This should be completed **before the next major release**.
## Why now
- `websockets.legacy` has been deprecated since websockets 14.0; the library documents a migration path to the modern asyncio client.
- Dependabot / version bumps (e.g. [#713](https://github.com/alpacahq/alpaca-py/pull/713) bumping 12.0 → 16.1) are risky while we still import legacy APIs.
- [#740](https://github.com/alpacahq/alpaca-py/issues/740) improves reconnect reliability on the current stack but explicitly deferred the legacy migration as a separate piece of work.
- Related report: [#561](https://github.com/alpacahq/alpaca-py/issues/561) (`DeprecationWarning: websockets.legacy is deprecated`).
## Scope
1. Replace `websockets.legacy.client` usage in:
- `alpaca/data/live/websocket.py`
- `alpaca/trading/stream.py`
2. Align connection options (`extra_headers`, ping/keepalive, max queue, close behavior) with the modern client API.
3. Re-verify reconnect / `data_timeout` / backoff behavior from [#740](https://github.com/alpacahq/alpaca-py/issues/740) against the new client.
4. Update `websockets` dependency bounds once the migration is validated.
5. Add regression coverage for connect/auth/subscribe/consume/close on the new API surface.
## Non-goals
- Changing the public alpaca-py stream subscribe/handler API (unless required by the websockets migration).
- Shipping as a minor/patch if the new client requires breaking changes for callers who pass custom `websocket_params`.
## Acceptance criteria
- [ ] No imports from `websockets.legacy` remain in the package.
- [ ] Importing / running stream clients does not emit the legacy deprecation warning.
- [ ] Existing stream tests (including reconnect / staleness coverage) pass on the supported `websockets` range.
- [ ] `websocket_params` behavior is documented for any intentional breaking changes; if breaking, gate behind the next major version.
- [ ] Close or update [#561](https://github.com/alpacahq/alpaca-py/issues/561) once this ships.
## References
- https://websockets.readthedocs.io/en/stable/howto/upgrade.html
- #561, #713, #740
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.