Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/clob/ws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ impl<S: State> Client<S> {
}))
}

/// All market events on a single stream (`custom_feature_enabled`).
///
/// Single broadcast receiver for all [`WsMessage`] variants.
pub fn subscribe_all_market(
&self,
asset_ids: Vec<U256>,
) -> Result<impl Stream<Item = Result<WsMessage>> + use<S>> {
self.inner
.get_or_create_channel(ChannelType::Market)?
.subscriptions
.subscribe_market_with_options(asset_ids, true)
}

/// Get the current connection state for a specific channel.
///
/// Returns [`ConnectionState::Disconnected`] if the channel has not been
Expand Down
32 changes: 32 additions & 0 deletions tests/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,38 @@ mod custom_features {
})
}

#[tokio::test]
async fn subscribe_all_market_receives_book_and_bba() {
let mut server = MockWsServer::start().await;
let endpoint = server.ws_url("/ws/market");

let client = Client::new(&endpoint, Config::default()).unwrap();

let stream = client
.subscribe_all_market(vec![payloads::asset_id()])
.unwrap();
let mut stream = Box::pin(stream);

let sub_request = server.recv_subscription().await.unwrap();
assert!(sub_request.contains("\"custom_feature_enabled\":true"));

server.send(&payloads::book().to_string());
let msg = timeout(Duration::from_secs(2), stream.next())
.await
.unwrap()
.unwrap()
.unwrap();
assert!(matches!(msg, WsMessage::Book(_)));

server.send(&best_bid_ask().to_string());
let msg = timeout(Duration::from_secs(2), stream.next())
.await
.unwrap()
.unwrap()
.unwrap();
assert!(matches!(msg, WsMessage::BestBidAsk(_)));
}

#[tokio::test]
async fn subscribe_best_bid_ask_receives_updates() {
let mut server = MockWsServer::start().await;
Expand Down
Loading