Skip to main content

hl_getBatchBlocks

Return fill blocks in a [from, to] range for a given stream.

When to Use This Method#

hl_getBatchBlocks is essential for:

  • Backfilling — Retrieve historical fill data in bulk
  • Batch Processing — Process trade events in ordered block ranges
  • Analytics Pipelines — Feed fill data into downstream systems
  • Reconciliation — Verify trade execution across block ranges

Request#

Endpoint#

POST https://api-hyperliquid-mainnet-jsonrpc.n.dwellir.com/<API-KEY>/hypercore

Headers#

HeaderValueRequired
Content-Typeapplication/jsonYes

Parameters#

FieldTypeRequiredDescription
streamstringYesData stream. Must be "trades"
fromintegerYesFirst block number (inclusive, must be > 0)
tointegerYesLast block number (inclusive, must be >= from)

The range is capped at 100 blocks per request by default.

Example Request#

{
"jsonrpc": "2.0",
"method": "hl_getBatchBlocks",
"params": { "stream": "trades", "from": 907626062, "to": 907626064 },
"id": 1
}

Response#

Success Response#

{
"jsonrpc": "2.0",
"result": {
"blocks": [
{
"local_time": "2026-02-27T09:58:16.738110784",
"block_time": "2026-02-27T09:58:16.410825222",
"block_number": 907626062,
"events": [
[
"0x9f9a72b449783e6a7e9afca2efa49a6b77793555",
{
"coin": "ETH",
"px": "2010.8",
"sz": "0.02",
"side": "B",
"time": 1772186296410,
"startPosition": "0.0543",
"dir": "Open Long",
"closedPnl": "0.0",
"hash": "0x92bca362a1e7aad59436043619464e0203a000483ceac9a736854eb560eb84c0",
"oid": 331832891533,
"crossed": false,
"fee": "0.005791",
"tid": 379919209298471,
"feeToken": "USDC",
"twapId": null
}
],
[
"0xf8ae6942b61c6cd0333d174244f2be138626a89e",
{
"coin": "ETH",
"px": "2010.8",
"sz": "0.02",
"side": "A",
"time": 1772186296410,
"startPosition": "0.0",
"dir": "Open Short",
"closedPnl": "0.0",
"hash": "0x92bca362a1e7aad59436043619464e0203a000483ceac9a736854eb560eb84c0",
"oid": 331834694017,
"crossed": true,
"fee": "0.017373",
"tid": 379919209298471,
"feeToken": "USDC",
"twapId": null
}
]
]
},
{
"local_time": "2026-02-27T09:58:16.935172042",
"block_time": "2026-02-27T09:58:16.511724597",
"block_number": 907626064,
"events": []
}
]
},
"id": 1
}

Response Fields#

FieldTypeDescription
blocksarrayArray of block objects in the requested range

Block Object#

FieldTypeDescription
block_numberintegerBlock number (height)
block_timestringISO-8601 timestamp from the upstream source
local_timestringISO-8601 timestamp when the block was received locally
eventsarrayArray of fill events in this block (may be empty)

Fill Event#

Each event is a two-element array: [address, fill], where address is the trader's hex address and fill is an object with the following fields:

FieldTypeDescription
coinstringAsset symbol (e.g. "ETH", "HYPE", "xyz:XYZ100")
pxstringExecution price
szstringFill size
sidestring"B" (buy) or "A" (sell/ask)
timeintegerUnix timestamp in milliseconds
startPositionstringPosition size before this fill
dirstringTrade direction (e.g. "Open Long", "Open Short", "Close Long", "Close Short")
closedPnlstringRealized PnL from this fill
hashstringTransaction hash
oidintegerOrder ID
crossedbooleanWhether the order crossed the spread (taker)
feestringFee charged (negative means rebate)
tidintegerTrade ID
feeTokenstringToken used for fee payment (e.g. "USDC")
twapIdinteger | nullTWAP order ID, if applicable
cloidstringClient order ID (optional, present when set by the trader)

Error Response#

{
"jsonrpc": "2.0",
"error": { "code": -32602, "message": "from must be > 0" },
"id": 1
}

Code Examples#

curl -s https://api-hyperliquid-mainnet-jsonrpc.n.dwellir.com/<API-KEY>/hypercore \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "hl_getBatchBlocks",
"params": { "stream": "trades", "from": 907626062, "to": 907626064 },
"id": 1
}' | jq .

Common Use Cases#

1. Sequential Backfill#

Fetch all blocks from a known starting point to the latest:

async function backfill(startBlock) {
const response = await fetch(ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'hl_getLatestBlockNumber',
params: ['trades'],
id: 1
})
});
const { result: latestBlock } = await response.json();

let current = startBlock;
while (current <= latestBlock) {
const to = Math.min(current + 99, latestBlock);
const blocks = await getBatchBlocks(current, to);
console.log(`Fetched blocks ${current}${to}: ${blocks.length} blocks`);

for (const block of blocks) {
// Process each block
}

current = to + 1;
}
}

2. Event Counting#

Count fill events across a block range:

def count_events(from_block: int, to_block: int) -> dict:
blocks = get_batch_blocks(from_block, to_block)

total_events = 0
for block in blocks:
total_events += len(block['events'])

return {
'block_range': f"{from_block}{to_block}",
'blocks_returned': len(blocks),
'total_events': total_events
}

Error Handling#

Error CodeCauseSolution
-32602from must be > 0Ensure from is a positive integer
-32602to must be >= fromEnsure to is greater than or equal to from
-32602Range exceeds max batch sizeReduce the range to 100 blocks or fewer
-32602Unsupported streamUse "trades" as the stream value
-32600Array-wrapped requestSend a single JSON-RPC object, not an array
-32700Malformed JSONValidate your request JSON

Best Practices#

  1. Respect the batch limit — Keep ranges at or below 100 blocks per request
  2. Use sequential fetching — Combine with hl_getLatestBlockNumber to walk forward
  3. Handle sparse ranges — Some blocks in a range may have no events
  4. Implement retries — Use exponential backoff for transient errors

Query HyperCore fill data with Dwellir's JSON-RPC API. Get your API key →