From 8ada9eef02438942fd2de8ddc12365980e3febdd Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 8 Jul 2021 10:26:20 +0800 Subject: [PATCH] bbgo: optimize AdjustQuantityByMaxAmount, early return --- pkg/bbgo/order_processor.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/bbgo/order_processor.go b/pkg/bbgo/order_processor.go index b3b129dd1..661975fdb 100644 --- a/pkg/bbgo/order_processor.go +++ b/pkg/bbgo/order_processor.go @@ -18,12 +18,12 @@ var ( func AdjustQuantityByMaxAmount(quantity, currentPrice, maxAmount fixedpoint.Value) fixedpoint.Value { // modify quantity for the min amount amount := currentPrice.Mul(quantity) - if amount > maxAmount { - ratio := maxAmount.Div(amount) - quantity = quantity.Mul(ratio) + if amount < maxAmount { + return quantity } - return quantity + ratio := maxAmount.Div(amount) + return quantity.Mul(ratio) } // AdjustQuantityByMinAmount adjusts the quantity to make the amount greater than the given minAmount