ws_order_updates/
ws_order_updates.rs

1use 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    // Key was randomly generated for testing and shouldn't be used with any real funds
18    let wallet: Arc<LocalWallet> = Arc::new(
19        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
20            .parse()
21            .unwrap(),
22    );
23
24    let mut ws: Websocket = Hyperliquid::new(Chain::Dev);
25
26    ws.connect().await?;
27
28    let order_updates = Channel {
29        id: 2,
30        sub: Subscription::OrderUpdates {
31            user: wallet.address(),
32        },
33    };
34
35    ws.subscribe(&[order_updates]).await?;
36
37    let handler = |event: Response| async move {
38        println!("Received Order Updates: \n--\n{:?}", event);
39
40        Ok(())
41    };
42
43    ws.next(handler).await?;
44
45    ws.disconnect().await?;
46
47    Ok(())
48}