From bf4ed53352844e7ca7905ba477c17adf0c7ec734 Mon Sep 17 00:00:00 2001 From: tedison Date: Sat, 23 Nov 2024 14:25:55 -0500 Subject: [PATCH 01/10] make all crates public --- src/lib.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 86f20e2a..c7588a80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,15 @@ #![deny(unreachable_pub)] -mod consts; -mod eip712; -mod errors; -mod exchange; -mod helpers; -mod info; -mod market_maker; -mod meta; -mod prelude; -mod req; -mod signature; -mod ws; +pub mod consts; +pub mod errors; +pub mod exchange; +pub mod helpers; +pub mod info; +pub mod market_maker; +pub mod meta; +pub mod prelude; +pub mod req; +pub mod signature; +pub mod ws; pub use consts::{EPSILON, LOCAL_API_URL, MAINNET_API_URL, TESTNET_API_URL}; pub use eip712::Eip712; pub use errors::Error; From b3743e8aa172442acb0856a3c0c576cb0e81cda0 Mon Sep 17 00:00:00 2001 From: tedison Date: Sun, 24 Nov 2024 17:47:22 -0500 Subject: [PATCH 02/10] qol --- src/exchange/exchange_client.rs | 2 +- src/info/info_client.rs | 9 ++++++++- src/info/sub_structs.rs | 2 +- src/meta.rs | 16 ++++++++++++++++ src/req.rs | 2 +- src/ws/ws_manager.rs | 3 ++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/exchange/exchange_client.rs b/src/exchange/exchange_client.rs index 70b686b8..19ea9937 100644 --- a/src/exchange/exchange_client.rs +++ b/src/exchange/exchange_client.rs @@ -30,7 +30,7 @@ use crate::{ VaultTransfer, Withdraw3, }; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ExchangeClient { pub http_client: HttpClient, pub wallet: PrivateKeySigner, diff --git a/src/info/info_client.rs b/src/info/info_client.rs index b3d8ba2a..e6313095 100644 --- a/src/info/info_client.rs +++ b/src/info/info_client.rs @@ -19,6 +19,13 @@ use crate::{ UserFundingResponse, UserTokenBalanceResponse, }; +use ethers::types::H160; +use log::info; +use reqwest::Client; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use tokio::sync::mpsc::UnboundedSender; + #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct CandleSnapshotRequest { @@ -96,7 +103,7 @@ pub enum InfoRequest { }, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct InfoClient { pub http_client: HttpClient, pub(crate) ws_manager: Option, diff --git a/src/info/sub_structs.rs b/src/info/sub_structs.rs index d244a063..bef31fd3 100644 --- a/src/info/sub_structs.rs +++ b/src/info/sub_structs.rs @@ -108,7 +108,7 @@ pub struct Vip { pub ntl_cutoff: String, } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct UserTokenBalance { pub coin: String, diff --git a/src/meta.rs b/src/meta.rs index 5c983dfe..a50eb3fb 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -52,6 +52,21 @@ pub enum SpotMetaAndAssetCtxs { Context(Vec), } +impl SpotMetaAndAssetCtxs { + pub fn get_spot_meta(&self) -> &SpotMeta { + match self { + SpotMetaAndAssetCtxs::SpotMeta(meta) => meta, + _ => panic!("Not a spot meta"), + } + } + pub fn get_context(&self) -> &Vec { + match self { + SpotMetaAndAssetCtxs::Context(ctxs) => ctxs, + _ => panic!("Not a context"), + } + } +} + #[derive(Deserialize, Debug, Clone)] #[serde(untagged)] pub enum MetaAndAssetCtxs { @@ -112,4 +127,5 @@ pub struct TokenInfo { pub index: usize, pub token_id: B128, pub is_canonical: bool, + pub full_name: Option, } diff --git a/src/req.rs b/src/req.rs index f7d5e430..e458b226 100644 --- a/src/req.rs +++ b/src/req.rs @@ -10,7 +10,7 @@ struct ErrorData { msg: String, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct HttpClient { pub client: Client, pub base_url: String, diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index 4035baf3..281fbe16 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -41,7 +41,8 @@ struct SubscriptionData { subscription_id: u32, id: String, } -#[derive(Debug)] + +#[derive(Debug, Clone)] pub(crate) struct WsManager { stop_flag: Arc, writer: Arc>, protocol::Message>>>, From e2e025be920258ae2d261742a3b5d260ea31f5f1 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 25 Nov 2024 17:36:40 -0500 Subject: [PATCH 03/10] remove unused import --- src/info/info_client.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/info/info_client.rs b/src/info/info_client.rs index e6313095..ca794e63 100644 --- a/src/info/info_client.rs +++ b/src/info/info_client.rs @@ -20,7 +20,6 @@ use crate::{ }; use ethers::types::H160; -use log::info; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::collections::HashMap; From 132b8d535697e1e4a09f794e562b773700a4f4be Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 23 Dec 2024 10:41:14 +0100 Subject: [PATCH 04/10] serialize spot meta and context --- src/meta.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index a50eb3fb..4f22464f 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -1,14 +1,15 @@ use std::collections::HashMap; use alloy::primitives::B128; -use serde::Deserialize; +use ethers::abi::ethereum_types::H128; +use serde::{Deserialize, Serialize}; #[derive(Deserialize, Debug, Clone)] pub struct Meta { pub universe: Vec, } -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone, Serialize)] pub struct SpotMeta { pub universe: Vec, pub tokens: Vec, @@ -74,7 +75,7 @@ pub enum MetaAndAssetCtxs { Context(Vec), } -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct SpotAssetContext { pub day_ntl_vlm: String, @@ -109,7 +110,7 @@ pub struct AssetMeta { pub only_isolated: Option, } -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct SpotAssetMeta { pub tokens: [usize; 2], @@ -118,7 +119,7 @@ pub struct SpotAssetMeta { pub is_canonical: bool, } -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Deserialize, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct TokenInfo { pub name: String, From b1bdf95784c4bd8516d70d028a0d0a868a588338 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 23 Dec 2024 11:47:37 +0100 Subject: [PATCH 05/10] fix message types --- src/ws/message_types.rs | 1 + src/ws/sub_structs.rs | 52 +++++++++++++++++++++++++++++++++++++++++ src/ws/ws_manager.rs | 14 +++++++++++ 3 files changed, 67 insertions(+) diff --git a/src/ws/message_types.rs b/src/ws/message_types.rs index 332a9e2b..ec019e70 100644 --- a/src/ws/message_types.rs +++ b/src/ws/message_types.rs @@ -58,6 +58,7 @@ pub struct WebData2 { } #[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] pub struct ActiveAssetCtx { pub data: ActiveAssetCtxData, } diff --git a/src/ws/sub_structs.rs b/src/ws/sub_structs.rs index 4c3c94e5..009041a0 100644 --- a/src/ws/sub_structs.rs +++ b/src/ws/sub_structs.rs @@ -351,3 +351,55 @@ pub struct BboData { pub time: u64, pub bbo: Vec>, } + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub enum ActiveAssetCtxData { + WsActiveAssetCtx(WsActiveAssetCtx), + WsActiveSpotAssetCtx(WsActiveSpotAssetCtx), +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct WsActiveAssetCtx { + pub coin: String, + pub ctx: PerpsAssetCtx, +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct WsActiveSpotAssetCtx { + pub coin: String, + pub ctx: SpotAssetCtx, +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct SharedAssetCtx { + pub day_ntl_vlm: u64, + pub prev_day_px: u64, + pub mark_px: u64, + pub mid_px: Option, +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct PerpsAssetCtx { + pub day_ntl_vlm: u64, + pub prev_day_px: u64, + pub mark_px: u64, + pub mid_px: Option, + pub funding: u64, + pub open_interest: u64, + pub oracle_px: u64, +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct SpotAssetCtx { + pub day_ntl_vlm: u64, + pub prev_day_px: u64, + pub mark_px: u64, + pub mid_px: Option, + pub circulating_supply: u64, +} diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index 281fbe16..ab41309e 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -35,6 +35,8 @@ use crate::{ WebData2, }; +use super::{ActiveAssetCtx, ActiveAssetCtxData}; + #[derive(Debug)] struct SubscriptionData { sending_channel: UnboundedSender, @@ -297,6 +299,18 @@ impl WsManager { Message::SubscriptionResponse | Message::Pong => Ok(String::default()), Message::NoData => Ok("".to_string()), Message::HyperliquidError(err) => Ok(format!("hyperliquid error: {err:?}")), + Message::ActiveAssetCtx(active_asset_ctx) => { + let coin = match &active_asset_ctx.data { + ActiveAssetCtxData::WsActiveAssetCtx(active_asset_ctx) => { + active_asset_ctx.coin.clone() + } + ActiveAssetCtxData::WsActiveSpotAssetCtx(active_asset_ctx) => { + active_asset_ctx.coin.clone() + } + }; + serde_json::to_string(&Subscription::ActiveAssetCtx { coin }) + .map_err(|e| Error::JsonParse(e.to_string())) + } } } From 398fc7e9b185bb4f7c7efbdfad4c20e41a303e49 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 23 Dec 2024 12:56:54 +0100 Subject: [PATCH 06/10] Fix active assets --- src/ws/sub_structs.rs | 56 ++++++++++--------------------------------- src/ws/ws_manager.rs | 16 ++++--------- 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/src/ws/sub_structs.rs b/src/ws/sub_structs.rs index 009041a0..aca7e3b0 100644 --- a/src/ws/sub_structs.rs +++ b/src/ws/sub_structs.rs @@ -354,52 +354,22 @@ pub struct BboData { #[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -pub enum ActiveAssetCtxData { - WsActiveAssetCtx(WsActiveAssetCtx), - WsActiveSpotAssetCtx(WsActiveSpotAssetCtx), -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct WsActiveAssetCtx { - pub coin: String, - pub ctx: PerpsAssetCtx, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct WsActiveSpotAssetCtx { +pub struct ActiveAssetCtxData { pub coin: String, - pub ctx: SpotAssetCtx, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct SharedAssetCtx { - pub day_ntl_vlm: u64, - pub prev_day_px: u64, - pub mark_px: u64, - pub mid_px: Option, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct PerpsAssetCtx { - pub day_ntl_vlm: u64, - pub prev_day_px: u64, - pub mark_px: u64, - pub mid_px: Option, - pub funding: u64, - pub open_interest: u64, - pub oracle_px: u64, + pub ctx: AssetCtx, } #[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -pub struct SpotAssetCtx { - pub day_ntl_vlm: u64, - pub prev_day_px: u64, - pub mark_px: u64, - pub mid_px: Option, - pub circulating_supply: u64, +pub struct AssetCtx { + pub funding: String, + pub open_interest: String, + pub prev_day_px: String, + pub day_ntl_vlm: String, + pub premium: String, + pub oracle_px: String, + pub mark_px: String, + pub mid_px: String, + pub impact_pxs: Vec, + pub day_base_vlm: String, } diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index ab41309e..af66672c 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -35,7 +35,7 @@ use crate::{ WebData2, }; -use super::{ActiveAssetCtx, ActiveAssetCtxData}; +use super::ActiveAssetCtx; #[derive(Debug)] struct SubscriptionData { @@ -300,16 +300,10 @@ impl WsManager { Message::NoData => Ok("".to_string()), Message::HyperliquidError(err) => Ok(format!("hyperliquid error: {err:?}")), Message::ActiveAssetCtx(active_asset_ctx) => { - let coin = match &active_asset_ctx.data { - ActiveAssetCtxData::WsActiveAssetCtx(active_asset_ctx) => { - active_asset_ctx.coin.clone() - } - ActiveAssetCtxData::WsActiveSpotAssetCtx(active_asset_ctx) => { - active_asset_ctx.coin.clone() - } - }; - serde_json::to_string(&Subscription::ActiveAssetCtx { coin }) - .map_err(|e| Error::JsonParse(e.to_string())) + serde_json::to_string(&Subscription::ActiveAssetCtx { + coin: active_asset_ctx.data.coin.clone(), + }) + .map_err(|e| Error::JsonParse(e.to_string())) } } } From a1d351708ddccc1ffa215a54ef604b1a050fa197 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 23 Dec 2024 15:09:49 +0100 Subject: [PATCH 07/10] resubscription --- src/errors.rs | 2 ++ src/ws/message_types.rs | 5 +++++ src/ws/ws_manager.rs | 26 +++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 00d56fb1..db525233 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -61,4 +61,6 @@ pub enum Error { SignatureFailure(String), #[error("Vault address not found")] VaultAddressNotFound, + #[error("Subscription error: {0:?}")] + SubscriptionError(String), } diff --git a/src/ws/message_types.rs b/src/ws/message_types.rs index ec019e70..5177b0e1 100644 --- a/src/ws/message_types.rs +++ b/src/ws/message_types.rs @@ -2,6 +2,11 @@ use serde::Deserialize; use crate::ws::sub_structs::*; +#[derive(Deserialize, Clone, Debug)] +pub struct SubscriptionError { + pub data: String, +} + #[derive(Deserialize, Clone, Debug)] pub struct Trades { pub data: Vec, diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index af66672c..1de81a82 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -35,7 +35,7 @@ use crate::{ WebData2, }; -use super::ActiveAssetCtx; +use super::{ActiveAssetCtx, SubscriptionError}; #[derive(Debug)] struct SubscriptionData { @@ -95,6 +95,7 @@ pub enum Message { ActiveAssetData(ActiveAssetData), ActiveSpotAssetCtx(ActiveSpotAssetCtx), Bbo(Bbo), + Error(SubscriptionError), Pong, } @@ -305,6 +306,15 @@ impl WsManager { }) .map_err(|e| Error::JsonParse(e.to_string())) } + Message::Error(err) => { + let error_str = err.data.to_string(); + let identifier = error_str + .split("Invalid subscription ") + .nth(1) + .unwrap_or("Invalid subscription") + .to_string(); + Ok(identifier) + } } } @@ -318,8 +328,10 @@ impl WsManager { if !data.starts_with('{') { return Ok(()); } + let message = serde_json::from_str::(&data) .map_err(|e| Error::JsonParse(e.to_string()))?; + let identifier = WsManager::get_identifier(&message)?; if identifier.is_empty() { return Ok(()); @@ -420,15 +432,11 @@ impl WsManager { ) -> Result { let mut subscriptions = self.subscriptions.lock().await; - let identifier_entry = if let Subscription::UserEvents { user: _ } = - serde_json::from_str::(&identifier) - .map_err(|e| Error::JsonParse(e.to_string()))? - { + let subscription = serde_json::from_str::(&identifier) + .map_err(|e| Error::JsonParse(e.to_string()))?; + let identifier_entry = if let Subscription::UserEvents { user: _ } = subscription { "userEvents".to_string() - } else if let Subscription::OrderUpdates { user: _ } = - serde_json::from_str::(&identifier) - .map_err(|e| Error::JsonParse(e.to_string()))? - { + } else if let Subscription::OrderUpdates { user: _ } = subscription { "orderUpdates".to_string() } else { identifier.clone() From f7cb0092c11712bbebc49e8bfca1c26bc24f76e6 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 30 Dec 2024 14:06:56 +0100 Subject: [PATCH 08/10] fix some info and ws types --- src/info/sub_structs.rs | 1 + src/ws/sub_structs.rs | 39 +++++++++++++++++++++++++++++++-------- src/ws/ws_manager.rs | 12 ++++++++---- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/info/sub_structs.rs b/src/info/sub_structs.rs index bef31fd3..53515d3f 100644 --- a/src/info/sub_structs.rs +++ b/src/info/sub_structs.rs @@ -114,6 +114,7 @@ pub struct UserTokenBalance { pub coin: String, pub hold: String, pub total: String, + pub token: u32, pub entry_ntl: String, } diff --git a/src/ws/sub_structs.rs b/src/ws/sub_structs.rs index aca7e3b0..d4d73e98 100644 --- a/src/ws/sub_structs.rs +++ b/src/ws/sub_structs.rs @@ -356,20 +356,43 @@ pub struct BboData { #[serde(rename_all = "camelCase")] pub struct ActiveAssetCtxData { pub coin: String, - pub ctx: AssetCtx, + pub ctx: ActiveAssetCtxEnum, } +#[derive(Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum ActiveAssetCtxEnum { + Perps(PerpsAssetCtx), + Spot(SpotAssetCtx), +} #[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -pub struct AssetCtx { - pub funding: String, - pub open_interest: String, - pub prev_day_px: String, +pub struct PerpsAssetCtx { + pub day_ntl_vlm: u64, + pub prev_day_px: u64, + pub mark_px: u64, + pub mid_px: Option, + pub funding: u64, + pub open_interest: u64, + pub oracle_px: u64, +} + +#[derive(Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct SpotAssetDetails { + #[serde(rename = "prevDayPx")] + pub prev_day_px: String, // Ensure this matches the JSON field exactly pub day_ntl_vlm: String, - pub premium: String, - pub oracle_px: String, pub mark_px: String, pub mid_px: String, - pub impact_pxs: Vec, + pub circulating_supply: String, + pub coin: String, + pub total_supply: String, pub day_base_vlm: String, } + +#[derive(Deserialize, Clone, Debug)] +pub struct SpotAssetCtx { + pub coin: String, + pub data: SpotAssetDetails, +} diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index 1de81a82..737e1072 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -35,7 +35,7 @@ use crate::{ WebData2, }; -use super::{ActiveAssetCtx, SubscriptionError}; +use super::{ActiveAssetCtx, SpotAssetCtx, SubscriptionError}; #[derive(Debug)] struct SubscriptionData { @@ -92,9 +92,7 @@ pub enum Message { Notification(Notification), WebData2(WebData2), ActiveAssetCtx(ActiveAssetCtx), - ActiveAssetData(ActiveAssetData), - ActiveSpotAssetCtx(ActiveSpotAssetCtx), - Bbo(Bbo), + ActiveSpotAssetCtx(SpotAssetCtx), Error(SubscriptionError), Pong, } @@ -306,6 +304,12 @@ impl WsManager { }) .map_err(|e| Error::JsonParse(e.to_string())) } + Message::ActiveSpotAssetCtx(active_spot_asset_ctx) => { + serde_json::to_string(&Subscription::ActiveAssetCtx { + coin: active_spot_asset_ctx.data.coin.clone(), + }) + .map_err(|e| Error::JsonParse(e.to_string())) + } Message::Error(err) => { let error_str = err.data.to_string(); let identifier = error_str From 855aa555d0867d23c1b3c39986147981508076a6 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 17 Feb 2025 15:58:32 -0500 Subject: [PATCH 09/10] Allow posting raw action --- src/exchange/exchange_client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exchange/exchange_client.rs b/src/exchange/exchange_client.rs index 19ea9937..e2c71fed 100644 --- a/src/exchange/exchange_client.rs +++ b/src/exchange/exchange_client.rs @@ -139,7 +139,7 @@ impl ExchangeClient { }) } - async fn post( + pub async fn post( &self, action: serde_json::Value, signature: Signature, From d4f68f82aef3472d43af77ac434c1e33b60aa564 Mon Sep 17 00:00:00 2001 From: tedison Date: Tue, 3 Feb 2026 13:18:21 +0100 Subject: [PATCH 10/10] Fix compilation errors after cherry-pick rebase - Remove duplicate imports in info_client.rs - Remove ethers dependency imports - Declare eip712 module in lib.rs - Remove duplicate struct definitions in ws/sub_structs.rs - Add missing Message variants (ActiveAssetData, Bbo) - Remove unreachable match patterns in ws_manager.rs Co-authored-by: Cursor --- src/info/info_client.rs | 6 ------ src/lib.rs | 1 + src/meta.rs | 1 - src/ws/sub_structs.rs | 45 ----------------------------------------- src/ws/ws_manager.rs | 18 ++++------------- 5 files changed, 5 insertions(+), 66 deletions(-) diff --git a/src/info/info_client.rs b/src/info/info_client.rs index ca794e63..f51e2880 100644 --- a/src/info/info_client.rs +++ b/src/info/info_client.rs @@ -19,12 +19,6 @@ use crate::{ UserFundingResponse, UserTokenBalanceResponse, }; -use ethers::types::H160; -use reqwest::Client; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use tokio::sync::mpsc::UnboundedSender; - #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct CandleSnapshotRequest { diff --git a/src/lib.rs b/src/lib.rs index c7588a80..2f16e4df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![deny(unreachable_pub)] pub mod consts; +pub mod eip712; pub mod errors; pub mod exchange; pub mod helpers; diff --git a/src/meta.rs b/src/meta.rs index 4f22464f..499ccb15 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use alloy::primitives::B128; -use ethers::abi::ethereum_types::H128; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Debug, Clone)] diff --git a/src/ws/sub_structs.rs b/src/ws/sub_structs.rs index d4d73e98..4c3c94e5 100644 --- a/src/ws/sub_structs.rs +++ b/src/ws/sub_structs.rs @@ -351,48 +351,3 @@ pub struct BboData { pub time: u64, pub bbo: Vec>, } - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ActiveAssetCtxData { - pub coin: String, - pub ctx: ActiveAssetCtxEnum, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(untagged)] -pub enum ActiveAssetCtxEnum { - Perps(PerpsAssetCtx), - Spot(SpotAssetCtx), -} -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct PerpsAssetCtx { - pub day_ntl_vlm: u64, - pub prev_day_px: u64, - pub mark_px: u64, - pub mid_px: Option, - pub funding: u64, - pub open_interest: u64, - pub oracle_px: u64, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct SpotAssetDetails { - #[serde(rename = "prevDayPx")] - pub prev_day_px: String, // Ensure this matches the JSON field exactly - pub day_ntl_vlm: String, - pub mark_px: String, - pub mid_px: String, - pub circulating_supply: String, - pub coin: String, - pub total_supply: String, - pub day_base_vlm: String, -} - -#[derive(Deserialize, Clone, Debug)] -pub struct SpotAssetCtx { - pub coin: String, - pub data: SpotAssetDetails, -} diff --git a/src/ws/ws_manager.rs b/src/ws/ws_manager.rs index 737e1072..e2267a19 100755 --- a/src/ws/ws_manager.rs +++ b/src/ws/ws_manager.rs @@ -35,7 +35,7 @@ use crate::{ WebData2, }; -use super::{ActiveAssetCtx, SpotAssetCtx, SubscriptionError}; +use super::SubscriptionError; #[derive(Debug)] struct SubscriptionData { @@ -92,7 +92,9 @@ pub enum Message { Notification(Notification), WebData2(WebData2), ActiveAssetCtx(ActiveAssetCtx), - ActiveSpotAssetCtx(SpotAssetCtx), + ActiveAssetData(ActiveAssetData), + ActiveSpotAssetCtx(ActiveSpotAssetCtx), + Bbo(Bbo), Error(SubscriptionError), Pong, } @@ -298,18 +300,6 @@ impl WsManager { Message::SubscriptionResponse | Message::Pong => Ok(String::default()), Message::NoData => Ok("".to_string()), Message::HyperliquidError(err) => Ok(format!("hyperliquid error: {err:?}")), - Message::ActiveAssetCtx(active_asset_ctx) => { - serde_json::to_string(&Subscription::ActiveAssetCtx { - coin: active_asset_ctx.data.coin.clone(), - }) - .map_err(|e| Error::JsonParse(e.to_string())) - } - Message::ActiveSpotAssetCtx(active_spot_asset_ctx) => { - serde_json::to_string(&Subscription::ActiveAssetCtx { - coin: active_spot_asset_ctx.data.coin.clone(), - }) - .map_err(|e| Error::JsonParse(e.to_string())) - } Message::Error(err) => { let error_str = err.data.to_string(); let identifier = error_str