Pyth Network Price Feeds
Fetch Aptos price feed update events for versions 2382400000
to 2382410000
for identifier 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
.
Code
Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
core::types::ChainId, query::Bound,
ClientBuilder, Format, WsProvider,
provider::MoveProvider, requests::pyth::GetPricesRequest,
};
#[tokio::main]
async fn main() {
dotenvy::dotenv_override().ok();
let client = match ClientBuilder::default()
.endpoint("aptos.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::APTOS]),
from_block: Bound::Exact(2382400000),
to_block: Bound::Exact(2382410000),
identifier__in: HashSet::from(["0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
.parse()
.unwrap()]),
..Default::default()
};
let stream = match client
.get_move_pyth_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
{
...
{
"block_number": 2382409732,
"transaction_hash": "0x9af325a2c45ec46fab8ba9a3682ed4341ba48be1c2e720b713bdbef0dd273da1",
"log_index": 20,
"timestamp": 1739913181365474,
"identifier": "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
"price": 9490383937348,
"price_exponent": -8,
"price_confidence": 5639062651,
"price_timestamp": 1739913179,
"ema": 9416997400000,
"ema_exponent": -8,
"ema_confidence": 4929064600,
"ema_timestamp": 1739913179,
"pyth_timestamp": 1739913181365474
}
}
Query parameters
chains
: Filters the data bychain
.from_block
: Filters the data by a startingversion
. As Move chains use a per-transaction versioned database, we useversion
interchangably withblock_number
and omit blocks altogether.to_block
: Filters the data by an endingversion
. As Move chains use a per-transaction versioned database, we useversion
interchangably withblock_number
and omit blocks altogether.identifier__in
/price_id__in
: Filters the data by a list ofidentifier
.