Skip to content

Commit

Permalink
Fixed potential division by zero in FIFO
Browse files Browse the repository at this point in the history
Happened because somewhere in my data there was a 0 fee set, which should
not cause any issues.
  • Loading branch information
bjorn committed Sep 15, 2023
1 parent 115fa21 commit bd1a2b2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ fn gains<'a>(holdings: &mut HashMap<&'a str, VecDeque<Entry>>, timestamp: NaiveD

let mut capital_gains: Vec<CapitalGain> = Vec::new();
let mut sold_quantity = outgoing.quantity;
if sold_quantity.is_zero() {
return Ok(capital_gains);
}

let sold_unit_price = incoming_fiat / sold_quantity;

while let Some(holding) = currency_holdings.front_mut() {
Expand Down

0 comments on commit bd1a2b2

Please sign in to comment.