ESCAPE HATCH — read-only SQL for what NO tool answers: custom cohort backtests beyond launch_cohort, multi-step joins, quantiles. Check the tools first; they are keyed and far cheaper:
- token_price, token_ohlcv, pair_ohlcv, currency_ohlcv, token_trade_bars (30 s to 1 h buy/sell bars)
- new_tokens, launch_cohort, token_launch_stats, early_buyers, token_dex_venues, pool_recent_trades
- trader_trades, trader_profile, trader_positions, trader_activity, top_traders_by_token
- list_tables, describe_table, search_columns before writing a query
- Hyperliquid (the perp exchange) is NOT in this database at all: its markets, funding, liquidations and traders are the hyperliquid_* tools, and its own hatch is hyperliquid_raw_sql
After a tool answers, keep going with tools; use SQL only for the step none can do.
Runs read-only ClickHouse SQL. SQL reference: https://clickhouse.com/docs/reference/home
Scope: only the trading_rt database — DEX trades and 1 s to 1 h bars per token, pair, pool and currency, last ~30 days, 10 chains. Other visible databases are internal and unsupported: do not query them. Address labels and per-chain transfers are not here: use the label and <chain>_ tools.
Rules:
- Names are case-sensitive, not GraphQL fields or tool output names: trades_* use Pair_Token_Address / Pair_Token_Network / Pair_Token_Symbol (quote side Pair_QuoteToken_*), tokens_* and pairs_* Token_*; confirm with describe_table.
- Use the *_by_<key> table that matches your filter, filter its leading sort keys, and on trades_* bound Block_Date too.
- Bars: Interval_VolumeBased = 0; Price_IsQuotedInUsd = 1 for USD.
- Windows on *_by_interval_start: enumerate the hour starts, Interval_Time_Start IN (SELECT arrayJoin(arrayMap(h -> toStartOfHour(now()) - toIntervalHour(h), range(24)))) AND Interval_Time_Duration = 3600; a >= range reads every duration.
- One tokens_* hour can be stored twice: on multi-token scans add Token_Did = '' (never on a single-address lookup); take the current and previous hour as argMax(Volume_Usd, Indexing_Time) per token; never GROUP BY Token_Name / Token_Symbol.
- Amounts are decimal-adjusted; USD: AmountsInUsd_Base / AmountsInUsd_Quote / PriceInUsd; Side = what the trader received; Supply_MarketCap = the diluted value when Supply_CirculatingSupply = 0.
- EVM addresses are lowercase 0x-hex, Solana/Tron base58 case-sensitive. Use UNION ALL; always add a LIMIT. Dates and times come back as ISO-8601 UTC (a Date as T00:00:00Z).