diff --git a/Cargo.lock b/Cargo.lock index 5867da9..e452a53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -997,7 +997,7 @@ dependencies = [ [[package]] name = "order-manager" -version = "11.1.0" +version = "11.1.1" dependencies = [ "alpaca 0.9.0", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 2a99c4d..e820eb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "order-manager" -version = "11.1.0" +version = "11.1.1" authors = ["Sebastian Rollen "] edition = "2018" diff --git a/src/order_manager/intents.rs b/src/order_manager/intents.rs index 8ab975f..41cba15 100644 --- a/src/order_manager/intents.rs +++ b/src/order_manager/intents.rs @@ -158,7 +158,7 @@ impl OrderManager { .flatten() .or(limit_price); match price { - Some(price) => dollars / price, + Some(price) => (dollars / price).round_dp(8), None => { warn!("Missing price"); return Ok(None); diff --git a/src/order_manager/order_updates.rs b/src/order_manager/order_updates.rs index e9a5cb5..19995c1 100644 --- a/src/order_manager/order_updates.rs +++ b/src/order_manager/order_updates.rs @@ -165,7 +165,7 @@ fn aggregate_previous_lots(lots: &[Lot]) -> (Decimal, Decimal) { lots.iter().fold((Decimal::ZERO, Decimal::ONE), |(shares, price), lot| { ( shares + lot.shares, - (price * shares + lot.price * lot.shares) / (shares + lot.shares), + ((price * shares + lot.price * lot.shares) / (shares + lot.shares)).round_dp(8), ) }) } @@ -179,7 +179,7 @@ fn calculate_lot_quantity_and_price( new_price: Decimal, ) -> (Decimal, Decimal) { let quantity = new_quantity - old_quantity; - let price = (new_price * new_quantity - old_price * old_quantity) / quantity; + let price = ((new_price * new_quantity - old_price * old_quantity) / quantity).round_dp(8); (quantity, price) } diff --git a/src/types/allocation.rs b/src/types/allocation.rs index 85aee46..4080c4d 100644 --- a/src/types/allocation.rs +++ b/src/types/allocation.rs @@ -102,7 +102,7 @@ pub fn split_lot(claims: &[Claim], lot: &Lot) -> Vec { if dollars.is_sign_negative() { allocated_dollars.set_sign_negative(true) } - (allocated_dollars, allocated_dollars / lot.price) + (allocated_dollars, (allocated_dollars / lot.price).round_dp(8)) } Amount::Shares(shares) => { let mut allocated_shares = shares.abs().min(remaining_shares.abs());