Skip to content

Uniswap V3 Prices

Fetch prices for the USDC-WETH 5 bps Uniswap V3 Pool using the pool_address__in filter for blocks 21000000 to 21010000.

Code

Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
    core::types::ChainId, query::Bound,
    ClientBuilder, Format, WsProvider,
    provider::UniswapV3Provider, requests::uniswap_v3::GetPricesRequest, 
};
 
#[tokio::main]
async fn main() {
    dotenvy::dotenv_override().ok();
 
    let client = match ClientBuilder::default()
        .endpoint("app.pangea.foundation")
        .build::<WsProvider>()
        .await
    {
        Ok(client) => Arc::new(client),
        Err(e) => {
            eprintln!("Client failed to initialize:\n{e}");
            return;
        }
    };
 
    {
        let request = GetPricesRequest { 
            chains: HashSet::from([ChainId::ETH]), 
            from_block: Bound::Exact(21000000), 
            to_block: Bound::Exact(21010000), 
            pool_address__in: HashSet::from(["0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
            .parse() 
            .unwrap()]), 
            ..Default::default() 
        }; 
        let stream = match client 
            .get_prices_by_format(request, Format::JsonStream, false) 
            .await
        {
            Ok(stream) => stream,
            Err(e) => {
                eprintln!("Request failed\n{e}");
                return;
            }
        };
 
        futures::pin_mut!(stream);
 
        while let Some(chunk) = stream.next().await {
            let chunk = String::from_utf8(chunk.unwrap()).unwrap();
            println!("{chunk}");
        }
    }
}

Response

[
  ...
  {
    "chain": 1,
    "block_number": 21009999,
    "block_hash": "0x6570a1fe1866fcb94c260314633f071372070abcb440658b58b1fed043898aef",
    "transaction_hash": "0x1b163a66d89c87030a79c000b2962261cf4e8d7e27fc107a153ec00f3fd6e9ab",
    "transaction_index": 30,
    "log_index": 214,
    "pool_address": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "virtual0": 3.3838346511779787e-15,
    "virtual1": 7.720969858310247e+51,
    "price": 2751.0370783676967,
    "sender": "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
    "receiver": "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
    "amount0": 1000,
    "amount1": -0.36331888587226946,
    "liquidity": 5111407374417632000,
    "tick": 197122,
    "token0_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "token0_decimals": 6,
    "token0_name": "USD//C",
    "token0_symbol": "USDC",
    "token1_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "token1_decimals": 18,
    "token1_name": "Wrapped Ether",
    "token1_symbol": "WETH",
    "timestamp": 1729466015
  }
]

Query Parameters

  • chains: Filters the data by specific blockchain networks.
  • from_block: Filters the data by a starting block number.
  • to_block: Filters the data by an ending block number.
  • pool_address__in: Filters the data by a list of pool_address.
  • pool_factory_address__in: Filters the data by a list of pool_factory_address.
  • virtual0__gte: Filters the data by virtual0 using the greater than or equal to operator.
  • virtual0__lte: Filters the data by virtual0 using the less than or equal to operator.
  • virtual1__gte: Filters the data by virtual1 using the greater than or equal to operator.
  • virtual1__lte: Filters the data by virtual1 using the less than or equal to operator.
  • price__gte: Filters the data by price using the greater than or equal to operator.
  • price__lte: Filters the data by price using the less than or equal to operator.
  • sender__in: Filters the data by a list of sender.
  • receiver__in: Filters the data by a list of receiver.
  • amount0__gte: Filters the data by amount0 using the greater than or equal to operator.
  • amount0__lte: Filters the data by amount0 using the less than or equal to operator.
  • amount1__gte: Filters the data by amount1 using the greater than or equal to operator.
  • amount1__lte: Filters the data by amount1 using the less than or equal to operator.
  • liquidity__gte: Filters the data by liquidity using the greater than or equal to operator.
  • liquidity__lte: Filters the data by liquidity using the less than or equal to operator.
  • tick__gte: Filters the data by tick using the greater than or equal to operator.
  • tick__lte: Filters the data by tick using the less than or equal to operator.
  • token0_address__in: Filters the data by a list of token0_address.
  • token0_symbol__in: Filters the data by a list of token0_symbol.
  • token1_address__in: Filters the data by a list of token1_address.
  • token1_symbol__in: Filters the data by a list of token1_symbol.
  • tokens_address__in: Filters the data by a list of both token0_address and token1_address.
  • tokens_symbol__in: Filters the data by a list of both token0_symbol and token1_symbol.
  • price__gte: Filters the data by price using the greater than or equal to operator.
  • price__lte: Filters the data by price using the less than or equal to operator.