M2 #23: API: WebSocket server for real-time updates#63
Merged
Conversation
- Add ws module to api crate with WebSocket support:
- mod.rs: Module exports
- messages.rs: ClientMessage and ServerMessage types
- channels.rs: Channel parsing and ChannelManager
- connection.rs: Connection state management
- handler.rs: WebSocket upgrade handler
- metrics.rs: WsMetrics for monitoring
- Channel subscriptions:
- book:{market} — Order book deltas
- trades:{market} — Real-time trades
- orders:{owner} — User's order updates (requires auth)
- Message types:
- subscribe/unsubscribe requests
- snapshot — Initial state on subscription
- update — Incremental updates
- error — Error responses
- ping/pong — Keepalive
- Connection management:
- Per-connection subscription tracking
- Authentication for private channels
- Backpressure via bounded mpsc channels
- WsState with shared ChannelManager and metrics
- WsMetrics tracking:
- Connections opened/closed/active
- Messages received/sent
- Subscriptions/unsubscriptions
- Errors and uptime
- Enable axum 'ws' feature for WebSocket support
- Add futures dependency for stream handling
- 50+ new unit tests for messages, channels, connection, and metrics
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
Implements the WebSocket server that provides real-time streaming of order book updates, trades, and user-specific order updates to connected clients.
Changes
New Module:
api/src/ws/mod.rsmessages.rschannels.rsconnection.rshandler.rsmetrics.rsChannel Subscriptions
book:{market}— Order book deltastrades:{market}— Real-time tradesorders:{owner}— User's order updates (requires auth)Message Types
Connection Management
WsMetrics Tracking
Dependencies
wsfeature for WebSocket supportfuturesdependency for stream handlingTechnical Decisions
WebSocketUpgradeWsStatecontainsChannelManagerandWsMetricsshared across connectionsTesting
Checklist
.internalDoc/09-rust-guidelines.mdcargo clippycargo fmtpassesCloses #23