TypeScript and Python SDKs
One client per language for every endpoint: retries, rate limits, pagination, the live stream and typed errors built in. Zero dependencies in both.
Install
Node 18+, Deno, Bun and edge runtimes for TypeScript and JavaScript; Python 3.9+ with the standard library.
npm install blockmetric- TypeScript and JavaScript: blockmetric on npm, ESM and CommonJS, types generated from the OpenAPI document, the CLI included (
npx blockmetric --help). - Python: blockmetric on PyPI, fully typed (TypedDicts), optional pandas frames with
pip install "blockmetric[pandas]". - AI assistants: the MCP server blockmetric-mcp on npm, set up in Connect an assistant.
Version on npm and PyPI: 0.7.0. Parts marked “from 0.7.2” arrive with the next release; until then the same data comes from the REST endpoints with any HTTP client. Both SDKs share one version line and follow semantic versioning.
A request without a key
Without a key the client uses keyless access and prints one hint that says so.
import { Blockmetric } from 'blockmetric'
const client = new Blockmetric() // no key set: keyless access
const { data, meta } = await client.liquidationSummary({ hours: 24 })
console.log(data.totalUsd, data.longUsd, data.shortUsd, meta.updatedAt)Without a key: a trial of 25 requests a day per IP address (10 a minute), 24 h of history; after it the API answers 401 key_required. The client paces itself to 9 a minute, stops pages() after 5 pages and lets follow() poll every 60 seconds. A free key gives 60 a minute, 1,000 a day and 30 days of history: get a free key.
Client with a key
Set BLOCKMETRIC_API_KEY once; nothing else changes in the code. A key always wins over keyless access.
// export BLOCKMETRIC_API_KEY=bm_live_...
import { Blockmetric } from 'blockmetric'
// publicAccess: false = a missing key fails loudly instead of falling back to keyless access
const client = new Blockmetric({ publicAccess: false, timeoutMs: 15_000, maxRetries: 3 })
const res = await client.markets({ venue: 'hyperliquid' })
console.log(res.data.length, res.lastResponse.rateLimit.remaining, res.lastResponse.requestId)Retries with exponential backoff and jitter on 429, 5xx, timeouts and network errors, honouring Retry-After; a 4xx other than 429 is never retried. The rate-limit headers and the request id of every answer sit on lastResponse / last_response. Keep keys on servers; a browser can use keyless access.
Methods
One method per endpoint, named after it: liquidationSummary() in TypeScript, liquidation_summary() in Python.
// Path parameters first, then the query parameters as one object
const heat = await client.heatmap('BTC', { tf: '15m', hours: 24 })
const candles = await client.candles('ETH', { tf: '1h', limit: 48 })
const wallet = await client.wallet('0x5b5d51203a0f9079f8aeb098a6523a13f298c060')
// Any GET path of the API, with the same retries and limits
const raw = await client.request('/funding?coin=BTC')Every endpoint page of this reference names its method (for example GET /heatmap/{coin}: heatmap()). Each method resolves to the API envelope { data, meta }; units are the API’s (money in USD, times ISO 8601 UTC, rates as fractions).
Pagination and new items
paginate() walks a window page by page; follow() polls a feed and yields every new item once.
// Every item of a window, page by page (follows meta.nextCursor)
for await (const liq of client.paginate('liquidations', { coin: 'BTC', from: '2026-11-28', limit: 1000 })) {
console.log(liq.ts, liq.venue, liq.side, liq.usd)
}
// New items as they arrive, oldest first, each one once (any key, also without one)
for await (const liq of client.follow('liquidations', { minUsd: 100_000 }, { intervalMs: 15_000 })) {
console.log('big liquidation', liq.coin, liq.side, liq.usd)
}follow() works with every key and without one, for liquidations, the whale feed, radar events, the tape and movements. More on cursors and polling: Pagination & caching.
Live prices
prices() returns the latest trade of every Hyperliquid market with its time and age; livePrices() keeps that state up to date from the stream.
// The latest trade of every Hyperliquid market (every key and keyless)
const { data } = await client.prices({ coin: ['BTC', 'ETH'] })
for (const p of data) console.log(p.coin, p.price, p.ts, p.ageSec, p.stale)
// API Pro: the whole state, pushed once a second over the stream
for await (const s of client.livePrices({ coin: ['BTC', 'ETH'] })) console.log(s.feed, s.prices.BTC?.price, s.changed.length)Live stream
API Pro: Server-Sent Events with auto-reconnect, Last-Event-ID resume and a heartbeat watchdog.
// API Pro: every single liquidation of at least $100k as it is stored
for await (const f of client.stream({ channel: 'liquidations', minUsd: 100_000 })) {
console.log(f.data.venue, f.data.coin, f.data.side, f.data.usd, f.data.feed)
}
// Radar events (the default channel), resumed with Last-Event-ID after a drop
for await (const e of client.stream({ kinds: ['big_liquidation', 'liq_cascade'], minSeverity: 2 })) console.log(e.type, e.data.title)Large trades as they are stored
// API Pro: large taker buys of BTC and ETH, the GET /tape rows live
for await (const f of client.stream({ channel: 'tape', coin: ['BTC', 'ETH'], side: 'buy' })) {
console.log(f.data.coin, f.data.px, f.data.usd, f.data.whale)
}Channels, freshness and resume rules: Live event stream. Without API Pro, follow() gives events, liquidations and the tape by polling.
Typed errors
Every failure is a BlockmetricError with code, status, param, request id and doc link; the subclass says what kind it is.
import { BlockmetricError, PlanRequiredError, RateLimitError } from 'blockmetric'
try {
await client.heatmap('BTC', { tf: '1m' })
} catch (e) {
if (e instanceof RateLimitError) console.error('slow down for', e.retryAfter, 's')
else if (e instanceof PlanRequiredError) console.error('needs a higher plan:', e.message)
else if (e instanceof BlockmetricError) console.error(e.code, e.status, e.param, e.requestId, e.docUrl)
}Classes: InvalidParamError, AuthenticationError, PermissionDeniedError, PlanRequiredError, NotFoundError, RateLimitError, ServerError and NetworkError. Every code with its fix: Errors.
Types
TypeScript types and Python TypedDicts are generated from the OpenAPI document, so field names and units match the reference.
import type { Liquidation, LiquidationSummaryResponse } from 'blockmetric'
const summary: LiquidationSummaryResponse = await client.liquidationSummary({ coin: "ETH" })
const big = (rows: Liquidation[]) => rows.filter((l) => (l.usd ?? 0) >= 1_000_000)Parallel calls
Independent calls can run at the same time; mind the per-minute limit of your key.
// Every method returns a Promise: run independent calls together
const [summary, heat] = await Promise.all([
client.liquidationSummary({ hours: 24 }),
client.heatmap('BTC', { tf: '15m' }),
])
console.log(summary.data.totalUsd, heat.data.times.length)Webhook signatures
API Dev and API Pro: verify the signature of every delivery in constant time before you use it.
import { constructEvent } from 'blockmetric/webhooks'
// rawBody: the exact bytes received, never re-serialised JSON
const event = await constructEvent(rawBody, req.headers['blockmetric-signature'], process.env.BLOCKMETRIC_WEBHOOK_SECRET!)
console.log(event.id, event.type) // deduplicate on event.idAnswer with a 2xx within 10 seconds and deduplicate on the event id: Webhooks.
Versions
Within /v1 the API adds endpoints, parameters and fields and removes none, so an older SDK keeps working.
Each release is generated against one API version and sends it in its User-Agent; lastResponse.apiVersion / last_response.api_version shows the version that answered, and a deprecated parameter answers with a Deprecation header. API changes: Changelog. Package releases: npm and PyPI.
Code snippets in these docs are licensed under MIT-0: copy them into your own code without attribution. The SDKs, CLI and MCP server are Apache-2.0; the name Blockmetric is not licensed (forks must be renamed). Data from the API is governed by the API terms; third-party exchange data by the exchange’s terms.