Skip to content

Commit

Permalink
Remove % for fiat fungible tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 27, 2024
1 parent ad98065 commit 1fb0763
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,7 @@ async fn process_account_list(
let mut total_unrealized_short_term_gain = 0.;
let mut total_unrealized_long_term_gain = 0.;
let mut total_current_basis = 0.;
let mut total_current_fiat_value = 0.;
let mut total_current_value = 0.;

let open_orders = db.open_orders(None, None);
Expand Down Expand Up @@ -2332,7 +2333,7 @@ async fn process_account_list(
"".into()
} else {
format!(
" [{}%] ({}{})",
" ({}%), {}{}",
((account_current_value - account_basis) / account_basis * 100.)
.separated_string_with_fixed_place(2),
if account_income > 0. {
Expand Down Expand Up @@ -2363,8 +2364,12 @@ async fn process_account_list(
total_unrealized_short_term_gain += account_unrealized_short_term_gain;
total_unrealized_long_term_gain += account_unrealized_long_term_gain;
total_income += account_income;
total_current_basis += account_basis;
total_current_value += account_current_value;
if account.token.fiat_fungible() {
total_current_fiat_value += account_current_value;
} else {
total_current_basis += account_basis;
}

held_token.2.short_term_cap_gain += account_unrealized_short_term_gain;
held_token.2.long_term_cap_gain += account_unrealized_long_term_gain;
Expand Down Expand Up @@ -2594,16 +2599,23 @@ async fn process_account_list(
.unwrap_or_default();

println!(
" {:<7} {:<20} ({}; ${:>4} per {:>4}{})",
" {:<7} {:<20} [{}; ${:>4} per {:>4}{}]",
held_token.to_string(),
held_token.format_amount(total_held_amount),
total_value
.map(|tv| {
format!(
"${:14} [{:>8}%]",
"${:14} {}",
tv.separated_string_with_fixed_place(2),
((tv - unrealized_gain.basis) / unrealized_gain.basis * 100.)
.separated_string_with_fixed_place(2)
if held_token.fiat_fungible() {
" ".into()
} else {
format!(
"({:>8}%)",
((tv - unrealized_gain.basis) / unrealized_gain.basis * 100.)
.separated_string_with_fixed_place(2)
)
}
)
})
.unwrap_or_else(|| "?".into()),
Expand All @@ -2620,11 +2632,17 @@ async fn process_account_list(

println!("Summary");
println!(
" Current Value: ${} [{}%]",
" Current Value: ${} ({}%)",
total_current_value.separated_string_with_fixed_place(2),
((total_current_value - total_current_basis) / total_current_basis * 100.)
(((total_current_value - total_current_fiat_value) - total_current_basis)
/ total_current_basis
* 100.)
.separated_string_with_fixed_place(2),
);
println!(
" Current Fiat Value: ${}",
total_current_fiat_value.separated_string_with_fixed_place(2)
);
if total_income > 0. {
println!(
" Income: ${} (realized)",
Expand Down

0 comments on commit 1fb0763

Please sign in to comment.