ws_candle/
ws_candle.rs

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 candle = Channel {
19        id: 2,
20        sub: Subscription::Candle {
21            coin: "BTC".into(),
22            interval: "5m".into(),
23        },
24    };
25
26    ws.subscribe(&[candle]).await?;
27
28    let handler = |event: Response| async move {
29        println!("Received Candle: \n--\n{:?}", event);
30
31        Ok(())
32    };
33
34    ws.next(handler).await?;
35
36    ws.disconnect().await?;
37
38    Ok(())
39}