hypersync.hypersync_timestamp
Documentation for eth_defi.hypersync.hypersync_timestamp Python module.
Block timestamp and hash bulk loading using Hypersync API.
Replace slow and expensive eth_getBlockByNumber calls with Hypersync API.
Example:
blocks = get_block_timestamps_using_hypersync(
hypersync_client,
chain_id=1,
start_block=10_000_000,
end_block=10_000_100,
)
# Blocks missing if they do not contain transactions
# E.g https://etherscan.io/block/10000007
assert len(blocks) == 101
block = blocks[10_000_100]
assert block.block_number == 10_000_100
assert block.block_hash == "0x427b4ae39316c0df7ba6cd61a96bf668eff6e3ec01213b0fbc74f9b7a0726e7b"
assert block.timestamp_as_datetime == datetime.datetime(2020, 5, 4, 13, 45, 31)
Functions
Sync wrapper. |
|
Quickly get block timestamps using Hypersync API and a local cache file. |
|
|
Quickly get block timestamps using Hypersync API. |
Read block timestamps using Hypersync API. |
|
|
Get the latest block known to Hypersync. |
Exceptions
Hypersync stream flaky error, e.g. |
- exception HypersyncFlaky
Bases:
ExceptionHypersync stream flaky error, e.g. timeout.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- async get_block_timestamps_using_hypersync_async(client, chain_id, start_block, end_block, timeout=120.0, display_progress=True, progress_throttle=10000)
Read block timestamps using Hypersync API.
Instead of hammering eth_getBlockByNumber JSON-RPC endpoint, we can get block timestamps using Hypersync API 1000x faster.
- Parameters
chain_id (int) –
Verify HyperSync client is connected to the correct chain ID.
(Not actually used in request because client is per-chain)
start_block (int) – Start block, inclusive
end_block (int) – End block, inclusive
client (hypersync.HypersyncClient) – Hypersync client to use
timeout (float) –
display_progress (bool) –
- Return type
AsyncIterable[eth_defi.event_reader.block_header.BlockHeader]
- get_block_timestamps_using_hypersync(client, chain_id, start_block, end_block, display_progress=True)
Quickly get block timestamps using Hypersync API.
Wraps
get_block_timestamps_using_hypersync_async().You want to use
fetch_block_timestamps_using_hypersync_cached()cached version.- Returns
Block number -> header mapping
- Parameters
- Return type
dict[eth_typing.evm.BlockNumber, eth_defi.event_reader.block_header.BlockHeader]
- get_hypersync_block_height(client)
Get the latest block known to Hypersync.
Wrapped around the async function.
- Parameters
client (hypersync.HypersyncClient) –
- Return type
- async fetch_block_timestamps_using_hypersync_cached_async(client, chain_id, start_block, end_block, cache_path=PosixPath('/home/runner/.tradingstrategy/block-timestamp'), display_progress=True, checkpoint_freq=1250000000)
Quickly get block timestamps using Hypersync API and a local cache file.
Ultra fast, used optimised Hypersync streaming and DuckDB local cache.
- fetch_block_timestamps_using_hypersync_cached(client, chain_id, start_block, end_block, cache_path=PosixPath('/home/runner/.tradingstrategy/block-timestamp'), display_progress=True, attempts=5)
Sync wrapper.
See
fetch_block_timestamps_using_hypersync_cached_async()for documentation.