M3 #29: Rust SDK: WebSocket client for real-time streaming#69
Merged
Conversation
- Add ws module to SDK with WebSocket client for real-time streaming: - config.rs: WsConfig with URL, heartbeat, reconnection settings - error.rs: WsError for connection, protocol, subscription errors - messages.rs: Message types for client/server communication - client.rs: MatchbookWsClient with async methods - Subscription management: - subscribe_book(market, depth) — Order book updates - subscribe_trades(market) — Trade stream - subscribe_orders() — User order updates (authenticated) - subscribe_ticker(market) — Price ticker - unsubscribe(channel, market) — Unsubscribe from channel - Message types: - ClientMessage: Subscribe, Unsubscribe, Ping - ServerMessage: Subscribed, BookSnapshot, BookUpdate, Trade, Ticker, OrderUpdate, Pong, Error - Channel: Book, Trades, Orders, Ticker - Subscription: Track active subscriptions - Connection lifecycle: - Automatic heartbeat/ping-pong - Event stream via next_event() - Graceful shutdown via close() - Add tokio-tungstenite and futures-util to workspace dependencies - 28 unit tests for WebSocket client
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 client that connects to the streaming API for real-time order book updates, trades, and user order notifications.
Changes
New Module:
sdk/src/ws/mod.rsconfig.rserror.rsmessages.rsclient.rsWebSocket Configuration
Subscription Management
subscribe_book(market, depth)— Order book updatessubscribe_trades(market)— Trade streamsubscribe_orders()— User order updates (authenticated)subscribe_ticker(market)— Price tickerunsubscribe(channel, market)— Unsubscribe from channelMessage Types
Client Messages:
Subscribe— Subscribe to a channelUnsubscribe— Unsubscribe from a channelPing— Heartbeat pingServer Messages:
Subscribed/Unsubscribed— Subscription confirmationsBookSnapshot— Full order book snapshotBookUpdate— Incremental book updates (deltas)Trade— Trade eventsTicker— Price ticker updatesOrderUpdate— User order updatesPong— Heartbeat responseError— Error messagesConnection Lifecycle
next_event()close()Dependencies
tokio-tungstenitev0.26 with rustls-tlsfutures-utilv0.3Technical Decisions
next_event()methodRwLock<HashSet<Subscription>>Testing
Checklist
.internalDoc/09-rust-guidelines.mdcargo clippycargo fmtpassesCloses #29