mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
bbgo: optimize AdjustQuantityByMaxAmount, early return
This commit is contained in:
parent
31358a69d1
commit
8ada9eef02
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user