types: add AdjustQuantityByMinNotional to types.Market

This commit is contained in:
c9s 2023-03-23 16:14:30 +08:00
parent 44850e48e8
commit 018e281627
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -136,6 +136,18 @@ func (m Market) CanonicalizeVolume(val fixedpoint.Value) float64 {
return math.Trunc(p*val.Float64()) / p
}
// AdjustQuantityByMinNotional adjusts the quantity to make the amount greater than the given minAmount
func (m Market) AdjustQuantityByMinNotional(quantity, currentPrice fixedpoint.Value) fixedpoint.Value {
// modify quantity for the min amount
amount := currentPrice.Mul(quantity)
if amount.Compare(m.MinNotional) < 0 {
ratio := m.MinNotional.Div(amount)
return quantity.Mul(ratio)
}
return quantity
}
type MarketMap map[string]Market
func (m MarketMap) Add(market Market) {