Skip to content

Commit

Permalink
chore: add example for recent_trade_ads
Browse files Browse the repository at this point in the history
  • Loading branch information
fekie committed Jun 6, 2023
1 parent 55d1893 commit eb34987
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/get_recent_trade_ads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#[tokio::main]
async fn main() {
let roli_client = roli::ClientBuilder::new().build();
let recent_trade_ads = roli_client.recent_trade_ads().await.unwrap();
let all_item_details = roli_client.all_item_details().await.unwrap();

for trade_ad in recent_trade_ads {
let offer_value = trade_ad
.offer
.items
.iter()
.map(|id| {
all_item_details
.iter()
.find(|item| item.item_id == *id)
.unwrap()
.value
})
.sum::<u64>()
+ trade_ad.offer.robux.unwrap_or_default();

let request_value = trade_ad
.request
.items
.iter()
.map(|id| {
all_item_details
.iter()
.find(|item| item.item_id == *id)
.unwrap()
.value
})
.sum::<u64>();

println!(
"Trade {} is offering a total value of {} for a total value of {}",
trade_ad.trade_id, offer_value, request_value
);
}
}

0 comments on commit eb34987

Please sign in to comment.