2020-09-16 06:05:03 +00:00
|
|
|
package bbgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrQuoteBalanceLevelTooLow = errors.New("quote balance level is too low")
|
|
|
|
ErrInsufficientQuoteBalance = errors.New("insufficient quote balance")
|
|
|
|
|
|
|
|
ErrAssetBalanceLevelTooLow = errors.New("asset balance level too low")
|
|
|
|
ErrInsufficientAssetBalance = errors.New("insufficient asset balance")
|
|
|
|
ErrAssetBalanceLevelTooHigh = errors.New("asset balance level too high")
|
|
|
|
)
|
|
|
|
|
2021-05-10 12:13:23 +00:00
|
|
|
// AdjustQuantityByMinAmount adjusts the quantity to make the amount greater than the given minAmount
|
|
|
|
func AdjustQuantityByMinAmount(quantity, currentPrice, minAmount float64) float64 {
|
2020-09-16 06:05:03 +00:00
|
|
|
// modify quantity for the min amount
|
|
|
|
amount := currentPrice * quantity
|
|
|
|
if amount < minAmount {
|
|
|
|
ratio := minAmount / amount
|
|
|
|
quantity *= ratio
|
|
|
|
}
|
|
|
|
|
|
|
|
return quantity
|
|
|
|
}
|
|
|
|
|
2021-05-10 12:13:23 +00:00
|
|
|
func AdjustQuantityByMaxAmount(quantity float64, price float64, maxAmount float64) float64 {
|
2020-11-09 06:56:54 +00:00
|
|
|
amount := price * quantity
|
2020-09-16 06:05:03 +00:00
|
|
|
if amount > maxAmount {
|
|
|
|
ratio := maxAmount / amount
|
|
|
|
quantity *= ratio
|
|
|
|
}
|
|
|
|
|
|
|
|
return quantity
|
|
|
|
}
|