View Source Hyperliquid.Config (hyperliquid v0.4.1)

Configuration module for Hyperliquid application.

Summary

Functions

Returns the base URL of the API.

Returns whether to automatically initialize the cache on application startup.

Returns the bridge contract address, used for deposits.

Returns the default TTL for cache entries in milliseconds.

Returns the interval for the cache janitor in milliseconds.

Returns the maximum number of cache entries before eviction.

Returns the maximum number of cache initialization retry attempts.

Returns the TTL for metadata cache entries in milliseconds.

Returns the TTL for all_mids cache entries in milliseconds.

Returns the fraction of entries to evict when size limit is reached.

Returns the delay in milliseconds between cache initialization retries.

Returns the selected chain. Defaults to :mainnet.

Returns the per-chain configuration map for the selected chain.

Returns whether database persistence is enabled.

Returns whether debug logging is enabled. Defaults to false. Controlled via config :hyperliquid, debug: true/false or HL_DEBUG env var.

Optional expiresAfter timestamp in milliseconds. When set, L1 actions will be rejected after this time. User-signed actions (e.g., usdSend/spotSend/withdraw3) must not include expiresAfter.

Returns the explorer HTTP URL.

Returns whether the application is running on mainnet.

Returns the named RPC endpoints configuration.

Returns whether the local node Info API is enabled.

Returns whether the local node EVM RPC is enabled.

Returns the URL for a local Hyperliquid node.

Returns the explorer (RPC) ws URL of the API.

Returns the private key.

Returns the chain id used in the EIP-712 domain when signing user-signed actions, as an integer.

Returns signature_chain_id/0 as the lowercase hex string used for the signatureChainId field (e.g. "0xa4b1").

Returns the stats URL of the API.

Returns whether Phoenix/LiveView web features are enabled.

Returns the maximum number of simultaneous WebSocket connections.

Returns the maximum number of new WebSocket connections allowed per minute.

Returns the maximum number of simultaneous WebSocket subscriptions.

Returns the maximum number of unique users allowed across user-specific WebSocket subscriptions.

Returns the ws URL of the API.

Functions

Returns the base URL of the API.

Returns whether to automatically initialize the cache on application startup.

When true (default), the cache will be populated with exchange metadata and mid prices when the application starts. Set to false to manually control cache initialization.

Configuration

config :hyperliquid,
  autostart_cache: false

Usage

# Check if cache should autostart
Hyperliquid.Config.autostart_cache?()
# => true

# Disable in config for manual control
config :hyperliquid, autostart_cache: false

Returns the bridge contract address, used for deposits.

Returns the default TTL for cache entries in milliseconds.

This is the fallback TTL used when no specific TTL is provided. Defaults to 300,000ms (5 minutes).

Configuration

config :hyperliquid,
  cache_default_ttl: 600_000

Usage

Hyperliquid.Config.cache_default_ttl()
# => 300_000
Link to this function

cache_janitor_interval()

View Source

Returns the interval for the cache janitor in milliseconds.

The janitor periodically cleans expired entries. Defaults to 60,000ms (60 seconds).

Configuration

config :hyperliquid,
  cache_janitor_interval: 120_000

Usage

Hyperliquid.Config.cache_janitor_interval()
# => 60_000

Returns the maximum number of cache entries before eviction.

When this limit is reached, LRW (Least Recently Written) eviction removes old entries. Defaults to 5000 entries.

Configuration

config :hyperliquid,
  cache_max_entries: 10_000

Usage

Hyperliquid.Config.cache_max_entries()
# => 5000

Returns the maximum number of cache initialization retry attempts.

Defaults to 3 retries. After max retries are exceeded, the application continues in degraded mode without cached data.

Configuration

config :hyperliquid,
  cache_max_retries: 5

Usage

Hyperliquid.Config.cache_max_retries()
# => 3

Returns the TTL for metadata cache entries in milliseconds.

Metadata (perp_meta, spot_meta) changes less frequently than prices. Defaults to 600,000ms (10 minutes).

Configuration

config :hyperliquid,
  cache_meta_ttl: 900_000

Usage

Hyperliquid.Config.cache_meta_ttl()
# => 600_000

Returns the TTL for all_mids cache entries in milliseconds.

Mid prices change frequently, so this TTL is shorter than the default. Defaults to 60,000ms (1 minute).

Configuration

config :hyperliquid,
  cache_mids_ttl: 30_000

Usage

Hyperliquid.Config.cache_mids_ttl()
# => 60_000
Link to this function

cache_reclaim_fraction()

View Source

Returns the fraction of entries to evict when size limit is reached.

A value of 0.1 means 10% of entries are evicted, creating a buffer to prevent constant eviction thrashing. Defaults to 0.1 (10%).

Configuration

config :hyperliquid,
  cache_reclaim_fraction: 0.15

Usage

Hyperliquid.Config.cache_reclaim_fraction()
# => 0.1

Returns the delay in milliseconds between cache initialization retries.

Defaults to 5000ms (5 seconds). Used by Cache.Warmer when initial cache population fails.

Configuration

config :hyperliquid,
  cache_retry_delay: 10_000

Usage

Hyperliquid.Config.cache_retry_delay()
# => 5000

Returns the selected chain. Defaults to :mainnet.

This is controlled by config :hyperliquid, :chain.

Returns the per-chain configuration map for the selected chain.

Expected structure in your config/config.exs:

config :hyperliquid,
  chain: :mainnet,
  chains: %{
    mainnet: %{http_url: ..., ws_url: ..., rpc_url: ..., rpc_ws_url: ..., stats_url: ...},
    testnet: %{...}
  }

Per-key overrides under :hyperliquid (e.g. :http_url, :ws_url) take precedence over this map.

Returns whether database persistence is enabled.

When true, the application will start Hyperliquid.Repo and Hyperliquid.Storage.Writer, enabling Postgres persistence for API data. When false (default), only Cachex storage is available.

Configuration

config :hyperliquid,
  enable_db: true

Required Dependencies

When enabling database features, ensure these dependencies are available:

  • phoenix_ecto
  • ecto_sql
  • postgrex

Usage

# Check if database is enabled
Hyperliquid.Config.db_enabled?()
# => false

# Enable in config
config :hyperliquid, enable_db: true

Returns whether debug logging is enabled. Defaults to false. Controlled via config :hyperliquid, debug: true/false or HL_DEBUG env var.

Optional expiresAfter timestamp in milliseconds. When set, L1 actions will be rejected after this time. User-signed actions (e.g., usdSend/spotSend/withdraw3) must not include expiresAfter.

Returns the explorer HTTP URL.

Used for block_details, user_details, and tx_details endpoints.

Returns whether the application is running on mainnet.

Returns the named RPC endpoints configuration.

Named RPCs allow you to register multiple RPC endpoints and reference them by name. This is useful when you want to switch between different RPC providers (e.g., Alchemy, QuickNode, local nodes).

Configuration

Expected structure in your config/config.exs:

config :hyperliquid,
  named_rpcs: %{
    alchemy: "https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY",
    quicknode: "https://your-endpoint.quiknode.pro/YOUR_KEY",
    infura: "https://arbitrum-mainnet.infura.io/v3/YOUR_KEY",
    local: "http://localhost:8545",
    backup: "https://rpc-backup.hyperliquid.xyz/evm"
  }

Usage

# Use a named RPC in your calls
Hyperliquid.Rpc.Eth.block_number(rpc_name: :alchemy)

# Or register new ones at runtime
Hyperliquid.Rpc.Registry.register(:my_node, "https://my-node.xyz")

Returns whether the local node Info API is enabled.

When true, Hyperliquid.Node convenience functions will send requests to node_url()/info. The node must be running with --serve-info.

Defaults to false.

Configuration

config :hyperliquid,
  enable_node_info: true

Returns whether the local node EVM RPC is enabled.

When true, the application registers a :node named RPC pointing to node_url()/evm in the RPC Registry at startup. This allows using rpc_name: :node in RPC calls.

Defaults to false.

Configuration

config :hyperliquid,
  enable_node_rpc: true

Returns the URL for a local Hyperliquid node.

Local nodes can serve EVM JSON-RPC (/evm) and Info API (/info) endpoints when started with --serve-eth-rpc and --serve-info flags.

Defaults to http://localhost:3001.

Configuration

config :hyperliquid,
  node_url: "http://localhost:3001"

Returns the explorer (RPC) ws URL of the API.

Returns the private key.

@spec signature_chain_id() :: non_neg_integer()

Returns the chain id used in the EIP-712 domain when signing user-signed actions, as an integer.

This value has to appear in two places that must always agree: the chainId of the EIP-712 domain the signature is produced over, and the signatureChainId field sent in the action body. The exchange rebuilds the domain from signatureChainId to recover the signer, so if the two drift the API recovers the wrong address and rejects the action. Reading both from here is what keeps them in step — they were previously hardcoded in the Rust NIF and in a dozen Elixir modules independently.

The value itself is not constrained by the exchange; any chain id works as long as both sides use the same one. The default is 421_614 ("0x66eee", Arbitrum Sepolia), matching the official Python SDK and the nktkas TypeScript SDK, so signatures produced here are byte-comparable with theirs.

Override with config :hyperliquid, signature_chain_id: 42_161.

Link to this function

signature_chain_id_hex()

View Source
@spec signature_chain_id_hex() :: String.t()

Returns signature_chain_id/0 as the lowercase hex string used for the signatureChainId field (e.g. "0xa4b1").

Returns the stats URL of the API.

Returns whether Phoenix/LiveView web features are enabled.

When true, web-specific features like Phoenix controllers and LiveView components will be available. This is a future feature flag.

Configuration

config :hyperliquid,
  enable_web: true

Usage

# Check if web features are enabled
Hyperliquid.Config.web_enabled?()
# => false

# Enable in config
config :hyperliquid, enable_web: true

Returns the maximum number of simultaneous WebSocket connections.

Hyperliquid enforces a limit of 10 concurrent WebSocket connections per client. The manager will return {:error, :connection_limit_exceeded} when this is reached.

Configuration

config :hyperliquid,
  ws_max_connections: 10
Link to this function

ws_max_connections_per_minute()

View Source

Returns the maximum number of new WebSocket connections allowed per minute.

Hyperliquid enforces a rate limit of 30 new connections per minute per client. The manager will return {:error, :connection_rate_exceeded} when this is reached.

Configuration

config :hyperliquid,
  ws_max_connections_per_minute: 30

Returns the maximum number of simultaneous WebSocket subscriptions.

Hyperliquid enforces a limit of 1000 concurrent subscriptions per client. The manager will return {:error, :subscription_limit_exceeded} when this is reached.

Configuration

config :hyperliquid,
  ws_max_subscriptions: 1000

Returns the maximum number of unique users allowed across user-specific WebSocket subscriptions.

Hyperliquid enforces a limit of 10 unique users across all user-grouped subscriptions (e.g., userFills, userFundings, orderUpdates). The manager will return {:error, :user_limit_exceeded} when subscribing would exceed this limit.

Configuration

config :hyperliquid,
  ws_max_users: 10

Returns the ws URL of the API.