From 19297657635c0c68f77bf660307fd1be8bed2af2 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 9 Feb 2024 18:04:18 -0800 Subject: [PATCH] Include total value in cost basis --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3aacd2d..ed90a18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2007,13 +2007,17 @@ async fn process_account_cost_basis( for (amount, price) in lots { total_amount += amount; - total_price += Decimal::from_u64(amount).unwrap() * price; + total_price += Decimal::from_f64(token.ui_amount(amount)).unwrap() * price; } println!( - " {:>7}: {:<20} at ${:.2}", + " {:>7}: {:<20} at ${} ; ${:.2} per {}", token.to_string(), token.format_amount(total_amount), - total_price / Decimal::from_u64(total_amount).unwrap() + TryInto::::try_into(total_price) + .unwrap() + .separated_string_with_fixed_place(2), + total_price / Decimal::from_f64(token.ui_amount(total_amount)).unwrap(), + token.name() ); } Ok(())