1use hyperliquid::{
2 types::{
3 websocket::{
4 request::{Channel, Subscription},
5 response::Response,
6 },
7 Chain,
8 },
9 Hyperliquid, Result, Websocket,
10};
11
12#[tokio::main]
13async fn main() -> Result<()> {
14 let mut ws: Websocket = Hyperliquid::new(Chain::Dev);
15
16 ws.connect().await?;
17
18 let trades = Channel {
19 id: 2,
20 sub: Subscription::Trades { coin: "BTC".into() },
21 };
22
23 ws.subscribe(&[trades]).await?;
24
25 let handler = |event: Response| async move {
26 println!("Received Trades: \n--\n{:?}", event);
27
28 Ok(())
29 };
30
31 ws.next(handler).await?;
32
33 ws.disconnect().await?;
34
35 Ok(())
36}