View Source Hyperliquid.Utils (hyperliquid v0.2.2)
Provides utility functions for the Hyperliquid application.
This module offers a collection of helper functions that are used across the Hyperliquid application. It includes utilities for data manipulation, PubSub operations, number formatting, random ID generation, and hexadecimal conversions.
Key Features
- Atomize keys in data structures
- PubSub subscription and broadcasting
- Number to string conversions with special float handling
- Random client order ID (cloid) generation
- Hexadecimal string manipulations
- Timestamp generation
Summary
Functions
Utils for converting map keys to atoms.
Convert a non-negative integer to a 0x-prefixed lowercase hex string.
Convert snake_case string to camelCase.
Convert struct/map to camelCase map recursively (for JSONB storage).
Convert a hex string (0x-prefixed) to an integer. Pass-through for integers and nil.
Functions
Utils for converting map keys to atoms.
@spec from_int(non_neg_integer()) :: String.t()
Convert a non-negative integer to a 0x-prefixed lowercase hex string.
Convert snake_case string to camelCase.
Examples
iex> Hyperliquid.Utils.snake_to_camel("account_value")
"accountValue"
iex> Hyperliquid.Utils.snake_to_camel("total_ntl_pos")
"totalNtlPos"
Convert struct/map to camelCase map recursively (for JSONB storage).
Drops internal Ecto fields like :meta and :id.
Examples
iex> Hyperliquid.Utils.to_camel_case_map(%{account_value: "100", total_ntl_pos: "50"})
%{"accountValue" => "100", "totalNtlPos" => "50"}
Convert a hex string (0x-prefixed) to an integer. Pass-through for integers and nil.