bbgo: optimize AdjustQuantityByMaxAmount, early return

This commit is contained in:
c9s 2021-07-08 10:26:20 +08:00
parent 31358a69d1
commit 8ada9eef02

View File

@ -18,12 +18,12 @@ var (
func AdjustQuantityByMaxAmount(quantity, currentPrice, maxAmount fixedpoint.Value) fixedpoint.Value { func AdjustQuantityByMaxAmount(quantity, currentPrice, maxAmount fixedpoint.Value) fixedpoint.Value {
// modify quantity for the min amount // modify quantity for the min amount
amount := currentPrice.Mul(quantity) amount := currentPrice.Mul(quantity)
if amount > maxAmount { if amount < maxAmount {
ratio := maxAmount.Div(amount) return quantity
quantity = quantity.Mul(ratio)
} }
return quantity ratio := maxAmount.Div(amount)
return quantity.Mul(ratio)
} }
// AdjustQuantityByMinAmount adjusts the quantity to make the amount greater than the given minAmount // AdjustQuantityByMinAmount adjusts the quantity to make the amount greater than the given minAmount