View Source Hyperliquid.Config (hyperliquid v0.2.2)
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 the explorer (RPC) ws URL of the API.
Returns the private key.
Returns the stats URL of the API.
Returns whether Phoenix/LiveView web features are enabled.
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: falseUsage
# 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_000Usage
Hyperliquid.Config.cache_default_ttl()
# => 300_000
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_000Usage
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_000Usage
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: 5Usage
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_000Usage
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_000Usage
Hyperliquid.Config.cache_mids_ttl()
# => 60_000
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.15Usage
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_000Usage
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: trueRequired 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 the explorer (RPC) ws URL of the API.
Returns the private key.
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: trueUsage
# Check if web features are enabled
Hyperliquid.Config.web_enabled?()
# => false
# Enable in config
config :hyperliquid, enable_web: true
Returns the ws URL of the API.