-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add example for recent_trade_ads
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |