ypricemagic

raw JSON →
5.2.16 verified Fri May 01 auth: no python

A Python library for extracting historical on-chain price data from an archive node, supporting a wide range of tokens and protocols including Yearn, Curve, Balancer, Uniswap, and more. Current version 5.2.16, actively maintained with frequent releases.

pip install ypricemagic
error KeyError: '0x...'
cause Token address not found in the built-in price magic database.
fix
Manually provide a price locator via the locator parameter or ensure the token is supported.
error Web3.exceptions.BadFunctionCallOutput: No data available - did you connect to an archive node?
cause Connected to a non-archive node that does not have historical state.
fix
Switch to an archive node endpoint.
error TypeError: get_price() got multiple values for argument 'block'
cause Passing block as both positional and keyword argument.
fix
Use only keyword arguments: get_price(token, block=123)
gotcha Requires an archive node; non-archive nodes will fail with missing state errors.
fix Use an archive node RPC (e.g., Alchemy, Infura archive plan, or local archive node).
deprecated The old import path `from ypricemagic import magic` is deprecated and will be removed.
fix Use `from ypricemagic import get_price` directly.
breaking In v5.0.0, the internal price fetching API was restructured; custom locator classes may break.
fix Ensure any custom price locators inherit from the new base classes; consult migration guide.

Fetch the price of WETH at block 15,000,000. Set ETH_RPC_URL environment variable to your archive node endpoint.

import os
from ypricemagic import get_price

# Requires an Ethereum archive node RPC URL
rpc_url = os.environ.get('ETH_RPC_URL', 'https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY')

# Get ETH price in USD at a specific block
price = get_price('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', block=15000000, fail_on_multiple_locators=True)
print(f'Price at block 15000000: {price}')