token_price
The Price API can help you easily fetch current/historical price data.

Parameters

Object - An object with the following fields (required):
  • timestamp(integer number, required) - price data at this specific time you want to query(If you set a number that is out of range, the latest price data will be returned).
  • token0(hex string, required) - address of a token that you want to query.
  • token1(hex string, required) - address of the other token you want to query.

Returns

Object - An object with the following fields:
  • id(integer number) - json-rpc id.
    • jsonrpc(string) - json-rpc version.
    • result(object) - an object with the following fields:
      • timestamp - price time.
      • token0(hex string) - address of the token0.
      • token0Name(string) - name of the token0.
      • token0Price(string) - the amount of token0 needed to swap 1 token1.
      • token1(hex string) - address of the token1.
      • token1Name(string) - name of the token1.
      • token1Price(string) - the amount of token1 needed to swap 1 token0.
      • blockNumbers(array of integer numbers) - where the prices are calculated from.
Notice: You don't have to worry about the order of token0/token1, our API will change the order according to your parameters.

Example

Request

1
curl https://api.blockvision.org/v1/<api key> \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{
5
"id": 1,
6
"jsonrpc": "2.0",
7
"method": "token_price",
8
"params": {
9
"token0":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
10
"token1":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
11
"timestamp": 1649520000
12
}
13
}'
Copied!

Result

1
{
2
"jsonrpc": "2.0",
3
"id": 1,
4
"result": {
5
"token0": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
6
"token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
7
"token0Name": "USD Coin",
8
"token1Name": "Wrapped Ether",
9
"token0Price": "3208.827648",
10
"token1Price": "0.0003116403112",
11
"blockNumbers": [
12
14552470,
13
14552472
14
]
15
}
16
}
Copied!
Last modified 1mo ago