Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
75 changes: 75 additions & 0 deletions crates/adapters/hyperliquid/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,78 @@ impl HyperliquidDataClientConfig {
.unwrap_or_else(|| info_url(self.is_testnet).to_string())
}
}

/// Configuration for the Hyperliquid execution client.
#[derive(Clone, Debug)]
pub struct HyperliquidExecClientConfig {
/// Private key for signing transactions (required for execution).
pub private_key: String,
/// Optional vault address for vault operations.
pub vault_address: Option<String>,
/// Override for the WebSocket URL.
pub base_url_ws: Option<String>,
/// Override for the HTTP info URL.
pub base_url_http: Option<String>,
/// Override for the exchange API URL.
pub base_url_exchange: Option<String>,
/// When true the client will use Hyperliquid testnet endpoints.
pub is_testnet: bool,
/// HTTP timeout in seconds.
pub http_timeout_secs: u64,
/// Maximum number of retry attempts for HTTP requests.
pub max_retries: u32,
/// Initial retry delay in milliseconds.
pub retry_delay_initial_ms: u64,
/// Maximum retry delay in milliseconds.
pub retry_delay_max_ms: u64,
}

impl Default for HyperliquidExecClientConfig {
fn default() -> Self {
Self {
private_key: String::new(),
vault_address: None,
base_url_ws: None,
base_url_http: None,
base_url_exchange: None,
is_testnet: false,
http_timeout_secs: 60,
max_retries: 3,
retry_delay_initial_ms: 100,
retry_delay_max_ms: 5000,
}
}
}

impl HyperliquidExecClientConfig {
/// Creates a new configuration with the provided private key.
#[must_use]
pub fn new(private_key: String) -> Self {
Self {
private_key,
..Self::default()
}
}

/// Returns `true` when private key is populated.
#[must_use]
pub fn has_credentials(&self) -> bool {
!self.private_key.is_empty()
}

/// Returns the WebSocket URL, respecting the testnet flag and overrides.
#[must_use]
pub fn ws_url(&self) -> String {
self.base_url_ws
.clone()
.unwrap_or_else(|| ws_url(self.is_testnet).to_string())
}

/// Returns the HTTP info URL, respecting the testnet flag and overrides.
#[must_use]
pub fn http_url(&self) -> String {
self.base_url_http
.clone()
.unwrap_or_else(|| info_url(self.is_testnet).to_string())
}
}
Loading
Loading