Skip to content

Curve Prices

Fetch prices for blocks 21000000 to 21010000 by filtering on 3pool pool_address 0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7.

Code

Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
    core::types::ChainId, query::Bound,
    ClientBuilder, Format, WsProvider,
    provider::CurveProvider, requests::curve::GetCrvPriceRequest, 
};
 
#[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 = GetCrvPriceRequest { 
            chains: HashSet::from([ChainId::ETH]), 
            from_block: Bound::Exact(21000000), 
            to_block: Bound::Exact(21010000), 
            pool_address__in: HashSet::from(["0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7"
            .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": 21009991,
    "block_hash": "0x5aa672a9838e283191d3254112be108e2cf27e0b764ceb992895117fdeb37067",
    "transaction_hash": "0x32bc781f1ec9fcb6345d00297ec34e1bde479cb18a12f72a2a91a8c827131dbc",
    "transaction_index": 19,
    "log_index": 128,
    "pool_address": "0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7",
    "buyer": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
    "sold_id": 2,
    "tokens_sold": 50067.492497,
    "sold_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "sold_decimals": 6,
    "sold_name": "Tether USD",
    "sold_symbol": "USDT",
    "bought_id": 1,
    "tokens_bought": 50057.72226,
    "bought_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "bought_decimals": 6,
    "bought_name": "USD//C",
    "bought_symbol": "USDC",
    "price": 1.00019517941606,
    "kind": "coin",
    "timestamp": 1729465919
  }
]

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.
  • buyer__in: Filters the data by a list of buyer.
  • tokens_address__in: Filters the data by a list of token_address.
  • tokens_symbol__in: Filters the data by a list of token_symbol.
  • sold_address__in: Filters the data by a list of sold_address.
  • sold_symbol__in: Filters the data by a list of sold_symbol.
  • sold_decimals__gte: Filters the data by sold_decimals using the greater than or equal to operator.
  • sold_decimals__lte: Filters the data by sold_decimals using the less than or equal to operator.
  • bought_address__in: Filters the data by a list of bought_address.
  • bought_symbol__in: Filters the data by a list of bought_symbol.
  • bought_decimals__gte: Filters the data by bought_decimals using the greater than or equal to operator.
  • bought_decimals__lte: Filters the data by bought_decimals 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.
  • tokens_sold__gte: Filters the data by tokens_sold using the greater than or equal to operator.
  • tokens_sold__lte: Filters the data by tokens_sold using the less than or equal to operator.
  • tokens_bought__gte: Filters the data by tokens_bought using the greater than or equal to operator.
  • tokens_bought__lte: Filters the data by tokens_bought using the less than or equal to operator.