Uniswap V2 Prices
Fetch prices for blocks 21000000
to 21010000
for pair_address
0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
.
Code
Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
core::types::ChainId, query::Bound,
ClientBuilder, Format, WsProvider,
provider::UniswapV2Provider, requests::uniswap_v2::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),
pair_address__in: HashSet::from(["0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc"
.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": "0xfce09be95c468d592796d539bfef619345224acdb8dad7fe8e49b336f36d773c",
"transaction_index": 10,
"log_index": 69,
"pair_address": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
"event": "swap",
"reserve0": "0x29056f6e61f0",
"reserve1": "0x378e23ce52fd20cba1b",
"price": 2750.7038551923733,
"sender": "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
"receiver": "0x163c5e051049e92915017fe7bb9b8ce6182bcbb1",
"amount0": 522.024415,
"amount1": 0.19034732574832847,
"lp_amount": 0,
"protocol_fee": null,
"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.pair_address__in
: Filters the data by a list ofpair_address
.pair_factory_address__in
: Filters the data by a list ofpair_factory_address
.reserve0__gte
: Filters the data byreserve0
using the greater than or equal to operator.reserve0__lte
: Filters the data byreserve0
using the less than or equal to operator.reserve1__gte
: Filters the data byreserve1
using the greater than or equal to operator.reserve1__lte
: Filters the data byreserve1
using the less than or equal to operator.price__gte
: Filters the data byprice
using the greater than or equal to operator.price__lte
: Filters the data byprice
using the less than or equal to operator.sender__in
: Filters the data by a list ofsender
.receiver__in
: Filters the data by a list ofreceiver
.amount0__gte
: Filters the data byamount0
using the greater than or equal to operator.amount0__lte
: Filters the data byamount0
using the less than or equal to operator.amount1__gte
: Filters the data byamount1
using the greater than or equal to operator.amount1__lte
: Filters the data byamount1
using the less than or equal to operator.lp_amount__gte
: Filters the data bylp_amount
using the greater than or equal to operator.lp_amount__lte
: Filters the data bylp_amount
using the less than or equal to operator.protocol_fee__gte
: Filters the data byprotocol_fee
using the greater than or equal to operator.protocol_fee__lte
: Filters the data byprotocol_fee
using the less than or equal to operator.token0_address__in
: Filters the data by a list oftoken0_address
.token0_symbol__in
: Filters the data by a list oftoken0_symbol
.token1_address__in
: Filters the data by a list oftoken1_address
.token1_symbol__in
: Filters the data by a list oftoken1_symbol
.tokens_address__in
: Filters the data by a list of bothtoken0_address
andtoken1_address
.tokens_symbol__in
: Filters the data by a list of bothtoken0_symbol
andtoken1_symbol
.