Skip to content

Commit

Permalink
examples/rofl-orcale: Fetch price from binance to avoid rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Sep 19, 2024
1 parent ef77853 commit 0079a6b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/runtime-sdk/rofl-oracle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ impl OracleApp {
let observation = tokio::task::spawn_blocking(move || -> Result<_> {
// Request some data from Coingecko API.
let rsp: serde_json::Value = rofl_utils::https::agent()
.get("https://api.coingecko.com/api/v3/simple/price?ids=oasis-network&vs_currencies=USD")
.get("https://www.binance.com/api/v3/ticker/price?symbol=ROSEUSDT")
.call()?
.body_mut()
.read_json()?;

// Extract price and convert to integer.
let price = rsp
.pointer("/oasis-network/usd")
.pointer("/price")
.ok_or(anyhow::anyhow!("price not available"))?
.as_f64()
.ok_or(anyhow::anyhow!("price malformed"))?;
.as_str().unwrap()
.parse::<f64>()?;
let price = (price * 1_000_000.0) as u128;

Ok(price)
Expand Down

0 comments on commit 0079a6b

Please sign in to comment.