Hyperliquid raw sql
ESCAPE HATCH — arbitrary read-only SQL over the Hyperliquid data, ONLY for questions
none of the hyperliquid_* tools answers. PREFER THE SPECIALIZED TOOLS: they carry the
indexed filters and the data rules below already; ad-hoc SQL that misses them reads
billions of rows and times out. Every table below is in database hyperliquid_rt —
qualify names as hyperliquid_rt.<table>. Queries are limited to 60 seconds and 4 GB. 64-bit integers come back as JSON numbers, exact only up to 2^53: return a hash such as cityHash64(...) or any other 64-bit id as toString(x). Date-time values come back as ISO-8601 UTC, e.g. 2026-09-21T15:04:18Z (toString() of a date-time gives 2026-09-21 15:04:18).
Runs read-only ClickHouse SQL. SQL reference: https://clickhouse.com/docs/reference/home
Data rules (each one silently breaks a naive query):
- Every amount is a DECIMAL STRING (Trade_Execution_Price, _Size, Trade_Fees_Fee,
Trade_Position_RealizedPnl, Funding_Amount, …): wrap in toFloat64OrZero() or use the
*_Decimal alias columns. Block_Time is epoch NANOSECONDS (Int64) — filter as
Block_Time >= toInt64(toUnixTimestamp(now() - INTERVAL 1 DAY)) * 1000000000, never
compare it to now64() directly (decimal overflow). Trade_Execution_EventTime is ms.
- ONE FILL = TWO ROWS in trades (maker + taker), joined by (Block_Number,
Trade_Market_CoinRaw, Trade_Execution_Tid). Market volume: Trade_Execution_IsAggressor = 1
only. An account's own activity: filter Trade_Trader_Address (one row per fill).
- Tid is an identifier, not an order. Fills of one block run in Trade_Execution_Index /
Liquidation_Execution_Index order (from 1, one sequence across trades and liquidations;
0 on older rows): order by (Block_Number, *_Execution_Index, *_Execution_Tid).
- Liquidation fills live ONLY in perp_liquidations (Liquidation_* columns, same shape).
- Market kinds share every table: Trade_Market_Kind in perp | hip3 | spot | outcome;
Trade_Market_IsPerp = 1 for perp + hip3. Identity is Trade_Market_CoinRaw (BTC,
xyz:NFLX, @107, #<n>); Trade_Market_Symbol is NOT unique. The SPOT pair with the id
PURR/USDC is Kind spot, but rows not re-filed yet still read Kind perp with IsPerp = 1 -
leave it out by id when a figure must cover perpetuals only, and include it by id (once)
in a spot figure.
- Empty string means UNKNOWN, not zero: Position_EntryPrice and
Position_Size (size after the fill) on rows with Execution_Index = 0. Position_Leverage,
Position_IsCross, Market_MaxLeverage and Trader_SignedAt are NULL when not known (0 on
rows written before the processor kept them Nullable).
- Trade_Fees_FeeToken is USDC on ~96% of rows; sum fees only where IN ('USDC','').
- Raw tables are ReplacingMergeTree: add FINAL. AggregatingMergeTree tables need the
-Merge combinators (argMaxMerge(Position_Size), argMaxMerge(Mark), …); ohlc is read with
min/max/sum, Open/Close as tupleElement(min(Ohlc_Open), 3) / tupleElement(max(Ohlc_Close), 3).
- Addresses are lowercase 0x strings everywhere except signed_actions (User, Signer:
raw bytes — concat('0x', lower(hex(User)))).
- Price: latest_mark / price_updates cover ONLY HIP-3 markets. A native perp's mark =
|Funding_Amount| / (|Funding_Size| x Funding_Rate) on the latest funding block;
otherwise the last candle close.
- Outcome (prediction) markets #<n>: the trade, funding and liquidation rows carry
*_Market_Outcome_{Headline,Title,SideTitle,Side,OutcomeId,Question_QuestionId,
Question_IsFallback,Question_IsSettled} (from 2026-10-30 08:24 UTC; empty before). The
directions Split Outcome / Merge Outcome / Negate Outcome / Merge Question / Settlement are
not trades between accounts (a split or merge is one row at a fixed 0.5): leave them out of
volumes and prices. A holding of side #<n> is the spot balance of token +<n>.
Tables (key columns first; retention):
- trades (Trade_Market_CoinRaw, Trade_Trader_Address, Block_Number) ~11 M rows/day,
30 days. Trade_Trader_{Address,Signer,Vault}, Trade_Market_{Symbol,Kind,Protocol,
CoinRaw,IsPerp}, Trade_Execution_{Side,Direction,IsAggressor,Price,Size,Oid,Tid,Hash,
EventTime,Index}, Trade_Fees_{Fee,FeeToken,BuilderFee,DeployerFee}, Trade_Position_{Side,
Size,SizeBefore,RealizedPnl,Leverage,IsCross}, Trade_Builder, Trade_IsTwap, Trade_TwapId;
aliases Trade_Execution_NotionalUSD, Trade_Trader_IsAgent, Trade_Position_IsClosing,
Trade_Position_IsWin, Trade_Position_NetPnl.
- trades_5m_aggr — 5-minute roll-up per market x trader x (IsAggressor, Side, FeeToken,
IsTwap, Builder, IsAgent, IsClosing, IsWin): Trade_Count, Trade_Execution_NotionalUSD,
Trade_Execution_Size, Trade_Position_RealizedPnl, Trade_Fees_Fee, Trade_Position_NetPnl
(sums, plain columns — GROUP BY and sum()), *_Max/_Min. USE THIS for counts,
volumes, leaderboards.
- perp_liquidations (Liquidation_Market_CoinRaw, Block_Number), 30 days: same shape
as trades plus Liquidation_MarkPx, Liquidation_Method (market|backstop),
Liquidation_LiquidatedUser.
- perp_fundings (Funding_Trader_Address, Block_Number), 30 days, one row per open perp
position per hour: Funding_Market_CoinRaw, Funding_Amount (signed, + received),
Funding_Rate (hourly), Funding_Size (signed position). Sum |Funding_Size| on the
latest block per market = open interest.
- order_updates (Order_Market_CoinRaw, Order_Trader_Address, Block_Number), 7 DAYS,
~11 B rows: Order_{Side,Status,IsReject,OrderType,Tif,ReduceOnly,LimitPx,Size,OrigSz,
TriggerPx,TriggerCondition,IsTrigger,Oid,Cloid,PlacedTime,EventTime,Index}. Statuses of
one order in a block share EventTime; Order_Index (from 1; 0 on older rows) orders them.
Never read without market + trader + a short window. order_updates_10m_aggr = roll-up per market
x trader x (Status, Tif, IsReject, OrderType, Side, ReduceOnly) with Order_Count.
- book_updates (BookUpdate_Market_CoinRaw, Block_Number), 7 days, ~8 B rows, per-order
book deltas with the OWNER (BookUpdate_Trader_Address, Oid, Side, Px, Kind new|update|
remove, Size, SizeBefore, Index). Same warning.
- twaps (Twap_Market_CoinRaw, Block_Number), 30 days: Twap_TwapId, Twap_Trader_Address,
Twap_Order_{Side,Size,ReduceOnly,Randomize}, Twap_Interval_{StartTime(ms),
DurationMinutes}, Twap_State_{Status,StatusError,ExecutedSize,ExecutedNotional}.
- price_updates (PriceUpdate_Market_CoinRaw, Block_Number), 30 days, HIP-3 only:
PriceUpdate_{Price,Kind(mark|oracle|extPerp|markInput|spotInput|extPerpInput),
UpdateClass,DailyPx,UpdateTime}. latest_mark = argMaxMerge(Mark) per Market_CoinRaw.
- ohlc (Market_Symbol, Interval_Time_Duration 60|300|900|3600, Interval_Time_Start,
Market_CoinRaw): Ohlc_Open / Ohlc_Close are (Block, Index, Price) of the first / last fill —
tupleElement(min(Ohlc_Open), 3), tupleElement(max(Ohlc_Close), 3); Ohlc_High (max),
Ohlc_Low (min), Ohlc_Volume (sum, taker side).
- current_positions (Trader_Address, Market_CoinRaw): argMaxMerge(Position_Size) (string,
signed), argMaxMerge(Position_Leverage) and argMaxMerge(Position_IsCross) (one-element
tuples, (20) / (1), (NULL) when not known; a plain number on a host not migrated yet),
sum(Position_RealizedPnl), sum(Position_Funding), max(LastTime) (any event, funding
included), max(LastTradeTime) (the last fill; 0 = none). Size includes the hourly
funding restatement (none in an hour of zero rate), so a perp size is exact even for a
position older than the data.
- trader_leverage_updates (LeverageUpdate_Trader_Address, Block_Number): accepted leverage
changes — LeverageUpdate_Market_CoinRaw, LeverageUpdate_Leverage, LeverageUpdate_IsCross.
- signed_actions (Block_Number, Bundle_Index, Bundle_ActionIndex), 7 days: what accounts
ASKED the exchange, incl. REJECTED actions (Status = 'err', reason in Response) and
the recovered Signer; only rejects and non-order action types are kept (User,
ActionType, Status, Action, Response raw JSON, Nonce, VaultAddress, Bundle_Hash).
- cluster_labels (node, label) / cluster_edges (src, dst) — the account—agent graph
behind hyperliquid_linked_accounts; operator_clusters view = (ClusterId, Account).
- State snapshots, 7 days, one about every 12 minutes: the whole state of every account.
Read ONLY complete ones, the height from the view in the SAME statement —
WITH (SELECT max(Block_Number) FROM hyperliquid_rt.snapshots WHERE IsComplete) AS h —
and always FINAL with Block_Number = h (or IN the complete heights). Tables by key:
snapshot_markets (Market_CoinRaw, Block_Number): OpenInterest (longs + shorts in coins,
twice one side), Prices_MarkPx, Book_BestBid / BestAsk / LastTradePx, Positions,
Market_Outcome_* (never the old Outcome_* columns); snapshot_positions (Market_CoinRaw,
Block_Number, Trader_Address) and snapshot_positions_by_trader: Position_Size (negative =
short), Position_EntryPrice, Position_Leverage, Position_IsCross,
Valuation_PositionValue / UnrealizedPnl, CumFunding_SinceOpen (positive = paid);
snapshot_orders (Market_CoinRaw, Block_Number, Oid) and _by_trader: resting orders
(IsTrigger = 0, QueuePosition) and pending stops (IsTrigger = 1, TriggerPx;
IsPositionTpsl = 1 has Size 0); snapshot_balances (Token, Block_Number, Trader_Address)
and _by_trader: Total, Hold, EntryNotional; snapshot_accounts (Trader_Address, Protocol,
Block_Number); snapshot_vaults, snapshot_vault_followers (Vault, …) and _by_trader;
snapshot_leverage_settings (Trader_Address, Market_CoinRaw, …) — read it by trader;
snapshot_earn_reserves / snapshot_earn_positions. ~2.5 M balances, ~640 K orders and
~410 K positions per snapshot against a 100,000-row result cap: aggregate or LIMIT.
Block_Time there is epoch ns too.
Always add a Block_Time bound and a LIMIT.