Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ccb9ea8
Added ws bbo
austinzhang1018 May 2, 2025
d171dd1
cleaned up import
austinzhang1018 May 2, 2025
6da990b
added cloid support to modify requests
austinzhang1018 May 19, 2025
d32db23
Merge pull request #2 from austinzhang1018/modify-request-cloid
austinzhang1018 May 19, 2025
ebc269a
added users to trade field
austinzhang1018 Jun 14, 2025
f28d955
updated tokio tungstenite and updated websocket params for faster web…
austinzhang1018 Jul 5, 2025
7527b5a
Merge pull request #3 from austinzhang1018/fast-websockets
austinzhang1018 Jul 7, 2025
4abb2cb
updated reqwest version
austinzhang1018 Jul 15, 2025
b4ab3f5
added ws place and cancel methods
austinzhang1018 Jul 19, 2025
4cc2e7f
added post client
austinzhang1018 Jul 19, 2025
98c0410
Merge pull request #4 from austinzhang1018/ws-place-cancel
austinzhang1018 Jul 20, 2025
ecb7f82
added ping
austinzhang1018 Jul 20, 2025
2358d44
Merge pull request #5 from austinzhang1018/add-post-ws-ping
austinzhang1018 Jul 20, 2025
3f4df43
added ping
austinzhang1018 Jul 20, 2025
7357a00
Merge pull request #6 from austinzhang1018/add-post-ws-ping
austinzhang1018 Jul 20, 2025
ffcf4c9
added ws post performance metrics
austinzhang1018 Oct 11, 2025
ac5871d
Merge pull request #7 from austinzhang1018/austin/added-ws-post-perfo…
austinzhang1018 Oct 11, 2025
38399e2
add nonce as a return type to place orders
spiderman279 Oct 13, 2025
73eb7e8
add noop as an action
spiderman279 Oct 13, 2025
63b95d2
switch to a prepare the send model
spiderman279 Oct 13, 2025
c6ef834
Merge branch 'add-nonce' of github.com:austinzhang1018/hyperliquid-ru…
spiderman279 Oct 16, 2025
0958f38
add test case
spiderman279 Oct 16, 2025
6af4d09
Merge pull request #9 from austinzhang1018/add-noop
spiderman279 Oct 16, 2025
98e0180
Merge pull request #8 from austinzhang1018/add-nonce
spiderman279 Oct 16, 2025
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
30 changes: 30 additions & 0 deletions src/bin/ws_bbo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use hyperliquid_rust_sdk::{BaseUrl, InfoClient, Message, Subscription};
use log::info;
use tokio::{
spawn,
sync::mpsc::unbounded_channel,
time::{sleep, Duration},
};

#[tokio::main]
async fn main() {
env_logger::init();
let mut info_client = InfoClient::new(None, Some(BaseUrl::Testnet)).await.unwrap();
let coin = "BTC".to_string();

let (sender, mut receiver) = unbounded_channel();
let subscription_id = info_client
.subscribe(Subscription::Bbo { coin }, sender)
.await
.unwrap();

spawn(async move {
sleep(Duration::from_secs(30)).await;
info!("Unsubscribing from bbo");
info_client.unsubscribe(subscription_id).await.unwrap()
});

while let Some(Message::Bbo(bbo)) = receiver.recv().await {
info!("Received bbo: {bbo:?}");
}
}
5 changes: 5 additions & 0 deletions src/ws/message_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pub struct WebData2 {
pub struct ActiveAssetCtx {
pub data: ActiveAssetCtxData,
}

#[derive(Deserialize, Clone, Debug)]
pub struct Bbo {
pub data: BboData,
}
8 changes: 8 additions & 0 deletions src/ws/sub_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,11 @@ pub struct SpotAssetCtx {
pub shared: SharedAssetCtx,
pub circulating_supply: String,
}

#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BboData {
pub coin: String,
pub time: u64,
pub bbo: Vec<Option<BookLevel>>
}
8 changes: 7 additions & 1 deletion src/ws/ws_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
prelude::*,
ws::message_types::{AllMids, Candle, L2Book, OrderUpdates, Trades, User},
ws::message_types::{AllMids, Candle, L2Book, OrderUpdates, Trades, User, Bbo},
ActiveAssetCtx, Error, Notification, UserFills, UserFundings, UserNonFundingLedgerUpdates,
WebData2,
};
Expand Down Expand Up @@ -62,6 +62,7 @@ pub enum Subscription {
UserFundings { user: H160 },
UserNonFundingLedgerUpdates { user: H160 },
ActiveAssetCtx { coin: String },
Bbo { coin: String },
}

#[derive(Deserialize, Clone, Debug)]
Expand All @@ -83,6 +84,7 @@ pub enum Message {
Notification(Notification),
WebData2(WebData2),
ActiveAssetCtx(ActiveAssetCtx),
Bbo(Bbo),
Pong,
}

Expand Down Expand Up @@ -267,6 +269,10 @@ impl WsManager {
})
.map_err(|e| Error::JsonParse(e.to_string()))
}
Message::Bbo(bbo) => {
serde_json::to_string(&Subscription::Bbo { coin: bbo.data.coin.clone() })
.map_err(|e| Error::JsonParse(e.to_string()))
},
Message::SubscriptionResponse | Message::Pong => Ok(String::default()),
Message::NoData => Ok("".to_string()),
Message::HyperliquidError(err) => Ok(format!("hyperliquid error: {err:?}")),
Expand Down
Loading