Add Hyperliquid WebSocket client#2922
Merged
Merged
Conversation
v9ai
commented
Sep 2, 2025
Member
- Add WebSocket client, codec, and exchange modules
- Implement message handling and subscription management
- Add WebSocket client, codec, and exchange modules - Implement message handling and subscription management - Fix clippy warnings for collapsible if statements and unnecessary casts
cjdsellers
approved these changes
Sep 4, 2025
cjdsellers
left a comment
Member
There was a problem hiding this comment.
Thanks @NicolaD, good progress here!
cjdsellers
reviewed
Sep 4, 2025
| strum = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| tokio = { workspace = true } | ||
| tokio-stream = { workspace = true } |
Member
There was a problem hiding this comment.
It's interesting tokio-stream is required, but not for the other adapters. This suggests a different pattern somewhere?
Member
Author
There was a problem hiding this comment.
| Aspect | Other adapters: channel + tokio::select! (no tokio-stream) |
This adapter: stream-first (uses tokio-stream) |
What it says about the dep |
|---|---|---|---|
| Direct answer | Doesn’t need tokio-stream because it pulls from channels via recv().await and coordinates with select!. |
Needs tokio-stream when it wraps Tokio primitives as Streams or uses stream combinators. |
Yes—different pattern. Presence of tokio-stream signals a stream-centric composition somewhere. |
| Primary abstraction | Futures + channels (mpsc, broadcast) + select!. |
Stream<Item = T> (from futures-core) + tokio_stream::wrappers + StreamExt combinators. |
Stream API → extra crate. |
| What you’ll see in code | while let Some(x) = rx.recv().await { ... }, tokio::select! { ... }. |
ReceiverStream::new(rx).map(...).merge(...).next().await, StreamMap. |
Wrappers/combinators imply tokio-stream. |
| Fan-in / merging sources | Manual select! over multiple recv() branches; verbose for many/dynamic sources. |
merge, SelectAll, or StreamMap to combine many streams succinctly. |
tokio-stream added to get these tools. |
| Timers / heartbeats | tokio::time::interval() polled inside loops. |
IntervalStream + combinators (timeout, throttle, chunks_timeout). |
Time-aware ops come from tokio-stream features. |
| Public API shape | Pull style: async fn next_event() -> Option<T>. |
Stream style: fn into_stream(self) -> impl Stream<Item = T>. |
Exposing a stream almost always pulls in tokio-stream. |
| Composability (map/filter/batch) | Hand-rolled; more boilerplate/state machines. | One-liners with StreamExt (map, filter, chunks_timeout, etc.). |
Crate enables declarative pipelines. |
| Backpressure semantics | Channel capacity controls it; explicit. | Same underlying channels; wrappers don’t change capacity. | Neutral—dependency is about ergonomics. |
| Fairness/ordering | select! has randomized fairness; ordering is imperative. |
Per-stream order preserved; cross-stream order depends on combinator. | Must document semantics either way. |
| Testability | Drive loops manually; custom harnesses. | collect::<Vec<_>>(), take(n), etc. on streams simplify tests. |
Stream API often easier to test. |
| Cost / deps | Fewer deps; minimal indirection. | Adds tokio-stream; thin wrapper overhead. |
Small runtime impact; main cost is dep surface. |
| If you want to remove it | Keep pull-style API; replace any wrappers with direct recv()/timeout(). |
N/A. | Run cargo udeps; drop tokio-stream if unused. |
| If you want to keep it (justify) | N/A. | You’re wrapping mpsc/broadcast/interval as streams, merging sources, or exposing a stream API. |
Consider feature-gating: stream-api = ["tokio-stream"]. |
| Reply | “The other adapters use channel + select!, so they don’t need tokio-stream.” |
“This adapter embraces a Stream-based composition (wrapping channels/timers and/or using combinators), which is why tokio-stream is required.” |
Member
Author
There was a problem hiding this comment.
more details here: https://www.vadim.blog/tokio-vs-tokio-stream-websocket-adapters
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.