hl-types
Shared domain types for the motosan-hyperliquid SDK — orders, positions, candles, errors, signatures, and parsing helpers.
Overview
hl-types is the foundation crate for the workspace. It defines Rust structs/enums that map to Hyperliquid API data and provides the unified HlError type.
This crate has no network dependencies.
Key Types
Market Data
HlCandle— OHLCV candle.HlOrderbook— L2 orderbook snapshot.HlAssetInfo— asset metadata.HlFundingRate— current funding rate and next funding time.TradeSide— trade side used in parsed market/account responses.
Account
HlAccountState— equity, available margin, positions.HlPosition— position size, entry, unrealized PnL, leverage, liquidation price.HlFill— fill price/size/side/fee/closed PnL.HlOpenOrder— basic open order.HlFrontendOpenOrder— richer frontend open-order view with trigger / TP-SL metadata and children.HlOrderDetail/HlHistoricalOrder— order status views.HlVaultSummary,HlVaultDetails,HlUserFees,HlUserFundingEntry,HlStakingDelegation, etc.
Orders
OrderWire— wire format for submitting orders.OrderWireBuilder— validates positive price/size atbuild().OrderTypeWire— limit or trigger order type.Tif—Gtc,Ioc,Alo.Tpsl—Sl,Tp.Side—Buy/Sell, withSide::from_is_buy.Grouping—Na,NormalTpsl,PositionTpslfor bulk order grouping / TP-SL brackets.OrderResponse,OrderStatus— parsed execution response.CancelRequest,CancelByCloidRequest,ModifyRequest— batch action request structs.
Signing
Signature— ECDSA signature split intor,s, andv.
Errors
HlError is the unified error enum. Retry helpers:
is_retryable()— true for transport failures, timeouts, WebSocket errors, 429, and HTTP 5xx.retry_after_ms()— populated forRateLimited.
Usage
use ;
use Decimal;
let order = limit_buy
.tif
.build?;
let grouping = NormalTpsl;
assert_eq!;
let err = RateLimited ;
assert!;
assert_eq!;
# Ok::
Utility Functions
normalize_coin(coin)— strips-PERP,-USDC,-USDsuffixes and uppercases ("BTC-PERP"→"BTC").parse_mid_price_from_l2book(value)— parse mid price from anl2BookJSON response.parse_position_szi(value, coin)— parse signed position size/side for close helpers.
License
MIT