estimate_block_at_timestamp
Documentation for eth_defi.derive.historical.estimate_block_at_timestamp function.
- estimate_block_at_timestamp(w3, target_ts, latest_block=None, latest_ts=None)
Estimate the Derive Chain block number closest to a Unix timestamp.
Uses linear interpolation from the current block. Derive Chain has a stable 2-second block time so the estimate is accurate to within a handful of blocks (a few seconds), which is more than adequate for hourly perp snapshots (OI, perp price, index price).
- Parameters
w3 (web3.main.Web3) – Web3 instance connected to Derive Chain.
target_ts (int) – Target Unix timestamp (seconds, UTC).
latest_block (int | None) – Current block number. Fetched automatically if not provided.
latest_ts (int | None) – Timestamp of the current block. Fetched automatically if not provided.
- Returns
Estimated block number (always >= 1).
- Return type