fetch_perp_snapshots_multicall

Documentation for eth_defi.derive.api.fetch_perp_snapshots_multicall function.

fetch_perp_snapshots_multicall(w3, contract_addresses, block_number, sub_id=0)

Fetch open interest, perp price, and index price for multiple instruments in one RPC call.

Uses Multicall3 aggregate3 to batch three view function calls per instrument:

  • openInterest(uint256 subId) — OI in base currency

  • getPerpPrice() — mark/perp price in USD

  • getIndexPrice() — spot/index price in USD

For N instruments this sends 3×N subcalls in a single RPC round-trip. Each call uses allowFailure=True so a single contract reverting (e.g. not yet deployed at that block) does not fail the whole batch.

Parameters
  • w3 (web3.main.Web3) – Web3 instance connected to Derive Chain.

  • contract_addresses (list[str]) – List of perp contract addresses (base_asset_address from the instruments API).

  • block_number (int) – Block number at which to read state.

  • sub_id (int) – Sub-asset identifier. Always 0 for perpetuals.

Returns

List of PerpSnapshotMulticallResult in the same order as contract_addresses.

Raises

Exception – Transient RPC errors propagate to the caller.

Return type

list[eth_defi.derive.api.PerpSnapshotMulticallResult]