Fee Estimation
FeeEstimator fetches fee rates from the mempool.space REST API with a 30-second in-memory cache.
Usage
import asyncio
from bitpilot import FeeEstimator
estimator = FeeEstimator(network="mainnet")
fee = asyncio.run(estimator.estimate_fee())
print(f"Fast: {fee.fast_sat_vb} sat/vB (~10 min)")
print(f"Medium: {fee.medium_sat_vb} sat/vB (~30 min)")
print(f"Slow: {fee.slow_sat_vb} sat/vB (~60 min)")
FeeEstimate Model
| Field | Type | Description |
|---|---|---|
fast_sat_vb | float | Next-block fee rate |
medium_sat_vb | float | ~3 block fee rate |
slow_sat_vb | float | ~6 block fee rate |
estimated_minutes | dict | {"fast": 10, "medium": 30, "slow": 60} |
fetched_at | datetime | UTC timestamp of the fetch |
Target Block Helper
rate = fee.for_target_blocks(1) # returns fast_sat_vb
rate = fee.for_target_blocks(3) # returns medium_sat_vb
rate = fee.for_target_blocks(6) # returns slow_sat_vb
API Endpoints
| Network | URL |
|---|---|
| mainnet | https://mempool.space/api/v1/fees/recommended |
| testnet | https://mempool.space/testnet/api/v1/fees/recommended |
No API key required. Requests time out after 10 seconds.
Caching
Results are cached for 30 seconds. Subsequent calls within the TTL return the cached FeeEstimate without making an HTTP request.