ws_notification/
ws_notification.rs1use std::sync::Arc;
2
3use ethers::signers::{LocalWallet, Signer};
4use hyperliquid::{
5 types::{
6 websocket::{
7 request::{Channel, Subscription},
8 response::Response,
9 },
10 Chain,
11 },
12 Hyperliquid, Result, Websocket,
13};
14
15#[tokio::main]
16async fn main() -> Result<()> {
17 let wallet: Arc<LocalWallet> = Arc::new(
19 "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
20 .parse()
21 .unwrap(),
22 );
23 let mut ws: Websocket = Hyperliquid::new(Chain::Dev);
24
25 ws.connect().await?;
26
27 let notification = Channel {
28 id: 2,
29 sub: Subscription::Notification {
30 user: wallet.address(),
31 },
32 };
33
34 ws.subscribe(&[notification]).await?;
35
36 let handler = |event: Response| async move {
37 println!("Received Notification: \n--\n{:?}", event);
38
39 Ok(())
40 };
41
42 ws.next(handler).await?;
43
44 ws.disconnect().await?;
45
46 Ok(())
47}