Skip to content

Commit

Permalink
Merge pull request #73 from Overmuse/SR/round_amounts
Browse files Browse the repository at this point in the history
SR/round amounts
  • Loading branch information
SebRollen authored Sep 28, 2021
2 parents d20f51b + 6003c52 commit 15259c6
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "order-manager"
version = "11.1.0"
version = "11.1.1"
authors = ["Sebastian Rollen <seb@overmu.se>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion src/order_manager/intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/order_manager/order_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
})
}
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn split_lot(claims: &[Claim], lot: &Lot) -> Vec<Allocation> {
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());
Expand Down

0 comments on commit 15259c6

Please sign in to comment.